Hi Andy and everyone else,
I've got started with using python for the userspace hal module. So far opencv is happy alongside the hal, it appears to be capturing images in the loop in python. I say this because no errors are reported and cpu load increases, however the highgui window to display the frame will not show. Is this a limitation of the userspace hal components? I'm directly testing python opencv routines side by side, both in and out of linux cnc hal. What works and displays an image outside of linuxcnc does not work inside the python hal module.
Here is the pyhton script (sorry for the noise, it's only short) - I named this hal1:
#!/usr/bin/python
import hal, time
# import the necessary things for OpenCV
from opencv import cv
from opencv import highgui
fiducialCam = 0
h = hal.component("hal1")
h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("ok", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("x", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("y", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("theta", hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()
try:
highgui.cvNamedWindow ('Camera', highgui.CV_WINDOW_AUTOSIZE)
# move the new window to a better place
highgui.cvMoveWindow ('Camera', 10, 10)
capture = highgui.cvCreateCameraCapture (fiducialCam)
if not capture:
print "Error opening capture device"
sys.exit (1)
while 1:
#time.sleep(1)
h['out'] = h['in']
# capture the current image
frame = highgui.cvQueryFrame (capture)
if frame is None:
# no image captured... end the processing
break
# display the frame
highgui.cvShowImage ('Camera', frame)
#print "Does this work?"
except KeyboardInterrupt:
raise SystemExit
If you're going to try this out, the dependencies are satisfied on ubuntu 10.04 with linuxcnc already instaled with the following:
sudo apt-get install libcv4 libcvaux4 libcvaux-dev libhighgui4 libhighgui-dev python-opencv opencv-doc libcv-dev
also, having a webcam/video grabber plugged in would help.
Do you know of a way to write an image into a part of axis instead? Would that be a part of pyVCP or the other VCP?
Any ideas greatly appreciated,
Cheers,
Ed
-- edited code, grr - indentation... mumble mumble