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

cannot use cvimageptr -> expression

asked 2014-09-28 00:44:57 -0600

fromandto gravatar image

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 !

edit retag flag offensive close merge delete


hi administrator, I wonder if there's anything wrong with my question so it's has not been made public

fromandto gravatar image fromandto  ( 2014-09-28 01:37:43 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2014-09-29 08:10:30 -0600

Wolf gravatar image

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


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


sensor_msgs::ImagePtr img2_ = cv_ptr->toImageMsg();  //assign pointer to pointer
edit flag offensive delete link more


Your suggestion helps alot , thx!

fromandto gravatar image fromandto  ( 2014-11-24 10:19:42 -0600 )edit

Question Tools

1 follower


Asked: 2014-09-28 00:44:57 -0600

Seen: 163 times

Last updated: Sep 29 '14