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

Where do I save an Image for calling it with cv::imread

asked 2015-06-26 14:58:00 -0500

erivera1802 gravatar image

updated 2015-06-26 17:48:39 -0500

lucasw gravatar image

Hi! I'm using opencv for reading an image that later I'm going to use as a reference in my ROS node, the problem is that my code isn't reading it. I saved it in the src folder inside the package folder, that is, in the same folder as the .cpp Here is the code that does it:

    cv_ptr=cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
    cv::Mat img2;
    //Thresholding
    cv::cvtColor(cv_ptr->image,img2,CV_BGR2GRAY);
    Mat img1 = imread("bucher.jpg", CV_LOAD_IMAGE_GRAYSCALE );
    if( img1.empty() ) {
      printf("Error occured, image not read correctly");
            }

The terminal is always showing me that error, then it isnt reading correctly the image. I don't know if maybe I have to modify something in the CMakeLists.txt to be able to use the image.

I apreciate your help, thanks

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2015-06-26 17:52:12 -0500

lucasw gravatar image

Pass the location of the image as a param in a launch file like:

<param name="image" value="$(find your_pkg)/src/bucher.jpg">

Or use find package in the source as in http://wiki.ros.org/Packages#C.2B-.2B-

std::string image = ros::package::getPath("your_pkg") + "/src/bucher.jpg";
edit flag offensive delete link more

Comments

for the second solution, where goes that line?. And where you write "your_pkg" i write the name of the package or the entire path? Then image would be a ROS type image, so i would need to convert it with cv-bridge? Thanks a lot!·

erivera1802 gravatar image erivera1802  ( 2015-06-26 18:14:55 -0500 )edit

I would prefer the first one ... hard coded paths ... well ... are just ugly for reusing your node, well except you know that nobody ever will change it for any reason, like an icon for an application for example ...

cyborg-x1 gravatar image cyborg-x1  ( 2015-06-26 18:33:48 -0500 )edit

The problem is that i havent used any launch file yet. But if I do so, in my code i just call image und is an image type message? Thanks

erivera1802 gravatar image erivera1802  ( 2015-06-26 19:44:21 -0500 )edit

Oooook I wasnt understanding at all. Yep, lucasw solution worked perfectly!

Thanks

erivera1802 gravatar image erivera1802  ( 2015-06-26 23:01:22 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-26 14:58:00 -0500

Seen: 1,069 times

Last updated: Jun 26 '15