Rosanswers logo

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


But the step with

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


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.

Originally posted by mintybim on ROS Answers with karma: 3 on 2021-07-22

Post score: 0


2 Answers 2


Rosanswers logo

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 so it should be what you're looking for.

Originally posted by shonigmann with karma: 1567 on 2021-07-23

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by mintybim on 2021-07-26:
That worked, thank you!


Rosanswers logo

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.

Originally posted by jimmycanuck with karma: 31 on 2022-03-14

This answer was NOT ACCEPTED on the original site

Post score: 3

Original comments

Comment by benedikt on 2022-05-24:
I had the same issue and this solution worked for me.

Comment by Morris on 2022-10-05:
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.

Comment by kametor on 2023-01-13:
I worked me too, thanks. (Ubuntu 22.04, ROS 2 Humble)


Your Answer

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