Displaying the image does not work [closed]
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()