从bag包中提取图片数据
1 rosbag info xxx.bag
2 python bag-to-image.py
bag-to-image.py文件内容如下:
#coding:utf-8
import roslib;
import rosbag
import rospy
import cv2
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
from cv_bridge import CvBridgeErrorpath='/home/Data/camera2/' #存放图片的位置
class ImageCreator():def __init__(self):
self.bridge = CvBridge()
with rosbag.Bag('2024-06-07-14-14-46_0.bag', 'r') as bag: #要读取的bag文件;
for topic,msg,t in bag.read_messages():
if topic == "/hik2/hik_cam_node/hik_camera2": #图像的topic;
try:
cv_image = self.bridge.imgmsg_to_cv2(msg,"bgr8")
except CvBridgeError as e:
print e
timestr = "%.6f" % msg.header.stamp.to_sec()
#%.6f表示小数点后带有6位,可根据精确度需要修改;
image_name = timestr+ ".jpg" #图像命名:时间戳.jpg
cv2.imwrite(path+image_name, cv_image) #保存;
if __name__ == '__main__':try:
image_creator = ImageCreator()
except rospy.ROSInterruptException:
pass
从bag包中提取点云数据
1 roscore
2 rosrun pcl_ros bag_to_pcd 2024-06-07-14-14-46_0.bag /avia_3421/livox/lidar pointcloud
( rosrun pcl_ros bag_to_pcd <*.bag> <topic> <output_directory> )
bag数据流可视化
1 rqt_bag <bagname>
Opencalib工具箱标定
手动标定
1 cd ~./manual_calib/
2 ./bin/run_lidar2camera data/1.jpg data/1.pcd data/center_camera-intrinsic.json data/top_center_lidar-to-center_camera-extrinsic.json
手动调整点云和图像,使关键点位置重合
选择Save Image,自动保存图片与相关信息。