Ask Your Question

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

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

edit flag offensive delete link more


That worked, thank you!

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 519 times

Last updated: Jul 23