How to publish camera data over ros?
HI,
I'm looking to use a usb camera to publish over ros for further computation. Any idea on where I should get started? c
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
HI,
I'm looking to use a usb camera to publish over ros for further computation. Any idea on where I should get started? c
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>
YouClass::YourClass(){
// 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) {
return;
}
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
Asked: 2020-02-05 00:12:38 -0600
Seen: 2,196 times
Last updated: Feb 06 '20
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.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.
I would not have guessed that from your question title -- especially not because you then write:
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).