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

Substitute for image_view for command line

asked 2021-09-17 04:50:59 -0500

shankk gravatar image

So, I have a node which continuously publishes images on the /image_raw topic as sensor_msgs.Image objects. To test it I decided to use the image_view package. But the package is giving an error and I suppose it's because I don't have GUI in which a window could open and show the image. It is purely a command line interface. Can someone suggest an alternate package or a workaround. Thanks.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2021-09-17 05:53:50 -0500

Ranjit Kathiriya gravatar image

updated 2021-09-17 07:42:20 -0500

Hello @shankk,

Terminal Check:

$ rostopic list

It will give you the list of topics been published.

$ rostopic echo /image_publish_topic_name

You can get an array of integers with random numbers that means your image is published and it is perfect.

image description

Your output can be in this form described in the above image.

Browser Check:

You can view this stream in your browser.

I think a browser will be a good Substitute.


import rclpy
from rclpy.node import Node
from cv_bridge import CvBridge
from sensor_msgs.msg import Image


class ImageNode(Node):
    def __init__(self):
        super().__init__("image_save_jpg")
        self.subscriber_ = self.create_subscription(
            Image, "Your_image_channel_name", self.callback, 10)
        self.get_logger().info("Images saved has been started.")
        self.counter = 0

    def callback(data):
        br = CvBridge()
        rospy.loginfo("receiving video frame")
        # Convert ROS Image message to OpenCV image
        current_frame = br.imgmsg_to_cv2(data)
        # saved image to jpg , counter for unique name
        cv2.imwrite("path"+self.counter+".jpeg", img)
        self.counter += 1



def main(args=None):
    rclpy.init(args=args)
    node = SmartphoneNode()
    rclpy.spin(node)
    rclpy.shutdown()


if __name__ == "__main__":
    main()

I hope this helps you,

edit flag offensive delete link more

Comments

I would like to get a jpeg file through some package like image_view.

shankk gravatar image shankk  ( 2021-09-17 07:13:19 -0500 )edit

You can create a custom subscriber that does this task for you.

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-09-17 07:31:08 -0500 )edit

@Ranjit After some research I found that the image_view package has this node called image_saver which can be used to save he published images as jpg files. But I faced an issue with that. Since my node continuously (after every few ms) publishes images on the topic, using image_saver immediately filled the directory with hundreds of files. But I found a workaround for that. image_saver has a filename_format parameter through which we can make it use the same filename every time and hence make it overwrite on the same file.

shankk gravatar image shankk  ( 2021-09-17 09:44:38 -0500 )edit

Can you please have a look at this question it saves images with time stamp #q283724, so every time file will get a new name and you can get rid of your overwrite issue.

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-09-17 10:21:08 -0500 )edit
0

answered 2021-09-17 05:24:44 -0500

gvdhoorn gravatar image

updated 2021-09-17 08:48:30 -0500

You could take a look at dheera/rosshow.

Alternatively: run image_view on a remote system which does have the capability to run GUI programs. ROS is distributed by nature, so that should work.

I would like the file to be intact. I just want to know if the files are being published correctly or not

if you can't use a remote system, you could use the image_saver node from the image_viewer package (ROS Index link). It should work in the same way as it did in ROS 1.

No need to write anything custom yourself.

edit flag offensive delete link more

Comments

I will say that the rosshow package/node is very handy. But I would like the file to be intact. I just want to know if the files are being published correctly or not. I would then use scp to transfer that jpeg file to a system which has GUI and view it there.

shankk gravatar image shankk  ( 2021-09-17 07:16:10 -0500 )edit

Question Tools

Stats

Asked: 2021-09-17 04:48:52 -0500

Seen: 211 times

Last updated: Sep 17 '21