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

OpenCV and ROS2

asked 2021-07-22 13:45:42 -0600

mintybim gravatar image

I've checked all the related questions here and I still wasn't able to get this example to run. I apologize in advance if the solution was right in front of me and if that offended anyone.

Problem description: I run Ubuntu 20.04 and ROS2 foxy, installed OpenCV 4.5.3.56, via pip, everything is in the system python (no venv/conda), I wanted to get this minimal example of an OpenCV publisher and subscriber to run to get my webcam stream from one node to another. For installation the debian package method was chosen.

The example is found here, I did everything as it is described:

https://automaticaddison.com/getting-started-with-opencv-in-ros-2-foxy-fitzroy-python/

But the step with

rosdep install -i --from-path src --rosdistro foxy -y

returns

ERROR: the following packages/stacks could not have their rosdep keys resolved to system dependencies: cv_basics: Cannot locate rosdep definition for [opencv2]

Question: How do I make this run? Are there any kind of examples for ROS2 where any somewhat modern version of OpenCV and Python/C++ works?

My greatest fear is that I have to use OpenCV 3.2 with Python 2.7 or something like that. Please tell me this is not the case anymore for ROS2.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-07-23 17:55:04 -0600

shonigmann gravatar image

ROS2 is comfortably using Python3, so let that alleviate your concerns.

The error you see wnen using rosdep install is just rosdep telling you that it doesn't know what "opencv2" is for your given OS and so it can't install something that satisfies the requirement listed in the package.xml of your cv_basics pacakge. As for resolutions, I'll refer you to question #232795 which does a good job of explaining how rosdep works and what you can do next.

If you've installed OpenCV2 yourself and have confirmed that the version you've installed matches the version expected by whichever package has the dependency, then you should be okay to ignore the error. You can ignore errors when by adding -r to your rosdep call. This allows rosdep to continue installing dependencies, despite errors.

If you'd rather fix the error, then you probably want to change "opencv2" in your package.xml to "opencv-python" so that rosdep can find it. opencv-python points to OpenCV 4.5.3.56 so it should be what you're looking for.

edit flag offensive delete link more

Comments

That worked, thank you!

mintybim gravatar image mintybim  ( 2021-07-26 07:16:36 -0600 )edit
3

answered 2022-03-14 10:37:46 -0600

jimmycanuck gravatar image

using UBUNTU 20.04 I am following the same tutorial. But, the above solution did not work. I have opencv installed to local python via sudo apt install libopencv-dev python3-opencv Instead, I edited the package.xml file of my project to depend on python3-opencv rather than the suggestions above, and the project built successfully.

As I am still rather new to package management I would appreciate it if anyone could explain why this was what I needed to do rather than the users above. Since I have the same UBUNTU and ROS2 running.

edit flag offensive delete link more

Comments

I had the same issue and this solution worked for me.

benedikt gravatar image benedikt  ( 2022-05-24 11:25:38 -0600 )edit

This worked for me. python3-opencv installs version OpenCV 4.2 which works with Foxy. It was not working when I did pip install opencv-python, I think because that is version 4.5 which probably does not work with Foxy.

Morris gravatar image Morris  ( 2022-10-05 14:49:50 -0600 )edit

I worked me too, thanks. (Ubuntu 22.04, ROS 2 Humble)

kametor gravatar image kametor  ( 2023-01-13 05:12:50 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-07-22 13:45:42 -0600

Seen: 8,696 times

Last updated: Jul 23 '21