【问题标题】:Turtlebot subscriber pointcloud2 shows color in Gazebo simulator but not in robotTurtlebot 订阅者 pointcloud2 在 Gazebo 模拟器中显示颜色,但在机器人中不显示
【发布时间】:2016-11-06 04:22:28
【问题描述】:

我正在订阅带有 ASUS Xtion PRO LIVE 摄像头的海龟机器人(深度学习版)上的主题 "/camera/depth/points" 和消息 PointCloud2

我在gazebo模拟器环境下使用了下面的python脚本,我可以成功接收x、y、z和rgb值。

但是,当我在机器人中运行它时,rgb 值丢失了。

这是我的turtlebot 版本或相机的问题,还是我必须指定要接收PointCloud2 type="XYZRGB" 的地方?还是同步问题?任何线索请感谢!

#!/usr/bin/env python
import rospy
import struct
import ctypes
import sensor_msgs.point_cloud2 as pc2
from sensor_msgs.msg import PointCloud2

file  = open('workfile.txt', 'w')

def callback(msg):

    data_out = pc2.read_points(msg, skip_nans=True)

    loop = True
    while loop:
        try:
            int_data = next(data_out)
            s = struct.pack('>f' ,int_data[3])
            i = struct.unpack('>l',s)[0]
            pack = ctypes.c_uint32(i).value

            r = (pack & 0x00FF0000)>> 16
            g = (pack & 0x0000FF00)>> 8
            b = (pack & 0x000000FF)

            file.write(str(int_data[0])+","+str(int_data[1])+","+str(int_data[2])+","+str(r)+","+str(g)+","+str(b)+"\n")

        except Exception as e:
            rospy.loginfo(e.message)
            loop = False
            file.flush
            file.close

def listener():

    rospy.init_node('writeCloudsToFile', anonymous=True)
    rospy.Subscriber("/camera/depth/points", PointCloud2, callback)
    rospy.spin()

if __name__ == '__main__':
    listener()

【问题讨论】:

  • 华硕 Xtion PRO LIVE
  • 我想我也试过depth-registered,但我现在不记得了,我会检查一次
  • 这可能会有所帮助,我已经尝试过使用 openni 但即使不使用深度注册也无法使其工作。但我认为我没有按照您的链接depth_registration:=true 中的说明设置参数,所以我明天早上会试试这个。 1个问题,使用openni是最正常的方法吗?
  • @peter Brittain 很好,你成功了。 /camera/depth/points 仅显示 xyz,而 /camera/depth_registered/points 显示 xyz 与 rgb 的组合。有趣的是为什么它在凉亭中有所不同......好吧,没关系。如果您将其发布为答案,我会接受。
  • 谢谢!我现在整理了我的 cmets 并将所有内容移到了答案中。

标签: python rgb point-cloud-library ros point-clouds


【解决方案1】:

已发布主题的内容由提供它们的软件(即您的相机的驱动程序)决定。因此,要解决此问题,您需要获取正确的驱动程序并使用它所说的包含所需信息的主题。

您可以在ROS wiki 或一些社区网站(例如this)上找到推荐的相机驱动程序。在您的情况下,华硕设备应使用 openni2 并设置 depth_registration:=true - 如文档中的 here 所述。

此时,/camera/depth_registered/points 现在应该显示组合的 xyz 和 RGB 点云。要使用它,您的新 listener() 代码应如下所示:

def listener():
    rospy.init_node('writeCloudsToFile', anonymous=True)
    # Note the change to the topic name
    rospy.Subscriber("/camera/depth_registered/points", PointCloud2, callback)
    rospy.spin()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 2018-03-24
    • 2012-06-24
    • 1970-01-01
    相关资源
    最近更新 更多