0
$\begingroup$

Rosanswers logo

I am trying to write a converter from rgb to gray image

and here comes the code :


cv_bridge::CvImagePtr cv_ptr;

cv_ptr = cv_bridge::toCvCopy(img_ , enc::MONO8);

sensor_msgs::Image img2_ = cv_ptr->toImageMsg();

image_pub_.publish(img2_, *ci);


But the compiler says

/root/catkin_ws/src/usb_cam/nodes/usb_cam_node.cpp:178:51: error: conversion from ‘sensor_msgs::ImagePtr {aka boost::shared_ptr<sensor_msgs::Image_std::allocator<void > >}’ to non-scalar type ‘sensor_msgs::Image’ requested

which maybe means it cannot access the function toImageMsg() from cv_ptr

Hope anyone could help me out of this !


Originally posted by fromandto on ROS Answers with karma: 27 on 2014-09-28

Post score: 0


Original comments

Comment by fromandto on 2014-09-28:
hi administrator, I wonder if there's anything wrong with my question so it's has not been made public

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

The call cv_ptr->toImageMsg(); retuns you an instance of sensor_msgs::ImagePtr

See:

http://docs.ros.org/indigo/api/cv_bridge/html/c++/classcv__bridge_1_1CvImage.html#a48a7cc72fa96bdf0180d0306543ceb07

In your line

sensor_msgs::Image img2_ = cv_ptr->toImageMsg();

you attempt to assign the pointer to an object.

So try either:

sensor_msgs::Image img2_ = *(cv_ptr->toImageMsg());  // dereference pointer to get content before assigning to object

or:

sensor_msgs::ImagePtr img2_ = cv_ptr->toImageMsg();  //assign pointer to pointer

Originally posted by Wolf with karma: 7555 on 2014-09-29

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by fromandto on 2014-11-24:
Your suggestion helps alot , thx!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.