0
$\begingroup$

Rosanswers logo

I would like to have a pure OpenCV version cv::Mat of the Image on which I can do further modifications. I tried cv_ptr->dImg; but it outputs errors. So far I have

 void imageCb(const sensor_msgs::ImageConstPtr& msg)
   {
    cv_bridge::CvImagePtr cv_ptr;
    try
    {
      cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::TYPE_16UC1);
    }
    catch (cv_bridge::Exception& e)
    {
      ROS_ERROR("cv_bridge exception: %s", e.what());
      return;
    }
    
    // Draw an example circle on the video stream
    //if (cv_ptr->image.rows > 60 && cv_ptr->image.cols > 60)
     // cv::circle(cv_ptr->image, cv::Point(px, py), 10, CV_RGB(255,0,0));
        cv::Mat dImg;

Originally posted by user23fj239 on ROS Answers with karma: 748 on 2016-02-03

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I guess I figured it out. Did I make any mistakes?

cv::Mat dImg =  cv_ptr->image;
     double min = 0;
     double max = 1000;
cv::Mat img_scaled_8u;
cv::Mat(cv_ptr->image-min).convertTo(img_scaled_8u, CV_8UC1, 255. / (max - min));
cv::cvtColor(img_scaled_8u, dImg, CV_GRAY2RGB);
//if (cv_ptr->image.rows > 60 && cv_ptr->image.cols > 60)
//cv::circle(dImg, cv::Point(px, py), 10, CV_RGB(255,0,0));
// Update GUI Window
cv::imshow(OPENCV_WINDOW, dImg);
cv::waitKey(3);

Originally posted by user23fj239 with karma: 748 on 2016-02-03

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by Gushu on 2018-05-24:
I only needed the part of converting cv_bridge image to Mat. It worked for me - thanks!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.