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

Include image in roslaunch

asked 2014-05-28 08:06:02 -0500

eirikaso gravatar image

Hi I am creating a launch file for my project. One of my nodes has to load a .jpg image as a part of the code execution. Normally, when using rosrun, I'm located in the folder with the picture when running the code, and it is found automatically by the node.

How do i include this in roslaunch so it is found automatically?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-05-28 08:14:29 -0500

updated 2014-05-28 10:09:27 -0500

You need to use args in your node call in launch file.

<node pkg="rospy_demo" type="listener" args="$(find mypkg)/resources/test.jpg" />. (just random example from google)

For just running the program (with rosrun, for example) put the absolute path to the file - here it will be imread("/home/username/img.jpg") or put the image in the executable folder - it should be devel/lib/package_name/

edit flag offensive delete link more


Hmm. I tried but did not get it working. This is how I am reading the image in the node: Mat objectMat = imread("te.jpg"); Will this be wrong?

eirikaso gravatar image eirikaso  ( 2014-05-28 08:41:10 -0500 )edit

So it's inside the code itself? I don't remember precisely, try placing the image either in the executable folder or launch file folder. With no need in using any args in launch file. You can also pass the image path as an argument - this way you wont need to copy your jpg.

delta785 gravatar image delta785  ( 2014-05-28 08:58:22 -0500 )edit

It is in the code yes. Have tried to put it all over the place now, but still can't find it :( Have also tried to use args to the path like you suggested without any luck

eirikaso gravatar image eirikaso  ( 2014-05-28 09:24:05 -0500 )edit

Try if this works - imread("/home/username/te.jpg"); and put the jpg file in your user folder. For test its fine, but you shouldnt do it often :P

delta785 gravatar image delta785  ( 2014-05-28 09:36:25 -0500 )edit

Anyway it's strange that locating your jpeg file in exe directory doesnt work. Do you put it in devel/lib/package_name/ folder?

delta785 gravatar image delta785  ( 2014-05-28 09:39:16 -0500 )edit

Now it works :) Thanks a lot! Working in both "devel/lib/package_name/" and with your "imread("/home/username/te.jpg")" solution. Is it possible to get it copied into the "devel/lib/package_name/" folder when doing catkin_make?

eirikaso gravatar image eirikaso  ( 2014-05-28 09:49:19 -0500 )edit

Probably somehow it could be done. But you'd better use arguments, it will make your application more flexible.You do it by typing, for example, string name; name = argv[1] and then using it in imread (maybe with some easy data conversion from string to char *).

delta785 gravatar image delta785  ( 2014-05-28 10:05:22 -0500 )edit

and then you can run your program with rosrun mynode mynode te.jpg, and THEN you can add args in your launch file. Hardcoding thingies isn't good

delta785 gravatar image delta785  ( 2014-05-28 10:07:01 -0500 )edit

Question Tools



Asked: 2014-05-28 08:06:02 -0500

Seen: 617 times

Last updated: May 28 '14