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

How can i bridge and display images from realsense d435 camera?

asked 2020-06-11 12:51:23 -0500

Anonymous gravatar image

updated 2020-06-11 13:43:19 -0500

I am a beginner in ros. I am looking to get image frames from an Intel Realsense D435 camera, bridge and show the image (with opencv) . At the same time, I look to print/ log out the information from the camera. After running code, the program continuously runs (due to rospy.spin() function) but does not print out anything.

Where could I be going wrong with the code? Could someone please explain a bit on how to use the ros messages in a python code. I am writing a subscriber node.'

class Depth_Retriever():
    def __init__(self):

        self.bridge = CvBridge()

        self.sub = rospy.Subscriber('/camera/depth/image_rect_raw',Image,callback)

    def callback(self,ros_pics):
        try: 
            my_image = self.bridge.imgmsg_to_cv2(ros_pics, encoding = "passthrough")

        except CvBridgeError as e:
            print("CvBridge could not convert images from realsense to opencv")
        height,width, channels = my_image.shape
        my_height = my_image.shape[0]
        print(my_height)

        self.vert_len = ros_pics.height # retrieve height information from Image msg
        print(self.vert_len)


def main():
    rospy.init_node("Depth",anonymous = True)

    rospy.spin()


if __name__ == '__main__':

    main()

Thank you for help in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-06-12 00:04:44 -0500

achille gravatar image

The callback is never accessed. Change

self.sub = rospy.Subscriber('/camera/depth/image_rect_raw',Image,callback)

to

self.sub = rospy.Subscriber('/camera/depth/image_rect_raw', Image, self.callback)

Some additional comments:

  • If you just want to view images, use rqt_image_view instead
  • use ROS logging instead of prints, that way you can use all the tools associated with it
  • consider using a linter, I see several PEP8 violations ;)
edit flag offensive delete link more

Comments

Thank you so much for the response. I was able to get the code to work. However, when I use cv2.imshow() to display the image, I receive a black image. If I change the datatype from "passthrough" ,when bridging, to other datatype such as "bgr8" it fails to convert. What could be the cause of this black image?

Anonymous gravatar image Anonymous  ( 2020-06-16 15:27:27 -0500 )edit

Don't forget to accept the answer then so the question shows as resolved. What do you see when you run rqt_image_view? And what is the actual encoding (what you call datatype)? It has to be an encoding supported by cv. And what is the actual error you're getting?

achille gravatar image achille  ( 2020-06-16 16:52:57 -0500 )edit

After running the rqt_image_view I realized I was subscribing to the wrong topic. The data encoding was "passthrough". It currently works. Thank you.

Anonymous gravatar image Anonymous  ( 2020-06-18 08:07:07 -0500 )edit

I'm having the same problem, how did you fix it?

danielcjacobs gravatar image danielcjacobs  ( 2020-11-03 14:53:46 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-06-11 12:51:23 -0500

Seen: 2,396 times

Last updated: Jun 12 '20