资源简介
可以将ros包中的颜色图和深度图读取出来,并保存到对应文件夹下。
使用时仅需要修改对应话题和路径即可。
代码片段和文件信息
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 sys
rgb_path= ‘/home/zxt/Documents/data/rgb_png/‘
depth_path= ‘/home/zxt/Documents/data/depth_png/‘
class ImageCreator():
def __init__(self):
self.bridge = CvBridge()
i=0
j=0
with rosbag.Bag(‘/home/zxt/Documents/data/2020-11-04-15-37-56.bag‘ ‘r‘) as bag:
for topicmsgt in bag.read_messages():
if topic == “/camera/color/image_raw“:
try:
cv_image = self.bridge.imgmsg_to_cv2(msg“bgr8“)
except CvBridgeError as e:
print e
评论
共有 条评论