Anbu Kumar
Published

AI - Face and Eye Detection

This is a simple artificial intelligent face and eye detection application deployed on Jetson Nano for security and surveillance.

IntermediateShowcase (no instructions)3 hours825
AI - Face and Eye Detection

Things used in this project

Story

Read more

Schematics

Video Shoot of POC

Code

Face and Eye Detection

Python
Install Python 3, OpenCV4 and Visual Studio IDE in Jetson Nano. Import HaarCascade algorithm from OpenCV GitHub repository and follow the below code
import cv2
print(cv2.__version__)
dispW=640
dispH=480
flip=2
#camSet='nvarguscamerasrc !  video/x-raw(memory:NVMM),width=1088, height=924, format=NV12, framerate=28/1 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(dispW)+', height='+str(dispH)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink'
#cam=cv2.VideoCapture(camSet)
cam=cv2.VideoCapture(1)
face_cascade=cv2.CascadeClassifier('/home/anbu/Desktop/PyPro/cascade/face.xml')
eye_cascade=cv2.CascadeClassifier('/home/anbu/Desktop/PyPro/cascade/eye.xml')
while True:
    ret, frame=cam.read()
    gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    faces=face_cascade.detectMultiScale(gray,1.3,5)
    for (x,y,w,h) in faces:
        cv2.rectangle(frame, (x,y),(x+w,y+h), (0,0,255),3)
        roi_gray=gray[y:y+h,x:x+w]
        Roi_color=frame[y:y+h,x:x+w]
        eyes=eye_cascade.detectMultiScale(roi_gray)
        for (xEye,yEye,wEye,hEye) in eyes:
            cv2.rectangle(Roi_color, (xEye,yEye),(xEye+wEye,yEye+hEye),(255,0,0),3)
            #cv2.circle(Roi_color,(int(xEye+wEye/2),int(yEye+hEye/2)),16,(255,0,0),-1)
    cv2.imshow('nanoCam',frame)
    cv2.moveWindow('nanoCam',0,0)
    if cv2.waitKey(1)==ord('q'):
        break
cam.release()
cv2.destroyALLWindows()

Credits

Anbu Kumar
21 projects • 81 followers
CodingScientist - Platform To Learn, Build, Code, Compile and Run your Artificial Intelligence applications on your own Autonomous Robot

Comments