I need to get a uEye camera working with python on Windows in order to take pictures and operate on the live stream.
Since uEye cameras are widely spread industrial cameras I would have thought that there is a standard solution to this; however, I could not find any.
The solution needs to run under python 2.7 on Windows XP or Windows 7.
I would appreciate anyone who has successfully used a uEye camera in python on Windows to share his knowledge on this issue or at least point me in the right direction. I also feel that there is really a need to find a generic soltion, since for sure I'm not the only one with this requirement.
What I've tried so far
(a) pyueye
There is a python driver available which works under Linux and - according to the documentation - "should work on windows".
I've tried that but installation failed:
python setup.py install
gives me
ueye\ueye.pyx: cannot find cimported module 'stdlib'
ueye\ueye.pyx: cannot find cimported module 'python_cobject'
Compiling ueye\ueye.pyx because it changed.
Compiling ueye\ueyeh.pyx because it changed.
[1/2] Cythonizing ueye\ueye.pyx
I have no idea what cimported
modules are and whether this should work at all. So it might be good to know if anyone has successfully installed this driver on a Windows system.
(b) openCV
OpenCV seems to be some kind of standard for image capturing and processing. It seems some people have used it to access a uEye camera, while there also seems to be some consensus that uEye cameras do not work with openCV. I haven't found any reportedly working example code.
Anyways I tried this (using openCV version 2.4.13) and I can access the camera and retrieve a picture from it. The resolution initially is 480 x 640
, but I am able to change it to the sensor resoltion of 768 x 1024
.
However, I am not able to set the exposure time and the gain correctly, as can be seen in the following code I used.
cam = cv2.VideoCapture(0)
width = cam.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
height = cam.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)
exposure = cam.get(cv2.cv.CV_CAP_PROP_EXPOSURE)
print width, height, exposure # prints 640 480 -4.0
hr = cam.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 768)
wr = cam.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 1024)
print "Setting resolution ", hr, wr # prints True True
cam.set(cv2.cv.CV_CAP_PROP_EXPOSURE, 0) # or any other value, same for gain
width = cam.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
height = cam.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)
exposure = cam.get(cv2.cv.CV_CAP_PROP_EXPOSURE)
print width, height, exposure # 1024.0 768.0 -4.0
ret, buff = cam.read()
cam.release()
It may well be that the camera is in some kind of auto-mode that automatically adjusts the parameters like exposure time and gain. But if this is the case, how would I set this auto-mode off.
(c) simpleCV
simpleCV seems to be an alternative to openCV. I also tried that and it gives the problem of only fetching a 480 x 640
pixel image and I couldn't find any way to set it differently, neither a way to set the exposure time.
from SimpleCV import Camera
cam = Camera(0)
img = cam.getImage() # img is a 480 x 640 pixel image
(d) Writing own driver in C
One option might be to write a C code to access the camera via its SDK. A full documentation of the SDK is available and it seems, someone has successfully done it (here, or here) but I wouldn't even know where to start and how to get the live image into python.