From 2985b29616485cdeb6f27105898c6c497f9802ca Mon Sep 17 00:00:00 2001 From: Uma Desai Date: Thu, 10 Mar 2016 16:30:46 -0500 Subject: [PATCH] Submitting Computer Vision Project Toolbox --- face_detect.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/face_detect.py b/face_detect.py index 247a4d1..5ebdefa 100644 --- a/face_detect.py +++ b/face_detect.py @@ -1,4 +1,56 @@ -""" Experiment with face detection and image filtering using OpenCV """ +""" Experiment with face detection and image filtering using OpenCV. This was done through pair programming +with Anne Ku who also added me as a contributor to her pull request. """ import cv2 -import numpy as np \ No newline at end of file +import numpy as np + +cap = cv2.VideoCapture(0) + +while(True): + # Capture frame-by-frame + ret, frame = cap.read() + face_cascade = cv2.CascadeClassifier('/home/udesai/ToolBox-ComputerVision/haarcascade_frontalface_alt.xml ') + kernel = np.ones((21,21),'uint8') + + + ret, frame = cap.read() + faces = face_cascade.detectMultiScale(frame, scaleFactor=1.2, minSize=(20,20)) + for (x,y,w,h) in faces: + # print x + # print y + # print w + # print h +# cv2.rectangle(frame,(x,y),(x+w,y+h),(0,0,255)) +# for (x,y,w,h) in faces: + frame[y:y+h,x:x+w,:] = cv2.dilate(frame[y:y+h,x:x+w,:], kernel) + cv2.rectangle(frame,(x,y),(x+w,y+h),(0,0,255)) + #cv2.circle(frame, (x + w/2, y + h/2), int(x/2), (0,0,255)) + + #cv2.ellipse(frame, (x + w/2, y + .75*h), (20, 10), 0, 0, 180, (0,0,255), -1) + cv2.ellipse(frame,(x + w/2, int(y + .75*h)),(50,25),0,0,180,(0, 0, 0), thickness=5) + #white Eyes: + cv2.circle(frame, (int(x + .3*w), int(y + .4*h)), 20, (255, 255, 255), -1) + cv2.circle(frame, (int(x + w - .3*w), int(y +.4*h)), 20, (255, 255, 255), -1) + #pupils: + cv2.circle(frame, (int(x + .3*w + 5), int(y + .4*h)), 5, (0, 0, 0), -1) + cv2.circle(frame, (int(x + w -.3*w - 5), int(y + .4*h)), 5, (0, 0, 0), -1) + + + # Display the resulting frame + cv2.imshow('frame',frame) + if cv2.waitKey(1) & 0xFF == ord('q'): + sys.exit() #break? + + # Display the resulting frame + cv2.imshow('frame',frame) + if cv2.waitKey(1) & 0xFF == ord('q'): + break + + + +# When everything done, release the capture +cap.release() +cv2.destroyAllWindows() + +#Make a OpenCV Object +#Combining the While loops together \ No newline at end of file