forked from carolinedunn/facial_recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheadshots_picam.py
35 lines (28 loc) · 953 Bytes
/
headshots_picam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import cv2
from picamera import PiCamera
from picamera.array import PiRGBArray
name = 'Caroline' #replace with your name
cam = PiCamera()
cam.resolution = (512, 304)
cam.framerate = 10
rawCapture = PiRGBArray(cam, size=(512, 304))
img_counter = 0
while True:
for frame in cam.capture_continuous(rawCapture, format="bgr", use_video_port=True):
image = frame.array
cv2.imshow("Press Space to take a photo", image)
rawCapture.truncate(0)
k = cv2.waitKey(1)
rawCapture.truncate(0)
if k%256 == 27: # ESC pressed
break
elif k%256 == 32:
# SPACE pressed
img_name = "dataset/"+ name +"/image_{}.jpg".format(img_counter)
cv2.imwrite(img_name, image)
print("{} written!".format(img_name))
img_counter += 1
if k%256 == 27:
print("Escape hit, closing...")
break
cv2.destroyAllWindows()