ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How do I use OpenCV 3.0 in ROS python?

asked 2014-04-05 06:15:52 -0600

Frederik Hagelskjær gravatar image

updated 2016-10-24 09:03:08 -0600

ngrennan gravatar image

I have downloaded the newest development version of OpenCV ( 3.0) which I am using in python. But when using ROS Hydro I am including the "old" version (2 point something). But then I cannot use certain functions and some of the constants are named differently.

How do I include ROS, but still use my own version of OpenCV?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2014-04-06 16:07:04 -0600

jbinney gravatar image

I'm not sure that there is any well supported way to do this, but if you really really need to hack it you could probably modify sys.path at the top of your python script.

When you do ". /opt/ros/hydro/setup.bash" the PYTHONPATH environment variable gets set to "PYTHONPATH=/opt/ros/hydro/lib/python2.7/dist-packages". The opencv python module is there, in "/opt/ros/hydro/lib/python2.7/dist-packages/cv.py".

When your python script starts, it sets up its module search path (sys.path) using the PYTHONPATH environment variable. You can modify this and it will change where python looks for modules:


#!/usr/bin/env python                                                                                                                                            
import sys                                                                                                                                                       
sys.path = ['/path/to/your/opencv'] + sys.path                                                                                                                   
print sys.path                                                                                                                                                   
# do stuff.... 

This will cause python to see your installed opencv3.0 before the opencv that got installed by ROS. This is a pretty big hack though, so it might not go completely smoothly.

edit flag offensive delete link more
1

answered 2014-04-19 08:59:56 -0600

Frederik Hagelskjær gravatar image

I almost followed your description. But instead of manipulating my opencv path I simply place the ROS path at the end of my python path: import sys sys.path.remove('/opt/ros/hydro/lib/python2.7/dist-packages') sys.path.append('/opt/ros/hydro/lib/python2.7/dist-packages') Though I must admit that it is a pretty ugly hack, it does work :)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-04-05 06:15:52 -0600

Seen: 1,673 times

Last updated: Apr 06 '14