# Open image from file with image_publisher

Hi everybody, I try to publish an an Image (bmp.file) to an camera stream with image_publisher. I want to display this Image with image_view. But here I got an error.

Can somebody tell me how to fix the error?

It would be nice to get a hint.

Greetings

P.S. I'm using kinetic with ubuntu 16.04.

Edit: I want use image_publisher for that issue. But I can't get it run. The Error occurs immediately when I launched the file. Please help me. Solved: edited image path with ($find package) My launchfile (copied from here http://wiki.ros.org/image_publisher) I just edited the image-path: <launch> <node pkg="image_publisher" type="image_publisher" name="mix_image" args="~/mix.bmp" > <param name="flip_horizontal" value="false" /> <param name="flip_vertical" value="false" /> <param name="frame_id" value="my_camera" /> <param name="publish_rate" value="10" /> <param name="camera_info_url" value="file:///$(env HOME)/.ros/camera_info/camera.yaml" />   <!-- relative to ~/.ros/ -->
</node>

</launch>


When I launch that file (from the same directiory where the mix.bmp is saved), I get this output:

nils-ros@nils-ros:~$roslaunch ar_with_ros mix_image_publisher.launch ... logging to /home/nils-ros/.ros/log/efc677ac-8eaf-11ea-a878-1867b0105cea/roslaunch-nils-ros-17494.log Checking log directory for disk usage. This may take awhile. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://nils-ros:35825/ SUMMARY ======== PARAMETERS * /mix_image/camera_info_url: file:////home/nil... * /mix_image/flip_horizontal: False * /mix_image/flip_vertical: False * /mix_image/frame_id: my_camera * /mix_image/publish_rate: 10 * /rosdistro: kinetic * /rosversion: 1.12.14 NODES / mix_image (image_publisher/image_publisher) ROS_MASTER_URI=http://localhost:11311 process[mix_image-1]: started with pid [17511] OpenCV Error: Assertion failed (cap_.isOpened()) in onInit, file /home/nils-ros/ws_moveit/src/image_pipeline/image_publisher/src/nodelet/image_publisher_nodelet.cpp, line 147 [ERROR] [1588670851.783852606]: Failed to load image (~/mix.bmp): cap_.isOpened() onInit /home/nils-ros/ws_moveit/src/image_pipeline/image_publisher/src/nodelet/image_publisher_nodelet.cpp 147  The bmp-file is 480x640Pixel big and colored. It is 922 kB big. I'm using image_publisher as well as image_view from source because I can't call them without. My test: roscd image_publisher/ called ~/ws_moveit/src/image_pipeline/image_publisher For some unknown reason roscd didn't recognized the preinstalled version. That's why I used it from source. Edit2: I deleted image_pipeline from my workspace. Wrote roscd image_ <tab> <tab> on the terminal an only got this output. Solved: see Edit above image_common/ image_transport/ image_geometry/ image_transport_plugins/ After I wrote roscd image_publisher it found the path /opt/ros/kinetic/share/image_publisher . When I now write roscd image_ <tab> <tab> on the terminal it shows me the other image_common/ image_publisher/ image_transport_plugins/ image_geometry/ image_rotate/ image_view/ image_proc/ image_transport/ I still get the same errormessage linking to /home/nils-ros/ws_moveit/src/image_pipeline/image_publisher/src/nodelet/image_publisher_nodelet.cpp 147 also I deleted the image_pipline package and run catkin_make Edit3: I changed the path to$(find ar_with_ros)/image/mix.bmp and I don't get an error anymore. Thank you for that one. But when I want to see the image with image_view I get only this ...

edit retag close merge delete

Sort by » oldest newest most voted

Would image_publisher be sufficient? From its wiki page:

Contains a node [to] publish an image stream from single image file or avi motion file.

Edit: note:

to an camera stream

there are no "camera stream"s, only topics carring sensor_msgs/Image (or any of the compressed variants).

That's what image_publisher does: it reads a file and publishes it as a sensor_msgs/Image.

Edit2:

[ERROR] [1588603210.289589342]: Failed to load image (mix.bmp): cap_.isOpened() onInit /home/nils-ros/ws_moveit/src/image_pipeline/image_publisher/src/nodelet/image_publisher_nodelet.cpp 147


I'm going to guess before you show us the full output of the roslaunch of your .launch file: the path you specify to the image is not correct / complete.

The error message mentions the filename as being mix.bmp. According to this line in image_publisher_nodelet.cpp that error message should contain the full path to the image it's trying to open. mix.bmp is not a full path. So it's likely that this line fails, as it cannot find the image, causing the error your report to be printed.

Assuming this is indeed the cause, you'll need to make sure to pass an absolute and complete path as the first argument to the image_publisher node, or if using the nodelet, the filename parameter.

Only a name of the file will not work. Neither will a relative path.

Edit 3:

<node pkg="image_publisher" type="image_publisher" name="mix_image" args="~/mix.bmp" >


This does indeed confirm my suspicions.

You cannot use ~/mix.bmp as a path. Relative paths don't work in .launch files. See #q331346 for a Q&A which discusses this (and #q235337 and #q271442 for related Q&As).

As I wrote in my earlier edit, you'll have to provide an absolute path.

If you can place the .bmp in a ROS package, you could use something like:

$(find your_ros_pkg)/mix.bmp  which would make the path relative to your_ros_pkg (but return an absolute path, so it avoids your earlier problems). You could also use the $(env ) substitution arg, or perhaps one of the others.

Edit 4:

Edit3: I changed the path to \$(find ar_with_ros)/image/mix.bmp and I don't get an error anymore. Thank you for that one.

Ok, so your question has been solved then.

But when I want to see the image with image_view I getonly this errormessage

That would seem to be a different question, for which it would be best if you post it as a separate question. ROS Answers is a Q&A site (like Stack Overflow), not a regular forum (where threads can go on indefinitely). A ratio of 1-to-1 of questions and answers works best here.

more

That sounds very good. Thanks. I'll try to use that.

( 2020-04-30 05:30:08 -0500 )edit

I tried image_publisher but I get this error.

OpenCV Error: Assertion failed (cap_.isOpened()) in onInit, file /home/nils-ros/ws_moveit/src/image_pipeline/image_publisher/src/nodelet/image_publisher_nodelet.cpp, line 147
[ERROR] [1588603210.289589342]: Failed to load image (mix.bmp): cap_.isOpened() onInit /home/nils-ros/ws_moveit/src/image_pipeline/image_publisher/src/nodelet/image_publisher_nodelet.cpp 147


Can you help me here? I used the first launch-file on the wiki page.

( 2020-05-04 09:46:36 -0500 )edit

Quite a bit more info should be printed when you use that launch file. Please show all of that as well.

Second: why are you building that package from sources? It's released into all currently supported ROS versions and should be an apt install away.

Third: if using a .launch file, alway show it and how you start it.

Do not post that as a comment here. Edit your original question and append a new section to it.

( 2020-05-04 09:51:14 -0500 )edit

I edited my question. I hope you'll understand more now.

( 2020-05-05 05:18:16 -0500 )edit

I opened a new question here. The image_publisher seems to work, but I can't see the Image.

( 2020-05-05 07:02:12 -0500 )edit

I am also getting the same error

rosrun image_publisher image_publish _nodelet rtsp://192.168.0.201:554/live0

OpenCV Error: Assertion failed (cap_.isOpened()) in onInit, file /home/rnd/mav_catkin_ws/src/image_pipeline/image_publisher/src/nodelet/image_publisher_nodelet.cpp, line 147

rosrun image_publisher image_publish rtsp://192.168.0.201:554/live0

while running the node image_publisher and image_publisher_nodelet.

As you might see, I am trying to stream a video (which already I tried to stream its rtsp) and later on RVIZ.

Any suggestions?

( 2021-07-19 08:47:47 -0500 )edit

Sorry I don't have any idea. Btw: I took another way for my project in saving the pictures to the hard disk.

Please start a new question so everybody in this forum notice your question. Try to isolate your failure as good as possible and tell in your question what you have tried to fix it or to find out where the failure is.

try rxgraph, tf_echo, rxconsole and the rostopic commands for debbugging

( 2021-07-25 14:56:42 -0500 )edit