-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcamera.py
42 lines (32 loc) · 1.06 KB
/
camera.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
36
37
38
39
40
41
42
import cv2
def capture(img_file):
video = cv2.VideoCapture(1)
while True:
ret, im = video.read()
p1 = (140, -1)
p2 = (140 + 360, 480)
cv2.rectangle(im, p1, p2, (255, 255, 255), thickness=2)
cv2.imshow('Camera', im)
key = cv2.waitKey(10)
if key % 256 == 27: # Esc key to stop
break
elif key % 256 == ord(' ') or \
key % 256 == 141 or key % 256 == 10: # Capture the image
cv2.imwrite(img_file, im)
cv2.imshow('Picture Captured', im)
elif key == -1: # normally -1 returned,so don't print it
continue
else:
print 'You pressed %d (0x%x), LSB: %d (%s)' % (
key, key, key % 256,
repr(chr(key % 256)) if key % 256 < 128 else '?'
)
# When everything done, release the capture
video.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
capture('output/pics/%s.jpg' % sys.argv[1])
else:
exit(1)