【问题标题】:Getting RealSense depth frame in ROS在 ROS 中获取 RealSense 深度帧
【发布时间】:2020-11-06 07:49:12
【问题描述】:

我在 Gazebo 环境中有一架无人机,上面装有 RealSense d435 摄像头。我的计划是使用 YOLO 找到一个感兴趣对象的中心,然后从深度图像中找到那个点的深度。我听说深度相机输出的图像是深度值以 RGB 值编码的。当进一步在网上查找时,我发现有一个 pyrealsense2 库,其中包含我需要的所有功能。

我在网上看到的实现需要你创建一个pyrealsense.pipeline() 并从中获取你的框架。问题是,这似乎只有在您将 RealSense 摄像头连接到您的计算机时才有效。由于我的存在于 Gazebo 环境中,我需要一种在 ROS 回调中获取和使用深度帧的方法。我该怎么做?任何指针将不胜感激

【问题讨论】:

    标签: python ros realsense


    【解决方案1】:

    是的,您可以在 ROS 订阅者的帮助下执行以下操作(大部分代码取自 here):

    import rospy
    from sensor_msgs.msg import Image as msg_Image
    from cv_bridge import CvBridge, CvBridgeError
    import sys
    import os
    
    class ImageListener:
        def __init__(self, topic):
            self.topic = topic
            self.bridge = CvBridge()
            self.sub = rospy.Subscriber(topic, msg_Image, self.imageDepthCallback)
    
        def imageDepthCallback(self, data):
            try:
                cv_image = self.bridge.imgmsg_to_cv2(data, data.encoding)
                pix = (data.width/2, data.height/2)
                sys.stdout.write('%s: Depth at center(%d, %d): %f(mm)\r' % (self.topic, pix[0], pix[1], cv_image[pix[1], pix[0]]))
                sys.stdout.flush()
            except CvBridgeError as e:
                print(e)
                return
    
    
    if __name__ == '__main__':
        rospy.init_node("depth_image_processor")
        topic = '/camera/depth/image_rect_raw'  # check the depth image topic in your Gazebo environmemt and replace this with your
        listener = ImageListener(topic)
        rospy.spin()
    

    注意:要安装 CvBridge,您可以按照以下说明进行操作:

     sudo apt-get install ros-(ROS version name)-cv-bridge
    
     sudo apt-get install ros-(ROS version name)-vision-opencv
    

    更多信息:http://wiki.ros.org/cv_bridge

    【讨论】:

    • 我自己也发现了。非常感谢您的回复。我在网上看到的大多数东西都告诉我使用 pyrealsense2 库中的get_distance 函数,所以我认为它比最终复杂得多
    【解决方案2】:

    为了补充上述答案,请注意 depth/image_rect_raw 主题。很可能您实际上想要原始图像,您可以从 /camera/aligned_depth_to_color/image_raw 获得。

    默认情况下,此主题可能不处于活动状态,例如在 d435i 上,您应该切换 align_depth:=true 选项:

    roslaunch realsense2_camera rs_camera.launch align_depth:=true
    

    请参阅https://github.com/IntelRealSense/realsense-ros#usage-instructions 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      • 2020-01-02
      • 1970-01-01
      • 2020-03-14
      • 1970-01-01
      相关资源
      最近更新 更多