X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/5ca7895fa1cf7655d555c0415d90c192087e74d6..ecb0ef2b5ea477ee170ce083f59d2200af7117a2:/camera.py diff --git a/camera.py b/camera.py index 1a7e3b5..d5dac75 100644 --- a/camera.py +++ b/camera.py @@ -6,16 +6,25 @@ if os.name == 'posix': import cv class Camera: - def __init__(self): - self._cam = cv.CreateCameraCapture(0) + def __init__(self, vid=0, res=None): + self._cam = cv.CreateCameraCapture(vid) + if res: + cv.SetCaptureProperty(self._cam, cv.CV_CAP_PROP_FRAME_WIDTH, res[0]) + cv.SetCaptureProperty(self._cam, cv.CV_CAP_PROP_FRAME_HEIGHT, + res[1]) def get_image(self): - im = cv.QueryFrame(self._cam) + for _ in range(5): #HACK + im = cv.QueryFrame(self._cam) # Add the line below if you need it (Ubuntu 8.04+) - im = cv.GetMat(im) + #im = cv.GetMat(im) #convert Ipl image to PIL image - return Image.fromstring("RGB", cv.GetSize(im), im.tostring()) + return Image.fromstring("RGB", cv.GetSize(im), im.tostring(), "raw", + "BGR", 0, 1) + def __del__(self): + del self._cam + elif os.name in ('ce', 'nt', 'dos'):