test07_unique_features.py
Go to the documentation of this file.
00001 import csv
00002 import roslib; roslib.load_manifest('hai_sandbox')
00003 from cv_bridge.cv_bridge import CvBridge, CvBridgeError
00004 import rospy
00005 import cv
00006 import sys
00007 
00008 import hrl_lib.rutils as ru
00009 import hrl_lib.tf_utils as tfu
00010 import tf.transformations as tr
00011 import tf
00012 import hrl_camera.ros_camera as cam
00013 from sensor_msgs.msg import CameraInfo
00014 import numpy as np
00015 import hai_sandbox.features as fea
00016 import os.path as pt
00017 import hrl_lib.util as ut
00018 
00019 
00020 ##
00021 # @param bagname
00022 # @param topic
00023 # @return features_list list of tuples [(float time, (list surf_keypoints, list surf_descriptors))...]
00024 def find_image_features(bagname, topic):
00025     features_list = []
00026     bridge = CvBridge()
00027     i = 0
00028     for topic, msg, t in ru.bag_iter(bagname, [topic]):
00029         t = msg.header.stamp.to_time()
00030         image = bridge.imgmsg_to_cv(msg, 'bgr8')
00031         image_gray = fea.grayscale(image)
00032         surf_keypoints, surf_descriptors = fea.surf(image_gray)
00033         features_list.append((t, (surf_keypoints, surf_descriptors)))
00034         rospy.loginfo("%.3f frame %d found %d points" % (t, i, len(surf_keypoints)))
00035         i = i + 1
00036     return features_list
00037 
00038 def csv_bag_names(fname):
00039     csv_file = open(fname)
00040     for bag_name in csv.reader(csv_file):
00041         yield bag_name
00042     csv_file.close()
00043 
00044 if __name__ == '__main__':
00045     forearm_cam_l = '/l_forearm_cam/image_rect_color'
00046     ws_l = '/wide_stereo/left/image_rect_color'
00047     ws_r = '/wide_stereo/right/image_rect_color'
00048 
00049     #features_list = find_image_features(sys.argv[1], forearm_cam_l)
00050     #Find all features in all videos that we have
00051     fname = sys.argv[1]
00052     for path_complete in csv_bag_names(fname):
00053         path_complete = path_complete[0]
00054         rospy.loginfo('processing %s'% path_complete)
00055         features_list = find_image_features(path_complete, forearm_cam_l)
00056 
00057         path_bag, name_bag = pt.split(path_complete)
00058         root_name, _ = pt.splitext(name_bag)
00059         surf_path_complete = pt.join(path_bag, root_name + '.surf_pkl')
00060 
00061         #pickle features list
00062         rospy.loginfo('saving feature extraction results to %s' % surf_path_complete)
00063         ut.save_pickle(features_list, surf_path_complete)
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 


hai_sandbox
Author(s): Hai Nguyen
autogenerated on Wed Nov 27 2013 11:46:56