本文主要是介绍[安装配置] TX2上利用Kinect v1录制'TUM'数据集,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
环境设置
- 安装驱动
$ sudo apt-get install ros-indigo-freenect-*
$ rospack profile
- 设置环境变量
echo $TURTLEBOT_3D_SENSOR
#Output: kinect
如果你看到一个3D传感器,例如asus_xtion_pro,您将需要设置环境变量的默认值,修改和重新启动终端:
echo "export TURTLEBOT_3D_SENSOR=kinect" >> .bashrc
如果是asus_xtion_pro相机,设置为asus_xtion_pro。
- 启动相机
在Turtlebot终端执行:
roslaunch turtlebot_bringup minimal.launch
在Turtlebot终端,新开终端,输入
#针对Microsoft Kinect:
$ roslaunch freenect_launch freenect-registered-xyzrgb.launch (新版本)
$ roslaunch openni_launch openni.launch (或旧版本)#针对Asus Xtion, Xtion Pro, or Primesense 1.08/1.09 cameras:
$ roslaunch openni2_launch openni2.launch depth_registration:=true
- 测试相机
图像,在工作站打开终端执行:
$ rosrun image_view image_view image:=/camera/rgb/image_color
$ rosrun image_view image_view image:=/camera/depth_registered/image_raw
- 问题
- 出问题:Kinect的USB链接自动掉线
sudo bash -c 'echo -1 > /sys/module/usbcore/parameters/autosuspend'
lsusb
录制rosbag
rosrun rosbag record /camera/rgb/image_color /camera/depth_registered/image_raw
rosbag保存图片
# coding:utf-8
#!/usr/bin/python# Extract images from a bag file.#PKG = 'beginner_tutorials'
import roslib; #roslib.load_manifest(PKG)
import rosbag
import rospy
import cv2
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
from cv_bridge import CvBridgeError# Reading bag filename from command line or roslaunch parameter.
#import os
#import sysrgb_path = '/home/nvidia/ttttt/rgb/'
depth_path= '/home/nvidia/ttttt/depth/'class ImageCreator():def __init__(self):self.bridge = CvBridge()with rosbag.Bag('/home/nvidia/ttttt/2019-05-10-09-00-55.bag', 'r') as bag: #要读取的bag文件;for topic,msg,t in bag.read_messages():#print(t)if topic == "/camera/rgb/image_color": #图像的topic;try:cv_image = self.bridge.imgmsg_to_cv2(msg,"bgr8")except CvBridgeError as e:print etimestr = "%.6f" % msg.header.stamp.to_sec()#%.6f表示小数点后带有6位,可根据精确度需要修改;image_name = timestr+ ".png" #图像命名:时间戳.pngcv2.imwrite(rgb_path + image_name, cv_image) #保存;elif topic == "/camera/depth_registered/image_raw": #图像的topic;try:cv_image = self.bridge.imgmsg_to_cv2(msg,"16UC1")except CvBridgeError as e:print etimestr = "%.6f" % msg.header.stamp.to_sec()#%.6f表示小数点后带有6位,可根据精确度需要修改;image_name = timestr+ ".png" #图像命名:时间戳.pngcv2.imwrite(depth_path + image_name, cv_image) #保存;if __name__ == '__main__':#rospy.init_node(PKG)try:image_creator = ImageCreator()except rospy.ROSInterruptException:pass
这篇关于[安装配置] TX2上利用Kinect v1录制'TUM'数据集的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!