Skip to content

Instantly share code, notes, and snippets.

@mpkuse
Created December 14, 2018 09:53
Show Gist options
  • Save mpkuse/fb86a7ba81bd69666dba657e64d79494 to your computer and use it in GitHub Desktop.
Save mpkuse/fb86a7ba81bd69666dba657e64d79494 to your computer and use it in GitHub Desktop.
ROS bag to images
import rosbag
from cv_bridge import CvBridge, CvBridgeError
import cv2
# Input : A ros-bag
# Output : Save the image msg as individual images. Edit as appropriate.
bag = rosbag.Bag('banana.bag')
for topic, msg, t in bag.read_messages(topics=['/mynteye/right/image_raw']):
# print msg
stamp = str(msg.header.stamp)
cv_image = CvBridge().imgmsg_to_cv2(msg )
print cv_image.shape
cv2.imshow( 'win', cv_image )
cv2.waitKey(30)
print stamp+'.jpg'
cv2.imwrite( 'right/%s.jpg' %(stamp), cv_image )
bag.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment