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

Why prefer to use uvc_camera instead of cv::Capture when working with OpenCV?

asked 2015-04-01 12:11:05 -0500

rbaleksandar gravatar image


ROS offers its own way of grabbing data from cameras (for example: a normal web cam most of us have integrated in our notebooks) using the uvc_camera driver. Now I'm not asking why use this at all. I'm simply curious when exactly should I use it? Imagine you have a web cam and the first thing you want to do with the image data from it is to process it with OpenCV and then publish it to the rest of the running ROS nodes in the system. This means that no other node except the one running with OpenCV in it has access to the camera hence why would I go in this case first for uvc_camera and then for the cv::Mat format, which is required for OpenCV? Note that in the situation above I presume that OpenCV supports capturing from the device and also have in mind that I'm not asking about image_transport, which has the role of hiding the complexity of transferring images between nodes (subscriber/publisher for example) and is not directly responsible for the capturing of data from the device.

Thanks! RB

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-14 03:34:08 -0500

Wolf gravatar image

If you separate your camera driver and the image processing into two nodes (as i think it's the most common pattern when using ROS) you can e. g. record the images of your camera driver into a ros bag file and then replay the recorded images for testing your image processing algorithm as often as you like without having to be connected to any physical camera device/robot hardware. The main advantage of using ros for such approach is that for your processor node it will be completely transparent from where the images are coming (rosbag/real camera/whatever). You do not have to change any line of code in your processor node for running it with rosbag or with the camera driver.

The drawback of two nodes is of course that the image data will be copied when it is published from driver to processor node. This might have some computational costs, exp. for images at high resolution/frame rate. But you can even overcome this problem if you put your driver and processor into nodelets ( ) and use shared_ptrs when for the publish/subscribe methods/calbacks. This implements separable code without unrequired copies.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-04-01 12:11:05 -0500

Seen: 259 times

Last updated: Apr 14 '15