Skip to content

Commit

Permalink
Engineers Day extras
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderHam committed Sep 14, 2015
1 parent cef83b9 commit caa62f3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions engineers_day.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import cv2
import sys

faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
video_capture = cv2.VideoCapture(0)
video_capture.read()
face_count = 0
eye_count = 0
face_no_count = 0
eye_no_count = 0
while True:
face_there = False
eye_there = False
# Capture frame-by-frame
ret, frame = video_capture.read()
img2 = frame
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
img = cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
face_there = True
roi_gray = gray[y:y+h, x:x+w]
roi_color = img2[y:y+h, x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray)
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(255,0,0),2)
eye_there= True
if(face_there):
face_count = face_count + 1
if(face_count>6):
print("I see you!")
face_count = 0
else:
face_no_count = face_no_count + 1
if(face_no_count>6):
print("Where did you go?")
face_no_count = 0
if(eye_there):
eye_count = eye_count + 1
if(eye_count>6):
print("Your eyes too!")
eye_count = 0
else:
eye_no_count = eye_no_count + 1
if(eye_no_count>6):
print("Open your eyes!")
eye_no_count = 0
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
1 change: 1 addition & 0 deletions process_real_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
eyes = eye_cascade.detectMultiScale(roi_gray)
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(255,0,0),2)
print("Hey there! I see you")
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
Expand Down

0 comments on commit caa62f3

Please sign in to comment.