0
$\begingroup$

Rosanswers logo

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?


Originally posted by Frederik Hagelskjær on ROS Answers with karma: 23 on 2014-04-05

Post score: 1

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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.


Originally posted by jbinney with karma: 606 on 2014-04-06

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$
0
$\begingroup$

Rosanswers logo

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 :)


Originally posted by Frederik Hagelskjær with karma: 23 on 2014-04-19

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.