+"""Camera module.
+
+This module handles various backends (different for every OS) for streaming the video from a (web)camera.
+"""
+
import os
if os.name == 'posix':
import cv
class Camera:
+ """Implement basic camera capabilities
+
+ This class has different implementations for different OS. On posix
+ systems it calls to opencv, on Windows to VideoCapture."""
+ # TODO what about win 64?
+ # TODO why not openCV on win?
+ # TODO document VideoCapture as a dependency
def __init__(self, vid=0, res=None):
self._cam = cv.CreateCameraCapture(vid)
if res:
res[1])
def get_image(self):
- for _ in range(5): #HACK
+ """Get a new image from the camera."""
+ for _ in range(5): #HACK TODO document this
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(), "raw",
"BGR", 0, 1)
def __del__(self):
del self._cam
+
+else:
+ pass # TODO exception "Cannot recognise OS." or back to posix?