0
$\begingroup$

Rosanswers logo

Hi,

My name is Junifer. I am a student at a university. I am working with ROS and OpenCV. I installed 2 version of OpenCV and Python in my computer.

OpenCV 3.4.3 - Python 3

OpenCV 2.4.8 - Python 2

And I realize that ROS is working with "OpenCV 2.4.8 - Python 2 ".

I want to use "OpenCV 3.4.3 - Python 3 " for ROS. What should i do now ?

Help me...Thank you so much !


Edit: Hi @l4ncelot, I tried but it's not working.

Question 1: Before run this code:

export PYTHONPATH=$PYTHONPATH:/opt/ros/indigo/lib/python3.5/dist-packages

Do i need to copy python3.4/dis-package folder to /opt/ros/indigo/lib/ ?

Case 1: I just run this code with without moving any file. Fisrt line is okay. Second line give an error:

sed: -e expression #1, char 12: unknown option to `s'

Case 2: I try to copy dist-package from python 3.4 folder (I using python 3.4). But i realized that content of python3.4/dist-package is different with python2.7/dist-package.

Particularly, python2.7/dist-package have files of ROS but python3.4/dist-package haven't them. Can you explain for me ?


Originally posted by ToanJunifer on ROS Answers with karma: 7 on 2018-10-09

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Edit: Sorry, I've overlooked somehow you're using python instead of c++. I'm not familiar with python in ROS that much, but here might be answer for you. It seems like you need to remove /opt/ros/indigo/lib/python2.7/dist-packages from your PYTHONPATH environment variable and replace it with the path to your python3 package (this should be something similar to /opt/ros/indigo/lib/python3.5/dist-packages depending on where your python is installed).

You can do it by adding these lines in the end of your .bashrc file at home directory:

export PYTHONPATH=$PYTHONPATH:/opt/ros/indigo/lib/python3.5/dist-packages
export PYTHONPATH=$(echo $PYTHONPATH | sed -e 's/\/opt\/ros\/indigo\/lib\/python2.7\/dist-packages//g')

The first line adds your python3 path to your PYTHONPATH system variable (again, this is just example of the path, yours path to the python3 can be different). The second line removes your old python2 path.

c++ version: You can find the correct version through your CMakeLists.txt file in yoru ROS package:

find_package(OpenCV 3.4.3 REQUIRED)

Look here for documentation of find_package.


Originally posted by l4ncelot with karma: 826 on 2018-10-09

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by ToanJunifer on 2018-10-09:
Hi C4ncelot,

Thank you so much for your support. I so glad, and I going to try this way to solve it.

And, do you know the most advantages of Ros? I am know not clearly about it.

I hope you will response me and discuss about it.

Thank you again!

Comment by l4ncelot on 2018-10-10:
@ToanJunifer, glad to help. I'm not the right one to explain full advantages of ROS in detail. Try to look at q#200423 for some basics. ROS is basically set of libraries, tools, communication layer etc...

Comment by l4ncelot on 2018-10-10:
... everything you need to build some robots. Image if ROS wouldn't exist. How would you e.g. program some mobile robot to navigate through unknown environment? What would you need to code except for your main algorithms? What about communication between your code? What about architecture? ...

Comment by l4ncelot on 2018-10-10:
... what about hardware drivers, debug tools etc.? Before ROS robotic research was primarily done at universities and not many universities were collaborating with each other. And when they did, each collaboration group had their own solution to the problem described above...

Comment by l4ncelot on 2018-10-10:
... There wasn't one solid approach everybody would use and improve. Now with ROS you basically don't need to solve above problems. Learning ROS is not easy, but it's a lot easier than solving everything on your own. Collaboration between the community is great advantage of ROS thanks to the...

Comment by l4ncelot on 2018-10-10:
... modularity of ROS packages. If you want to use package e.g. for obstacle avoidance using laser range finder you basically download it, look at the documentation about that particular package, find out input/output topics and connect it to your packages with subscribers/publishers of your own.

Comment by ToanJunifer on 2018-10-11:
Hi @l4ncelot, Do i need to copy python3.4/dis-package folder to /opt/ros/indigo/lib/ before run first line?

Comment by l4ncelot on 2018-10-11:
@ToanJunifer, Q1: No, just use the path you're working with. My path was just example, you need to replace it with yours. Q2: Sorry, I forgot about the escape characters. I've updated the syntax.

Comment by ToanJunifer on 2018-10-11:
I sorry for this issue again. But i dont understand clearly:

adding these lines in the end of your .bashrc file at home directory

It's mean run 2 lines command in terminal, right ?

Comment by l4ncelot on 2018-10-11:
You can run those in terminal to try out whether it works or not. But if you close your terminal or open a new one those changes won't be there. .bashrc file is bash script which is run every time new terminal is opened...

Comment by l4ncelot on 2018-10-11:
... More on that e.g. here.

Comment by l4ncelot on 2018-10-11:
This is the same thing you did while installing ROS itself. Look here for section "Environment setup". Command echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc adds source /opt/ros/kinetic/setup.bash line to your .bashrc file.

Comment by ToanJunifer on 2018-10-11:
Thank you @l4ncelot, It's work. Thank you so much.

But when i check version:

OpenCV : 2.4.8

Python: 2.7

It's seem like we only use library of Python3

Comment by l4ncelot on 2018-10-11:
Python3 or Python2?

Comment by ToanJunifer on 2018-10-11:
In code file code I run check python and opencv version. I show me: opencv 2.4.8 python 2.7 but it can run package in python3

Comment by l4ncelot on 2018-10-11:
How did you install both versions of opencv? Can't you just remove the old version of opencv?

Comment by l4ncelot on 2018-10-11:
Or try to remove opencv2 library with rm /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so command and try it out. But copy this library somewhere else first, so you can undo the process!!!

Comment by ToanJunifer on 2018-10-11:
Thank you for your advise. I need to make some demo project to check it. If have some trouble i will response to here. Have a nice day, @l4ncelot !

Comment by ToanJunifer on 2018-10-17:
I really want to use Python 3 and OpenCV 3. Do you use teamview ? Can you remote my compute to change it ? Thank you, @l4ncelot

Comment by l4ncelot on 2018-10-18:
@ToanJunifer sorry I couldn't help, unselect my answer so that somebody more familiar with python can help you. You could try to build the whole ROS using python3 as suggested in q#237613.

Comment by ToanJunifer on 2018-10-18:
Anyway thank you so much, buddy!

$\endgroup$

Your Answer

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