ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How to publish camera data over ros?

asked 2020-02-05 00:12:38 -0500

alam121 gravatar image


I'm looking to use a usb camera to publish over ros for further computation. Any idea on where I should get started? c

edit retag flag offensive close merge delete



We're here to help, but not to do all of your work. Can you tell us what you've found yourself?

Entering ROS usb camera in Google (or any other search engine) returns quite a few results for me.

gvdhoorn gravatar image gvdhoorn  ( 2020-02-05 02:34:37 -0500 )edit

Sure. getting to start the camera is no big deal. I'm more interested on how to use the camera data to publish for further processing. Cannot find any relevant tutorial for that.

alam121 gravatar image alam121  ( 2020-02-05 03:21:28 -0500 )edit

I would not have guessed that from your question title -- especially not because you then write:

I'm looking to use a usb camera to publish over ros for further computation

Could you please expand your OP a little with some things you would want to do with the "further processing"?

That would give a bit more of an idea what you are looking for.

Processing 2D (and sometimes 3D) imagery is typically done using opencv, for which various packages offering integration are available.

Perhaps also important: note that the typical pattern is to use ROS communication primitives to send and receive data, then leave the actual business logic to use whatever libraries you are comfortable with.

There is no "image processing with ROS" tutorial, as that would not make too much sense: it would essentially show what I described above (ie: receive msg, convert -> use library).

gvdhoorn gravatar image gvdhoorn  ( 2020-02-05 03:26:07 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-02-06 03:44:10 -0500

updated 2020-02-06 18:54:55 -0500

Lets assume that you successfully launched ros package of your camera and your camera is publishing image under a topic called "/camera/image_raw". Then you can receive this image with cv_brdige and converting to a open_cv image in your callback as ;

#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/Image.h>

        // Camera image topic subscriber.
        camera_subscriber_ =
            nh_->subscribe("/camera/image_raw", 1,
                           &YourClass::CameraImageCallback, this);


    //  Callback from camera image topic subscriber.
    void YouClass::CameraImageCallback(
        const sensor_msgs::Image::ConstPtr &msg) {
        cv_bridge::CvImageConstPtr cv_ptr;  // CV bridge image.
        try {
            // Copy the Image msg into the CV bridge variable.
            cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
        } catch (cv_bridge::Exception &e) {
        cv::Mat CameraImg =
            cv_ptr->image;  // Obtain the openCV image from the CVbridge.

     //Do you image processing on opencv image CameraImg

Note that in CMakeList.txt of your project you need to link the open_cv and cv_bridge libraries

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2020-02-05 00:12:38 -0500

Seen: 1,413 times

Last updated: Feb 06 '20