Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 extern "C" {
00037 #include <../meshlab/src/external/tsai-30b3/cal_main.h>
00038 }
00039
00040 #include "tsaimethods.h"
00041
00042 #include <vcg/math/camera.h>
00043
00044
00045
00046
00047 bool TsaiMethods::calibrate( vcg::Shot<double>* shot,std::list<TsaiCorrelation>* corr, bool p_foc)
00048 {
00049 bool my_ret_val=false;
00050
00051 if(corr->size() >= MIN_POINTS_FOR_CALIBRATE){
00052
00053
00054 Shot2Tsai(shot);
00055
00056 if(createDataSet(corr,shot))
00057 {
00058 if (p_foc)
00059
00060 noncoplanar_calibration_with_full_optimization ();
00061 else
00062 noncoplanar_extrinsic_parameter_estimation ();
00063
00064 Tsai2Shot(shot);
00065 my_ret_val = true;
00066 }
00067 else my_ret_val = false;
00068 }
00069 return my_ret_val;
00070 }
00071
00072
00073
00074
00075
00076 bool TsaiMethods::createDataSet(std::list<TsaiCorrelation>* corr,vcg::Shot<double>* s)
00077 {
00078 bool my_ret_val=false;
00079
00080 vcg::Point3d *p1;
00081 vcg::Point2d *p2;
00082 int count=0;
00083
00084 std::list<TsaiCorrelation>::iterator it_c;
00085 TsaiCorrelation* c;
00086
00087 double ratio = s->Intrinsics.ViewportPx.X()/(double) s->Intrinsics.ViewportPx.Y();
00088
00089 for ( it_c= corr->begin() ; it_c !=corr->end(); it_c++ ){
00090 c=&*it_c;
00091 p1=&(c->point3d);
00092 p2=&(c->point2d);
00093
00094 if(p1!=NULL && p2!=NULL)
00095 {
00096 cd.xw[count] = p1->X();
00097 cd.yw[count] = p1->Y();
00098 cd.zw[count] = p1->Z();
00099
00100
00101
00102 cd.Xf[count] = ((p2->X()/ratio) +1)/2.0 * cp.Cx*2.0;
00103 cd.Yf[count] = ((-p2->Y())+1)/2.0 * cp.Cy*2.0;
00104 count++;
00105 }
00106 if(count>=MAX_POINTS) break;
00107
00108 }
00109 assert(count==corr->size());
00110 cd.point_count = count;
00111
00112 if(count>0 && count<MAX_POINTS && count>10) my_ret_val = true;
00113
00114 return my_ret_val;
00115 }
00116
00117
00118
00119
00120
00121
00122 void TsaiMethods::Shot2Tsai(vcg::Shot<double>* shot){
00123 vcg::Matrix44d mat = shot->Extrinsics.Rot();
00124
00125 vcg::Point3d view_p = shot->Extrinsics.Tra();
00126
00127 cc.r1 = mat[0][0]; cc.r2 = mat[0][1]; cc.r3 = mat[0][2];
00128 cc.r4 = -mat[1][0]; cc.r5 = -mat[1][1]; cc.r6 = -mat[1][2];
00129 cc.r7 = -mat[2][0]; cc.r8 = -mat[2][1]; cc.r9 = -mat[2][2];
00130
00131
00132 vcg::Point3<vcg::Shot<double>::ScalarType> tl;
00133 tl = mat* shot->Extrinsics.Tra();
00134 cc.Tx = -tl[0];
00135 cc.Ty = tl[1];
00136 cc.Tz = tl[2];
00137
00138
00139
00140
00141
00142 Cam2Tsai(shot);
00143 }
00144
00145
00146
00147
00148
00149 void TsaiMethods::Tsai2Shot(vcg::Shot<double>* shot, bool p_foc ) {
00150
00151 if(p_foc)
00152 shot->Intrinsics.FocalMm = cc.f;
00153
00154
00155
00156
00157
00158
00159
00160 shot->Intrinsics.DistorCenterPx[0] = cp.Cx;
00161 shot->Intrinsics.DistorCenterPx[1] = cp.Cy;
00162
00163 shot->Intrinsics.k[0]=cc.kappa1;
00164
00165
00166 vcg::Matrix44<vcg::Shot<double>::ScalarType> mat;
00167 vcg::Matrix44<vcg::Shot<double>::ScalarType> s_mat=shot->Extrinsics.Rot();
00168 mat.SetIdentity();
00169 mat[0][0]=cc.r1; mat[0][1]=cc.r2; mat[0][2]=cc.r3;
00170 mat[1][0]=-cc.r4; mat[1][1]=-cc.r5; mat[1][2]=-cc.r6;
00171 mat[2][0]=-cc.r7; mat[2][1]=-cc.r8; mat[2][2]=-cc.r9;
00172
00173 shot->Extrinsics.SetRot(mat);
00174
00175
00176 vcg::Point3d tl = shot->Extrinsics.Tra();
00177
00178 tl = vcg::Inverse(shot->Extrinsics.Rot())* vcg::Point3d(-cc.Tx,cc.Ty,cc.Tz);
00179
00180 shot->Extrinsics.SetTra(tl);
00181 }
00182
00183 void TsaiMethods::Cam2Tsai(vcg::Shot<double> *s){
00184
00185 cp.Ncx = s->Intrinsics.ViewportPx.X();
00186 cp.Nfx = s->Intrinsics.ViewportPx.X();
00187 cp.dx = s->Intrinsics.PixelSizeMm.X();
00188 cp.dy = s->Intrinsics.PixelSizeMm.Y();
00189
00190 cp.dpx = cp.dx * cp.Nfx/cp.Ncx;
00191 cp.dpy = cp.dy;
00192
00193 cp.Cx = s->Intrinsics.CenterPx.X();
00194 cp.Cy = s->Intrinsics.CenterPx.Y();
00195
00196 cp.sx = 1.0;
00197
00198 cc.f = s->Intrinsics.FocalMm;
00199 cc.kappa1 = s->Intrinsics.k[0];
00200 }