Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions face_detect.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
""" Experiment with face detection and image filtering using OpenCV """
""" Experiment with face detection and image filtering using OpenCV. This is
mostly copied code, though I tried to look through the docs and understand
what is going on. I made a rather silly annoyed face for the rectangle."""

import cv2
import numpy as np
import numpy as np

cap = cv2.VideoCapture(0)

while(True):
face_cascade = cv2.CascadeClassifier('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:
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/4,y+h*4/10),(w/16),(0,0,0),-1)
cv2.circle(frame,(x+w*3/4,y+h*4/10),(w/16),(0,0,0),-1)
cv2.line(frame,(x+w/4,y+h/5),(x+w/2,y+h*4/10),(0,0,0),3)
cv2.line(frame,(x+w*3/4,y+h/5),(x+w/2,y+h*4/10),(0,0,0),3)
cv2.line(frame,(x+w/4,y+h*3/4),(x+w*3/4,y+h*3/4),(0,0,0),3)

# 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()
Loading