ZED2同步订阅RGB与Depth用于室内场景分析

1.安装ZED2相机SDK
chmod +x ZED_SDK_Tegra_JP45_v3.5.0.run
sudo ./ZED_SDK_Tegra_JP45_v3.5.0.run
相机校准,zed2 sdk安装在目录usr/locsl/zed
, 在usr/local/zed/tools
下运行
ZED_Calibration
2.编译zed_ros
mkdir -p zed_ws/src
cd zed_ws/src
git clone --recursive https://github.com/stereolabs/zed-ros-wrapper.git
cd ../
rosdep install --from-paths src --ignore-src -r -y
catkin_make -DCMAKE_BUILD_TYPE=Release
echo "source ~/zed_ws/devel/setup.bash">> ~/.bashrc
source ~/.bashrc
3.运行
roslaunch zed_wrapper zed2.launch
使用rqt或rviz订阅zed2相机发布的话题,查看相机捕获到的信息
rqt # 或 rviz
4.ROS同时订阅zed2两个话题同步处理
由于做室内场景分析使用RGB-D数据,需要同时使用RGB图像与Depth图像作为输入,因此需要同时订阅两个话题同步处理
# -*- coding: utf-8 -*-
import rospy
import message_filters
from sensor_msgs.msg import Image, CompressedImage
from cv_bridge import CvBridge, CvBridgeError
import cv2
import numpy as np
class rgbd():
def __init__(self):
# 带宽可能不足导致卡顿,订阅压缩话题
rgb = message_filters.Subscriber('/camera/color/image_raw/compressed', CompressedImage, queue_size=10,
buff_size=2 ** 24)
depth = message_filters.Subscriber('/camera/depth/image_rect_raw', Image, queue_size=10,
buff_size=2 ** 24)
# 同步时间戳
ts = message_filters.ApproximateTimeSynchronizer([rgb, depth], 10, 0.1, allow_headerless=True)
# 执行回调函数
ts.registerCallback(self.callback)
def callback(self, rgb, depth):
bridge = CvBridge()
# 解码压缩
rgb_image = cv2.imdecode(np.fromstring(rgb.data, dtype=np.int8), cv2.IMREAD_COLOR)
# 转16位深度图
depth_image = bridge.imgmsg_to_cv2(depth, '32FC1')
depth_image = np.array(depth_image, dtype=np.float)
depth_image = depth_image * 1000
depth_image = np.round(depth_image).astype(np.uint16)
# 显示
cv2.imshow('rgb', rgb_image)
cv2.imshow('depth', depth_image)
cv2.waitKey(1)
if __name__ == '__main__':
rospy.init_node('rgbd')
rgbd = rgbd()
rospy.spin()