rosbagToPictures.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import os
import cv2
savePath = 'highwayPictures'
if not os.path.exists(savePath):
os.makedirs(savePath)
count = 0
bridge = CvBridge()
def callbackFunc(image):
global count
global bridge
try: #将ROS图像消息转换为OpenCV图像,输入是图像消息image,bgr8是OpenCV图像编码
frame = bridge.imgmsg_to_cv2(image, "bgr8")
count += 1
print('frame {} receive success'.format(count)