Using ROS with OpenCV

When developing perception algorithms for robotics, OpenCV is an excellent open source computer vision library to use. Like ROS, it has interfaces for both Python and C++ and is designed for real-time applications.

ROS Kinetic actually comes with OpenCV v3.2.0. There are two packages, both available on the GitHub link from the ROS Wiki, that are very handy for combining ROS with OpenCV:

  • cv_camera  uses OpenCV to capture a camera image. It can be run as either a node or nodelet. Images and calibration parameters are published as ROS messages on the topics sensor_msgs/Image and sensor_msgs/CameraInfo. There is also a set of camera parameters that can be fine tuned for the task at hand.
  • vision_opencv is an interface for ROS and OpenCV. This is required because OpenCV images are not ROS messages. Specifically, the cv_bridge package provides a means to readily convert between ROS Image messages and OpenCV images. Similarly, the image_geometry package provides a way to interpret the images geometrically by interfacing ROS calibration parameters (sensor_msgs/CameraInfo) with OpenCV functions like rectification.

A complete example showing how to capture images using a built in laptop camera, apply canny edge detection to the images, then stream the output over a ROS topic can be found in this FunWithROS Github repository. Example output is shown below

CannyImage

Rqt image view showing the output of canny edge detection using ROS and OpenCV.

One thought on “Using ROS with OpenCV

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s