projekty
/
imago.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
intersections
[imago.git]
/
camera.py
diff --git
a/camera.py
b/camera.py
index
0f524f3
..
7efacb4
100644
(file)
--- a/
camera.py
+++ b/
camera.py
@@
-3,32
+3,45
@@
import os
if os.name == 'posix':
import Image
if os.name == 'posix':
import Image
- import cv
+ import cv
2.cv as cv
class Camera:
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):
def get_image(self):
+ for _ in range(8): #HACK
+ cv.QueryFrame(self._cam)
im = cv.QueryFrame(self._cam)
# Add the line below if you need it (Ubuntu 8.04+)
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())
#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'):
from VideoCapture import Device
elif os.name in ('ce', 'nt', 'dos'):
from VideoCapture import Device
+ import time
# TODO exception handling
class Camera:
# TODO exception handling
class Camera:
- def __init__(self):
+ def __init__(self
, device=0
):
self._cam = Device()
self._cam.setResolution(640, 480)
self._cam = Device()
self._cam.setResolution(640, 480)
+ #HACK to let the camera self-adjust:
+ print "The device is getting ready."
+ for _ in xrange(20):
+ self._cam.getImage()
+ time.sleep(0.5)
- def
shot
(self):
-
self._cam.saveSnapshot('image.jpg', quality=100
)
+ def
get_image
(self):
+
return self._cam.getImage(
)
def __del__(self):
del self._cam
def __del__(self):
del self._cam