Guest User

Untitled

a guest
Jan 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import cv2
  2. import sys
  3.  
  4. cascPath = "haarcascade_frontalface_default.xml"
  5. faceCascade = cv2.CascadeClassifier(cascPath)
  6.  
  7. video_capture = cv2.VideoCapture(0)
  8.  
  9. while True:
  10. # Capture frame-by-frame
  11. ret, frame = video_capture.read()
  12.  
  13. gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  14.  
  15. faces = faceCascade.detectMultiScale(
  16. gray,
  17. scaleFactor=1.1,
  18. minNeighbors=5,
  19. minSize=(30, 30),
  20. flags=cv2.CASCADE_SCALE_IMAGE
  21. )
  22.  
  23. # Draw a rectangle around the faces
  24. for (x, y, w, h) in faces:
  25. cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
  26.  
  27. # Display the resulting frame
  28. cv2.imshow('Video', frame)
  29.  
  30. if cv2.waitKey(1) & 0xFF == ord('q'):
  31. break
  32.  
  33. # When everything is done, release the capture
  34. video_capture.release()
  35. cv2.destroyAllWindows()
Add Comment
Please, Sign In to add comment