-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrab.py
More file actions
35 lines (28 loc) · 875 Bytes
/
grab.py
File metadata and controls
35 lines (28 loc) · 875 Bytes
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 os
import select
import v4l2capture
from PIL import Image
def capture_frame(width, height, device='/dev/video0'):
video = v4l2capture.Video_device(device)
size = video.set_format(width, height)
video.create_buffers(2)
video.queue_all_buffers()
video.start()
select.select((video,), (), ())
data = video.read()
video.close()
return size, data
def grab_image(filename, width=640, height=480, device='/dev/video0'):
size, data = capture_frame(width, height, device)
image = Image.fromstring("RGB", (size), data)
image.save(filename)
return True
if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
if grab_image(sys.argv[1]):
print 'Saved image to', sys.argv[1]
sys.exit(0)
else:
print 'Must provide output filename as second parameter'
sys.exit(1)