00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 from __future__ import with_statement
00015 __author__ = 'Rosen Diankov'
00016 __copyright__ = 'Copyright (C) 2009-2010 Rosen Diankov (rosen.diankov@gmail.com)'
00017 __license__ = 'Apache License, Version 2.0'
00018
00019 import roslib; roslib.load_manifest('openrave_calibration')
00020 import time
00021 import numpy
00022 from numpy import *
00023 from optparse import OptionParser
00024 from openravepy import *
00025
00026 import calibraterobotcamera
00027
00028 try:
00029 from itertools import izip, combinations
00030 except ImportError:
00031 def combinations(items,n):
00032 if n == 0: yield[]
00033 else:
00034 for i in xrange(len(items)):
00035 for cc in combinations(items[i+1:],n-1):
00036 yield [items[i]]+cc
00037
00038 try:
00039 import matplotlib
00040 import matplotlib.pyplot as plt
00041 from mpl_toolkits.mplot3d import Axes3D
00042 from matplotlib.patches import Arrow, Polygon
00043 from matplotlib.collections import PatchCollection, PolyCollection, LineCollection
00044 from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection
00045 except ImportError:
00046 print 'failed to import matplotlib.pyplot'
00047
00048 def compareIntrinsicStatistics(self,observations):
00049 KKall = []
00050 KKall_fixed = []
00051 for obs in combinations(observations,5):
00052 try:
00053 KKorig,kcorig,Tcamera,info = self.calibrateFromObservations(obs,False,fixprincipalpoint=False)
00054 KKall.append([KKorig[0,0],KKorig[1,1],KKorig[0,2],KKorig[1,2],kcorig[0],kcorig[1],kcorig[2],kcorig[3],info['intrinsiccondition'],info['error_grad'][0]])
00055 except self.CalibrationError,e:
00056 print e
00057 pass
00058
00059 try:
00060 KKorig,kcorig,Tcamera,info = self.calibrateFromObservations(obs,False,fixprincipalpoint=True)
00061 KKall_fixed.append([KKorig[0,0],KKorig[1,1],KKorig[0,2],KKorig[1,2],kcorig[0],kcorig[1],kcorig[2],kcorig[3],info['intrinsiccondition'],info['error_grad'][0]])
00062 except self.CalibrationError,e:
00063 print e
00064 pass
00065
00066 KKall = array(KKall)
00067 KKall_fixed = array(KKall_fixed)
00068 print 'with principal:'
00069 print array([mean(KKall,0),std(KKall,0)])
00070 print 'fixed:'
00071 print array([mean(KKall_fixed,0),std(KKall_fixed,0)])
00072 return KKall,KKall_fixed
00073
00074 def compareIntrinsicGradients(self,observations):
00075 numimages = 5
00076 KKall = []
00077 KKall_fixed = []
00078 for obs in combinations(observations,numimages):
00079 try:
00080 KKorig,kcorig,Tcamera,info = self.calibrateFromObservations(obs,False,fixprincipalpoint=False)
00081 KKall.append([KKorig[0,0],info['error_grad'][0],mean(info['error_intrinsic']),info['intrinsiccondition'][0],info['intrinsiccondition'][-2],info['intrinsiccondition'][-1]])
00082 except self.CalibrationError,e:
00083 print e
00084 pass
00085
00086 try:
00087 KKorig,kcorig,Tcamera,info = self.calibrateFromObservations(obs,False,fixprincipalpoint=True)
00088 KKall_fixed.append([KKorig[0,0],info['error_grad'][0],mean(info['error_intrinsic']),info['intrinsiccondition'][0],info['intrinsiccondition'][-2],info['intrinsiccondition'][-1]])
00089 except self.CalibrationError,e:
00090 print e
00091 pass
00092
00093 KKall = array(KKall)
00094 KKall_fixed = array(KKall_fixed)
00095 fig = plt.figure()
00096 KK = KKall_fixed
00097 fig.clf()
00098
00099
00100
00101
00102
00103
00104 ax = fig.add_subplot (1,1,1)
00105 ax.set_title('f_x intrinsic calibration %d images'%numimages)
00106 ax.set_ylabel('f_x')
00107 ax.set_xlabel('intrinsic error')
00108
00109 ax.plot(KK[:,4]/KK[:,5],KK[:,0],'o',markersize=2)
00110 ax.set_ylim(1800,2200)
00111 fig.show()
00112
00113 fig.clf()
00114 ax = fig.add_subplot (1,1,1)
00115 ax.set_title('f_x intrinsic calibration %d images'%numimages)
00116 ax.set_ylabel('f_x')
00117 ax.set_xlabel('second derivative of error')
00118
00119 ax.plot(KK[:,1]KK[:,0],'o',markersize=2)
00120 ax.set_ylim(1800,2200)
00121 fig.show()
00122
00123 return KKall,KKall_fixed