articulation_eval2.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import roslib; roslib.load_manifest('articulation_structure')
00004 import rospy
00005 import sys
00006 from visualization_msgs.msg import Marker, MarkerArray
00007 from geometry_msgs.msg import Vector3, Point, Pose, PoseArray
00008 from std_msgs.msg import ColorRGBA
00009 from sensor_msgs.msg import ChannelFloat32
00010 from articulation_msgs.msg import *
00011 from articulation_msgs.srv import *
00012 from articulation_models.track_utils import *
00013 import logging
00014 import getopt
00015 import colorsys
00016 import numpy
00017 import copy
00018 import rosbag
00019 
00020 def all_detected(pose_array):
00021   for p in pose_array.poses:
00022     r = [p.orientation.x,p.orientation.y,p.orientation.z,p.orientation.w]
00023     if( numpy.dot(r,r) == 0 ):
00024       return False
00025   return True
00026 
00027 def main():
00028   rospy.init_node('articulation_eval')
00029   model_pub = rospy.Publisher('/model', ModelMsg)
00030   track_pub = rospy.Publisher('/track', TrackMsg)
00031   fit_models = rospy.ServiceProxy('fit_models', ArticulatedObjectSrv)
00032   get_spanning_tree = rospy.ServiceProxy('get_spanning_tree', ArticulatedObjectSrv)
00033   get_fast_graph = rospy.ServiceProxy('get_fast_graph', ArticulatedObjectSrv)
00034   get_graph = rospy.ServiceProxy('get_graph', ArticulatedObjectSrv)
00035   
00036   downsample = 50
00037   sigma_position = 0.005
00038   sigma_orientation = 0.05
00039   reduce_dofs = 1
00040   inbag_filename = '/home/sturm/sturm-data/sturm10tro/closedchain-pose.bag'
00041   #inbag_filename = '/home/sturm/sturm-data/sturm10tro/openchain-pose.bag'
00042   
00043   inbag = rosbag.Bag(inbag_filename)
00044   
00045   sequence = [] 
00046   for topic, msg, t in inbag.read_messages(topics=['/camera/pose_array']):
00047 #    msg.poses = msg.poses[1:3]
00048     if all_detected(msg):
00049       sequence.append(msg)
00050       
00051   parts = len(sequence[0].poses)
00052   print "read %d observations of %d object parts"%(len(sequence),parts)
00053   
00054   sequence_downsampled = [
00055         p 
00056         for (i,p) in enumerate(sequence) 
00057         if (i % (max(1,len(sequence) / downsample)) == 0 )] \
00058         [0:downsample]
00059   print "downsampled to %d pose observations"%len(sequence_downsampled)
00060   
00061   request = ArticulatedObjectSrvRequest()
00062   request.object.header = sequence_downsampled[-1].header
00063   request.object.parts = [ 
00064     TrackMsg(
00065              id=i,
00066 
00067              header=request.object.header,
00068              pose=[p.poses[i] for p in sequence_downsampled]
00069     ) 
00070     for i in range(parts)
00071   ]
00072   
00073   set_param(request.object, "sigma_position", sigma_position, ParamMsg.PRIOR)
00074   set_param(request.object, "sigma_orientation", sigma_orientation, ParamMsg.PRIOR)
00075   
00076   set_param(request.object, "reduce_dofs", reduce_dofs, ParamMsg.PRIOR)
00077   
00078   #response = get_fast_graph(request)
00079   #response = get_graph(request)
00080   response = get_spanning_tree(request)
00081   
00082   rospy.loginfo('received articulation model: '+(' '.join(
00083      ['(%s:%d,%d)'%(model.name[0:2],model.id/parts,model.id%parts) for model in response.object.models])))
00084   
00085   print '\n'.join(
00086      ['(%s:%d,%d) bic=%f pos_err=%f rot_err=%f'%(
00087           model.name[0:2],
00088           model.id/parts,
00089           model.id%parts,
00090           get_param(model,'bic'),
00091           get_param(model,'avg_error_position'),
00092           get_param(model,'avg_error_orientation')
00093       ) for model in response.object.models])
00094   print "dofs=%d, nominal dofs=%d, bic=%f pos_err=%f rot_err=%f"%(
00095           get_param(response.object,'dof'),
00096           get_param(response.object,'dof.nominal'),
00097           get_param(response.object,'bic'),
00098           get_param(response.object,'avg_error_position'),
00099           get_param(response.object,'avg_error_orientation')
00100           )
00101 
00102 #  model_pub.publish(response.object.models[1])
00103 #  track_pub.publish(request.object.parts[0])
00104 #  track_pub.publish(request.object.parts[1])
00105 #  rospy.sleep(5)
00106   #model_pub.publish(response.object.models[0])
00107   
00108 if __name__ == '__main__':
00109   main()
00110 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


articulation_structure
Author(s): sturm
autogenerated on Wed Dec 26 2012 15:37:59