Initial scan
This commit is contained in:
commit
3439e34f4f
1 changed files with 44 additions and 0 deletions
44
scan_faces.py
Normal file
44
scan_faces.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import io
|
||||||
|
import picamera
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
camera = picamera.PiCamera()
|
||||||
|
camera.resolution = (1280, 720)
|
||||||
|
|
||||||
|
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml (~22sec)
|
||||||
|
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml (>25sec)
|
||||||
|
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml (~21sec)
|
||||||
|
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_alt_tree.xml (~14sec, seems to miss many faces)
|
||||||
|
classifier = cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml')
|
||||||
|
|
||||||
|
FPS = 1.0
|
||||||
|
frameTimeDelta = datetime.timedelta(seconds=1.0/FPS)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print(time.time(),"GO")
|
||||||
|
start = datetime.datetime.utcnow()
|
||||||
|
stream = io.BytesIO()
|
||||||
|
camera.capture(stream, format='jpeg')
|
||||||
|
print(time.time(),"captured")
|
||||||
|
buff = np.fromstring(stream.getvalue(), dtype=np.uint8)
|
||||||
|
image = cv2.imdecode(buff,1)
|
||||||
|
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||||
|
print(time.time(),"grayed")
|
||||||
|
faces = classifier.detectMultiScale(gray, 1.2, 5, minSize=(30,20))
|
||||||
|
|
||||||
|
print(time.time(),"Found {} faces".format(len(faces)))
|
||||||
|
|
||||||
|
end = datetime.datetime.utcnow()
|
||||||
|
if end - start < frameTimeDelta:
|
||||||
|
|
||||||
|
waitTime = frameTimeDelta - (end-start)
|
||||||
|
print("wait {}".waitTime.total_seconds())
|
||||||
|
time.sleep(waitTime.total_seconds())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue