0
$\begingroup$

Rosanswers logo

I have one urdf model of a car. It gets one camera in front of it. its grabbing the picture and publishing on a topic. I have write a callBack function where it will receive the image data. By the pixel by pixel data it will convert it to a opencv image, and will display on a window. Now my next step is to use the image data to track one target object. which will be the best way to do. I am really stuck in here.

 flag = 0;
 ROS_INFO("in image node function");
 int h = *(&img->height);
 int w = *(&img->width);
 cv::WImageBuffer3_b image(h,w);
 int step = image.WidthStep();
 step = 3; 
 for(int i=(h-1);i>=0;i--)
   {
    for(int j=(w-1);j>=0;j--)
     { 
       *(image(i,j)) = *(&img->data[count]);
       count++;
       *(image(i,j)+1) = *(&img->data[count]);
       count++;
       *(image(i,j)+2) = *(&img->data[count]);
        count++;
      }
    }
 //ROS_INFO("data = [%d]",*(&img->data[0]));
 cvStartWindowThread();
cvShowImage("view",image.Ipl());

the above is my imagecall back function. I have all the pixel data. please help me. Thank you in advance


Originally posted by Robot on ROS Answers with karma: 180 on 2014-10-06

Post score: 0


Original comments

Comment by Robot on 2014-10-06:
I am really stuck in here, please give me any hints,,, thank you in advance

Comment by ahendrix on 2014-10-06:
This has been the topic of a great many PhD theses. It may help if you can constrain your problem a little bit.

Comment by Robot on 2014-10-06:
using those pixel data I am able to generate the image. it is perfectly showing. the problem is the structure I am using to store the image file with all the relevant data is a WImagebuffer3_b. In order to perform any image processing I am gonna need in cv::Mat format. will cv_bridge will be perfect

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

It sounds like you may be looking for the cv_bridge conversion tutorial: http://wiki.ros.org/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages


Originally posted by ahendrix with karma: 47576 on 2014-10-06

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Robot on 2014-10-07:
undefined reference to `cv_bridge::toCvCopy(boost::shared_ptr<sensor_msgs::Image_std::allocator<void > const> const&, std::basic_string<char, std::char_traits, std::allocator > const&)' this is the error I am getting all the time.. any idea???? please...

Comment by bchiffreville on 2014-10-07:
Did you add cv_bridge in your package.xml and CMakeLists ? CMakeLists :

find_package(catkin REQUIRED COMPONENTS 
    roscpp 
    (...) 
    cv_bridge (...)
)

package.xml :

<build_depend>cv_bridge</build_depend>
<run_depend>cv_bridge</run_depend>

and did you include it ?

Comment by Robot on 2014-10-07:
I am sorry it worked. I missed to ad the cv_bridge in the CMakelist.txt....

Comment by Robot on 2014-10-07:
now it is in cv_bridge::CvImagePtr*. but I want it as a cv_Mat& format. what would be the next step.. thanks again.....

Comment by ahendrix on 2014-10-07:
The image member of the CvImage class is a cv::Mat.

$\endgroup$

Your Answer

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