Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import sys
- import logging as log
- import datetime as dt
- from time import sleep
- import time
- from picamera.array import PiRGBArray
- from picamera import PiCamera
- cascPath = "haarcascade_frontalface_default.xml"
- faceCascade = cv2.CascadeClassifier(cascPath)
- log.basicConfig(filename='webcam.log',level=log.INFO)
- camera = PiCamera()
- camera.resolution = (640, 480)
- camera.framerate = 32
- rawCapture = PiRGBArray(camera, size=(640, 480))
- anterior = 0
- sleep(0.1)
- for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
- # grab the raw NumPy array representing the image, then initialize the timestamp
- # and occupied/unoccupied text
- frame = frame.array
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- faces = faceCascade.detectMultiScale(
- gray,
- scaleFactor=1.1,
- minNeighbors=5,
- minSize=(30, 30)
- )
- # Draw a rectangle around the faces
- for (x, y, w, h) in faces:
- cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
- if anterior != len(faces):
- anterior = len(faces)
- log.info("faces: "+str(len(faces))+" at "+str(dt.datetime.now()))
- # Display the resulting frame
- cv2.imshow('Video', frame)
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- # Display the resulting frame
- cv2.imshow('Video', frame)
- rawCapture.truncate(0)
- # When everything is done, release the capture
- video_capture.release()
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement