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

cannot use cvimageptr -> expression

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

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

Comments

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 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

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

Wolf gravatar image

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

See:

http://docs.ros.org/indigo/api/cv_bri...

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
edit flag offensive delete link more

Comments

Your suggestion helps alot , thx!

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

Question Tools

1 follower

Stats

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

Seen: 164 times

Last updated: Sep 29 '14