NEWS
LinuxCNC 2.5.2 Release
There are no translations available.

LinuxCNC 2.5.2 Update Released (changelog).
 
LinuxCNC 2.5.1 Release
There are no translations available.

LinuxCNC 2.5.1 Update Released (changelog). If the Package Manager does not prompt you to upgrade see this page.

 
LinuxCNC 2.5.0 Release
There are no translations available.

New major release (changelog). See the instructions to update your system from EMC 2.4 to LinuxCNC 2.5.
 
Home Forum Configuring LinuxCNC Advanced Configuration OpenCV vision with EMC/linuxcnc

Welcome, Guest
Username: Password: Remember me

TOPIC: OpenCV vision with EMC/linuxcnc

Re:OpenCV vision with EMC/linuxcnc 25 Mag 2012 13:32 #20397

  • edsimmons
  • edsimmons's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 22
  • Karma: 0
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
Last Edit: 25 Mag 2012 14:08 by edsimmons.
The administrator has disabled public write access.

Re:OpenCV vision with EMC/linuxcnc 25 Mag 2012 13:48 #20398

  • edsimmons
  • edsimmons's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 22
  • Karma: 0
Another question that has arisen...

I'm a c++ man at heart. Would I be better off working in my native language with a hal component that's not userspace?

Does this have implications with the real time parts of linuxcnc?

Thanks!

:)
Ed
The administrator has disabled public write access.

Re:OpenCV vision with EMC/linuxcnc 25 Mag 2012 14:00 #20399

  • andypugh
  • andypugh's Avatar
  • NOW ONLINE
  • Moderator
  • Posts: 4106
  • Thank you received: 139
  • Karma: 129
edsimmons wrote:
I'm a c++ man at heart. Would I be better off working in my native language with a hal component that's not userspace?
The alternative to "Userspace" is "Realtime". I don't think you want to be doing the Vision in realtime...
The administrator has disabled public write access.

Re:OpenCV vision with EMC/linuxcnc 25 Mag 2012 14:03 #20400

  • edsimmons
  • edsimmons's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 22
  • Karma: 0
Lol - ok!!
The administrator has disabled public write access.

Re:OpenCV vision with EMC/linuxcnc 25 Mag 2012 14:24 #20401

  • andypugh
  • andypugh's Avatar
  • NOW ONLINE
  • Moderator
  • Posts: 4106
  • Thank you received: 139
  • Karma: 129
edsimmons wrote:
Lol - ok!!
C++ is fine though. I should have said.
The administrator has disabled public write access.

Re:OpenCV vision with EMC/linuxcnc 26 Mag 2012 00:10 #20411

  • edsimmons
  • edsimmons's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 22
  • Karma: 0
Ahh - if c++ is an option - where do I look?

I'm not loving the python-ness with opencv - c++ would be infinitely preferable!

Don't suppose you've got a link to a starting point for c++ userspace hal modules?

Thanks!

-- edit - found a sensible place to start - http://www.linuxcnc.org/docs/2.4/html/hal_comp.html#r1_13
Last Edit: 26 Mag 2012 02:02 by edsimmons.
The administrator has disabled public write access.
Time to create page: 1.060 seconds
Powered by Kunena Forum
© 2013 LinuxCNC.org
Joomla! is Free Software released under the GNU General Public License.