ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
If you need a "screenshot", you have two possibilities:
void save_image(const sensor_msgs::ImageConstPtr img, const std::string prefix)
{
// May want to view raw bayer data
// NB: This is hacky, but should be OK since we have only one image CB.
if (img->encoding.find("bayer") != std::string::npos)
boost::const_pointer_cast<sensor_msgs::image>(img)->encoding = "mono8";
cv::Mat image;
try
{
image = cv_bridge::toCvShare(img, "bgr8")->image;
} catch(cv_bridge::Exception)
{
ROS_ERROR("Unable to convert %s image to bgr8", img->encoding.c_str());
}
std::string directory = std::string(getenv("HOME")) + "/catkin_ws/video_dumper_jpeg/";
std::string filename = (filename_format_ % prefix % count_ ).str();
cv::imwrite(directory + filename, image);
}