ec947870557068d807f87f19c8190576a3efd833
[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             for _ in range(5): #HACK
14                 im = cv.QueryFrame(self._cam)
15             # Add the line below if you need it (Ubuntu 8.04+)
16             im = cv.GetMat(im)
17             #convert Ipl image to PIL image
18             return Image.fromstring("RGB", cv.GetSize(im), im.tostring())
19         
20         def __del__(self):
21             del self._cam 
22
23
24 elif os.name in ('ce', 'nt', 'dos'):
25     
26     from VideoCapture import Device
27
28     # TODO exception handling
29     class Camera:
30         def __init__(self):
31             self._cam = Device()
32             self._cam.setResolution(640, 480)
33
34         def get_image(self):
35             return self._cam.getImage()
36
37         def __del__(self):
38             del self._cam