convert from sensor_msgs::Image bgr8 to a png file on disk
This is the subroutine I need. What is holding me back from converting the rgb image you send me is converting to a png file. This is done by using cv_bridge to convert from ros to the cv space.
The problem is cv is expecting a const sensor_msgs::imageConstPtr msg
I only have a const sensor_msgs::image. We need to use “boost” some way to make a new member. Do you remember the syntax?
void convert_image_BGR82PNG(const sensor_msgs::Image msg) {
//Convert from the ROS image message to a CvImage suitable for working with OpenCV for processing
cv_bridge::CvImagePtr cv_ptr;
try
{
//Always copy, returning a mutable CvImage
//OpenCV expects color images to use BGR channel order.
const sensor_msgs::ImageConstPtr msgIn;
// msgIn = msg::ConstPtr<msg>;
//msgIn = sensor_msgs::ImageConstPtr(msg);
cv_ptr = cv_bridge::toCvCopy(msgIn,"bgr8");
cv::imwrite("jnk.pcd",cv_ptr->image);
}
catch (cv_bridge::Exception& e)
{
//if there is an error during conversion, display it
ROS_ERROR("tutorialROSOpenCV::main.cpp::cv_bridge exception: %s", e.what());
return;
}
}