Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

extract images from bag file python

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2016 Massachusetts Institute of Technology
# updated just two lines vs the original
"""Extract images from a rosbag.
"""

import os
import argparse

import cv2

import rosbag
from sensor_msgs.msg import Image
from cv_bridge import CvBridge

def main():
    """Extract a folder of images from a rosbag.
    """
    parser = argparse.ArgumentParser(description="Extract images from a ROS bag.")
    parser.add_argument("bag_file", help="Input ROS bag.")
    parser.add_argument("output_dir", help="Output directory.")
    parser.add_argument("image_topic", help="Image topic.")

    args = parser.parse_args()

    print "Extract images from %s on topic %s into %s" % (args.bag_file,
                                                          args.image_topic, args.output_dir)

    bag = rosbag.Bag(args.bag_file, "r")
    bridge = CvBridge()
    count = 0
    for topic, msg, t in bag.read_messages(topics=[args.image_topic]):
        # update the desired_encoding to rgb8 or bgr8 or something else ... depending on your sensor
        cv_img = bridge.imgmsg_to_cv2(msg, desired_encoding="passthrough") 

        cv2.imwrite(os.path.join(args.output_dir, "frame%06i.png" % count), cv_img)
        count += 1
        print("Wrote image %i" % count)

        

    bag.close()

    return

if __name__ == '__main__':
    main()
Comment

PREVIOUS NEXT
Code Example
Python :: per gjera te shumta. Python 
Python :: anaconda create new environment 
Python :: how do i change the hue color in seaborn 
Python :: python list comprehension index, value 
Python :: sort list of files by name python 
Python :: find record in mongodb with mongodb object id python 
Python :: pandast change datetime to date 
Python :: sort a pandas dataframe based on date and time 
Python :: taking hour information from time in pandas 
Python :: annaul sum resample pandas 
Python :: radix sort python 
Python :: print the heat map python 
Python :: selenium find element by link text python 
Python :: how to access a private attribute in child class python 
Python :: flask give port number 
Python :: split every character python 
Python :: .annotate unique distinct 
Python :: python date + days 
Python :: python pickle save and load multiple variables 
Python :: tag for deleting from a list in python 
Python :: django templateview 
Python :: bring tkinter window to front 
Python :: python class documentation 
Python :: tkinter maximize window 
Python :: tbc full form in cricket 
Python :: dont filter= true in scrapy 
Python :: python cache return value 
Python :: bulk file name changer in python 
Python :: text to speech to specific language python 
Python :: how to plot heatmap in python 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =