Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import cv2
  2. import sys
  3. import logging as log
  4. import datetime as dt
  5. from time import sleep
  6. import time
  7. from picamera.array import PiRGBArray
  8. from picamera import PiCamera
  9.  
  10. cascPath = "haarcascade_frontalface_default.xml"
  11. faceCascade = cv2.CascadeClassifier(cascPath)
  12. log.basicConfig(filename='webcam.log',level=log.INFO)
  13.  
  14. camera = PiCamera()
  15. camera.resolution = (640, 480)
  16. camera.framerate = 32
  17. rawCapture = PiRGBArray(camera, size=(640, 480))
  18.  
  19. anterior = 0
  20. sleep(0.1)
  21. for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
  22. # grab the raw NumPy array representing the image, then initialize the timestamp
  23. # and occupied/unoccupied text
  24. frame = frame.array
  25.  
  26. gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  27.  
  28. faces = faceCascade.detectMultiScale(
  29. gray,
  30. scaleFactor=1.1,
  31. minNeighbors=5,
  32. minSize=(30, 30)
  33. )
  34.  
  35. # Draw a rectangle around the faces
  36. for (x, y, w, h) in faces:
  37. cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
  38.  
  39. if anterior != len(faces):
  40. anterior = len(faces)
  41. log.info("faces: "+str(len(faces))+" at "+str(dt.datetime.now()))
  42.  
  43.  
  44. # Display the resulting frame
  45. cv2.imshow('Video', frame)
  46.  
  47.  
  48. if cv2.waitKey(1) & 0xFF == ord('q'):
  49. break
  50.  
  51. # Display the resulting frame
  52. cv2.imshow('Video', frame)
  53. rawCapture.truncate(0)
  54. # When everything is done, release the capture
  55. video_capture.release()
  56. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement