Skip to content

Instantly share code, notes, and snippets.

@edfungus
Created September 14, 2014 03:37
Show Gist options
  • Save edfungus/8da9baa0a04aa6d59177 to your computer and use it in GitHub Desktop.
Save edfungus/8da9baa0a04aa6d59177 to your computer and use it in GitHub Desktop.
OpenCV - eye tracking of webcam video
import numpy as np
import cv2
import time
cap = cv2.VideoCapture(0) #640,480
w = 640
h = 480
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
#detect face
faces = cv2.CascadeClassifier('haarcascade_eye.xml')
detected = faces.detectMultiScale(frame, 1.3, 5)
#draw square
for (x,y,w,h) in detected:
cv2.rectangle(frame, (x,y), ((x+w),(y+h)), (0,0,255),1)
cv2.line(frame, (x,y), ((x+w,y+h)), (0,0,255),1)
cv2.line(frame, (x+w,y), ((x,y+h)), (0,0,255),1)
#cv2.rectangle(frame, (x,y),((x+40),(y+40)),(0,0,255),1)
#show picture
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
cv2.destroyAllWindows()
@naushadck
Copy link

Hello,

This works ok if there is only one face and no other black objects.
It shows wrong identification for photo or id cards. .....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment