0f524f3d71d3ea19cab252f4004e6f1172e81026
[imago.git] / camera.py
1 import os
2
3 if os.name == 'posix':
4     
5     import Image
6     import cv
7
8     class Camera:
9         def __init__(self):
10             self._cam = cv.CreateCameraCapture(0)
11
12         def get_image(self):
13             im = cv.QueryFrame(self._cam)
14             # Add the line below if you need it (Ubuntu 8.04+)
15             im = cv.GetMat(im)
16             #convert Ipl image to PIL image
17             return Image.fromstring("RGB", cv.GetSize(im), im.tostring())
18         
19
20 elif os.name in ('ce', 'nt', 'dos'):
21     
22     from VideoCapture import Device
23
24     # TODO exception handling
25     class Camera:
26         def __init__(self):
27             self._cam = Device()
28             self._cam.setResolution(640, 480)
29
30         def shot(self):
31             self._cam.saveSnapshot('image.jpg', quality=100)
32
33         def __del__(self):
34             del self._cam