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

What is this error for?

asked 2020-07-28 17:37:35 -0500

feynman gravatar image

updated 2020-07-29 03:51:33 -0500

gvdhoorn gravatar image

Here's the code

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>

void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
  try
  {
   cv::imshow("view2", cv_bridge::toCvShare(msg, "mono8")->image);
   cv::waitKey(0);
  }
 catch (cv_bridge::Exception& e)
 {
   ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
 }
}

int main(int argc, char **argv)
{
 ros::init(argc, argv, "imagex");
 ros::NodeHandle nh;
 cv::namedWindow("view2",cv::WINDOW_AUTOSIZE);
 image_transport::ImageTransport it(nh);
 image_transport::Subscriber sub = it.subscribe("final/image", 1, imageCallback);
 ros::spin();
 cv::destroyWindow("view2");
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-07-29 17:29:47 -0500

praskot gravatar image

updated 2020-07-29 17:30:06 -0500

If you mean the error-handling (C++ Exceptions), it is to catch any errors that might arise during cv::imshow("view2", cv_bridge::toCvShare(msg, "mono8")->image);. Primarly during the image conversion to bgr8.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2020-07-28 17:37:35 -0500

Seen: 90 times

Last updated: Jul 29 '20