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

how to subscribe to usb_cam/image_raw to process the image from camera?

asked 2016-12-26 01:33:34 -0600

chaiein gravatar image

updated 2016-12-26 09:22:17 -0600

gvdhoorn gravatar image

what is missing in the below code that is used for subscribing to the topic /usb_cam/image_raw.

void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
  ROS_INFO("I heard: [%s]", msg->data.c_str());
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "main");
  ros::NodeHandle n;

  std::cout<<"Subscribing starts!"<<std::endl;
  ros::Subscriber sub = n.subscribe("usb_cam/image_raw", 2, chatterCallback);

  ros::spin();
  return 0;
}

how to get the image from the camera so that i need to process this image. Is there any files missing in the header.

~/usb_cam/launch$ rostopic info /usb_cam/image_raw
Type: std_msgs/String

Publishers: None

Subscribers: 
 * /listener (http://ubuntu:42711/)
 * /main (http://ubuntu:35605/)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-12-26 12:38:29 -0600

NEngelhard gravatar image

image_raw is most probably a sensor_msgs/Image and not a std_msgs/String so you will need to change the callback function to expect this data type.

So rather

void chatterCallback(const sensor_msgs::Image::ConstPtr& msg)
{
  ROS_INFO("Received image with size: %i x %i", msg->width, msg->height);
}
edit flag offensive delete link more

Question Tools

Stats

Asked: 2016-12-26 01:33:34 -0600

Seen: 1,435 times

Last updated: Dec 26 '16