$search
00001 # 00002 # Copyright (c) 2011, Robert Bosch LLC 00003 # All rights reserved. 00004 # 00005 # Redistribution and use in source and binary forms, with or without 00006 # modification, are permitted provided that the following conditions 00007 # are met: 00008 # 00009 # * Redistributions of source code must retain the above copyright 00010 # notice, this list of conditions and the following disclaimer. 00011 # * Redistributions in binary form must reproduce the above 00012 # copyright notice, this list of conditions and the following 00013 # disclaimer in the documentation and/or other materials provided 00014 # with the distribution. 00015 # * Neither the name of Robert Bosch LLC nor the names of its 00016 # contributors may be used to endorse or promote products derived 00017 # from this software without specific prior written permission. 00018 # 00019 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00022 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00023 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00024 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00025 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00027 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00028 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00029 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00030 # POSSIBILITY OF SUCH DAMAGE. 00031 # 00032 # 00033 # 00034 # 00035 # \author Dejan Pangercic 00036 # 00037 00038 #!/usr/bin/env python 00039 # -*- coding: utf-8 -*- 00040 import roslib; roslib.load_manifest('pr2_interactive_segmentation') 00041 import rosbag 00042 from cv_bridge import CvBridge, CvBridgeError 00043 import os 00044 import sys 00045 import shutil 00046 import cv 00047 00048 def grab(file, folder, topic): 00049 bridge = CvBridge() 00050 if file.endswith('.bag'): 00051 bag = rosbag.Bag(file,'r') 00052 index = 1 00053 for topic, msg, t in bag.read_messages(topics=[topic]): 00054 try: 00055 cv_image = bridge.imgmsg_to_cv(msg, "bgr8") 00056 image_name = os.path.join(folder, str("%.4d" % index) + '.png') 00057 index = index + 1 00058 cv.SaveImage(image_name, cv_image) 00059 print "saved %s" % image_name 00060 except CvBridgeError, e: 00061 print e 00062 00063 if __name__ == '__main__': 00064 00065 print "sys.argv.__len__", sys.argv.__len__() 00066 if sys.argv.__len__() != 4: 00067 print "usage bag_to_images.py <bag> <image folder> <topic>" 00068 sys.exit(1) 00069 grab(sys.argv[1], sys.argv[2], sys.argv[3])