Ask Your Question
0

Displaying the image does not work [closed]

asked 2019-11-20 04:50:58 -0600

oovidiustr gravatar image

updated 2019-11-20 06:05:58 -0600

Hello!

I am trying to make a simple program that will show me what the robot see. I want to learn how to use OpenCV.

I am using a real TurtleBot3 burger. It has a camera which give me the image in Compressed format. Before starting my program I launched this node:

<node name="republish" type="republish" pkg="image_transport" output="screen" args="compressed in:=/compressed_image out:=/raw_image" />

And now I have in /raw_image the image in Image format. But my program still is no working.

Below is my code. It stuck when I want to transform the image in OpenCv format.

#!/usr/bin/env python
import rospy
import cv2
from cv_bridge import CvBridge
from sensor_msgs.msg import Image


class MyCamera:
    def __init__ (self):
        self.bridge_object = CvBridge()
        self.image = Image()
        rospy.on_shutdown(self.shutdownhook)

    def show_img(self):
        self.image = rospy.wait_for_message('raw_image', Image)
        cv_image = self.bridge_object.imgmsg_to_cv2(self.image, desired_encoding="bgr8")
        cv2.imshow('image', cv_image)
        cv2.waitKey(1)


    def shutdownhook(self):
        cv2.destroyAllWindows()


def run():
    rospy.init_node('my_camera_node')
    obj = MyCamera()
    while not rospy.is_shutdown():
        obj.show_img()
        rospy.sleep(1)


if __name__ == '__main__':
    run()
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by oovidiustr
close date 2019-12-02 01:32:09.195533

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-11-21 09:26:53 -0600

oovidiustr gravatar image

I found the problem... I didn't set the good topic where to subscribe.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-11-20 04:50:58 -0600

Seen: 21 times

Last updated: Nov 21