X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/6f1565eb566394cd75f453303df30d904e333fa2..331a6c45e65595765e1f3b345f67675552c88588:/camera.py?ds=sidebyside diff --git a/camera.py b/camera.py index 0f524f3..a1be68b 100644 --- a/camera.py +++ b/camera.py @@ -3,19 +3,25 @@ import os if os.name == 'posix': import Image - import cv + import cv2.cv as cv class Camera: - def __init__(self): - self._cam = cv.CreateCameraCapture(0) + def __init__(self, device=0): + self._cam = cv.CaptureFromCAM(device) + print cv.GetCaptureProperty(self._cam, cv.CV_CAP_PROP_CONVERT_RGB) + cv.SetCaptureProperty(self._cam, cv.CV_CAP_PROP_CONVERT_RGB, True) def get_image(self): - im = cv.QueryFrame(self._cam) + for _ in range(8): #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()) + def __del__(self): + del self._cam + elif os.name in ('ce', 'nt', 'dos'): @@ -23,12 +29,12 @@ elif os.name in ('ce', 'nt', 'dos'): # TODO exception handling class Camera: - def __init__(self): + def __init__(self, device=0): self._cam = Device() self._cam.setResolution(640, 480) - def shot(self): - self._cam.saveSnapshot('image.jpg', quality=100) + def get_image(self): + return self._cam.getImage() def __del__(self): del self._cam