+import os
+
+if os.name == 'posix':
+
+ import Image
+ import cv
+
+ class Camera:
+ def __init__(self):
+ self._cam = cv.CreateCameraCapture(0)
+
+ def get_image(self):
+ im = cv.QueryFrame(self._cam)
+ # Add the line below if you need it (Ubuntu 8.04+)
+ im = cv.GetMat(im)
+ #convert Ipl image to PIL image
+ return Image.fromstring("RGB", cv.GetSize(im), im.tostring())
+
+
+elif os.name in ('ce', 'nt', 'dos'):
+
+ from VideoCapture import Device
+
+ # TODO exception handling
+ class Camera:
+ def __init__(self):
+ self._cam = Device()
+ self._cam.setResolution(640, 480)
+
+ def shot(self):
+ self._cam.saveSnapshot('image.jpg', quality=100)
+
+ def __del__(self):
+ del self._cam