环境设置
安装驱动
$
sudo apt-get install ros-indigo-freenect-*
$ rospack profile
设置环境变量
echo $TURTLEBOT_3D_SENSOR
如果你看到一个3D传感器,例如asus_xtion_pro,您将需要设置环境变量的默认值,修改和重新启动终端:
echo "export TURTLEBOT_3D_SENSOR=kinect" >> .bashrc
如果是asus_xtion_pro相机,设置为asus_xtion_pro。
启动相机
在Turtlebot终端执行:
roslaunch turtlebot_bringup minimal.launch
在Turtlebot终端,新开终端,输入
$ roslaunch freenect_launch freenect-registered-xyzrgb.launch (新版本)
$ roslaunch openni_launch openni.launch
(或旧版本
)
$ 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保存图片
import roslib
;
import rosbag
import rospy
import cv2
from sensor_msgs
.msg
import Image
from cv_bridge
import CvBridge
from cv_bridge
import CvBridgeError
rgb_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
:
for topic
,msg
,t
in bag
.read_messages
():
if topic
== "/camera/rgb/image_color":
try:
cv_image
= self
.bridge
.imgmsg_to_cv2
(msg
,"bgr8")
except CvBridgeError
as e
:
print e
timestr
= "%.6f" % msg
.header
.stamp
.to_sec
()
image_name
= timestr
+ ".png"
cv2
.imwrite
(rgb_path
+ image_name
, cv_image
)
elif topic
== "/camera/depth_registered/image_raw":
try:
cv_image
= self
.bridge
.imgmsg_to_cv2
(msg
,"16UC1")
except CvBridgeError
as e
:
print e
timestr
= "%.6f" % msg
.header
.stamp
.to_sec
()
image_name
= timestr
+ ".png"
cv2
.imwrite
(depth_path
+ image_name
, cv_image
)
if __name__
== '__main__':
try:
image_creator
= ImageCreator
()
except rospy
.ROSInterruptException
:
pass