calibrationstats.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Copyright (C) 2010 Rosen Diankov (rosen.diankov@gmail.com)
00003 # 
00004 # Licensed under the Apache License, Version 2.0 (the "License");
00005 # you may not use this file except in compliance with the License.
00006 # You may obtain a copy of the License at
00007 #     http://www.apache.org/licenses/LICENSE-2.0
00008 # 
00009 # Unless required by applicable law or agreed to in writing, software
00010 # distributed under the License is distributed on an "AS IS" BASIS,
00011 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 # See the License for the specific language governing permissions and
00013 # limitations under the License.
00014 from __future__ import with_statement # for python 2.5
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 # nice to be able to explicitly call some functions
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 #     ax = fig.add_subplot (1,2,1)
00099 #     ax.set_title('f_x intrinsic calibration %d images'%numimages)
00100 #     ax.set_ylabel('projection error')
00101 #     #ax.set_xlabel('normalized gradient')
00102 #     ax.plot(KK[:,4],KK[:,2],'o',markersize=2)
00103 #     ax = fig.add_subplot (1,2,2)
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     #ax.set_xlabel('normalized gradient')
00109     ax.plot(KK[:,4]/KK[:,5],KK[:,0],'o',markersize=2)
00110     ax.set_ylim(1800,2200)#mean(KK[:,0])-100,mean(KK[:,0])+100)
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     #ax.set_xlabel('normalized gradient')
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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


openrave_calibration
Author(s): Rosen Diankov (rosen.diankov@gmail.com)
autogenerated on Sun Mar 24 2013 06:30:32