33 #include <Geometry/Triangulation.hh>
34 #include <Base/Math/Random.hh>
35 #include <Base/Debug/TimeMeasure.hh>
36 #include <Base/Geometry/RMatrixBase.hh>
37 #include <Base/Geometry/KMatrix.hh>
38 #include <Geometry/PMatrix.hh>
44 int main(
int argc,
char *argv[])
58 bool read=
false, finished=
false;
59 double osum=0.0, ksum=0.0, ssum=0.0, osum2=0.0, ksum2=0.0, ssum2=0.0;
60 int onum=0, knum=0, snum=0;
73 K[0][0]=K[1][1]=840.0;
77 for (
int p=0; p<nump; p++){
98 is >> K >> R0 >> R1 >> C0 >> C1 >> np0 >> np1 >> p3d >> gtp0 >> gtp1;
100 cout << K << R0 << R1 << C0 << C1 << np0 << np1 << p3d<<gtp0<<gtp1<<endl;
108 for (
int i=0; i<num; i++){
119 cout <<
"\ntrue 3d point : "<<p3d<<endl;
120 cout <<
"true correspondences : "<<gtp0<<
" <--> "<<gtp1<<endl;
138 cout <<
"noisy correspondences (sigma = "<<setw(5)<<sigma<<
") : "<<p0<<
" <--> "
142 if (tri.
Optimal(P0, P1, p0, p1, tp3d)==0){
146 cout <<
"true 3d point : "<<p3d<<endl;
147 cout <<
"true correspondences : "<<gtp0<<
" <--> "<<gtp1<<endl;
148 cout <<
"noisy correspondences (sigma = "<<setw(5)<<sigma<<
") : "<<np0<<
" <--> "
151 cout <<
"corrected correspondences : "<<p0<<
" <--> "<<p1<<endl;
154 cout <<
"projected triangulated point : "<<p0<<
" <--> "<<p1<<endl;
155 cout <<
"optimal triangulated 3D point : "<<tp3d<<endl;
159 cout <<
"optimal euclidean dist. in 3D : "<<(tp3d-p3d).NormL2()
160 <<
"\teucl. dist in images: "<<(np0-p0).NormL1()<<
" "
161 <<(np1-p1).NormL1()<<endl;
162 osum+=(tp3d-p3d).NormL2();
163 osum2+=(tp3d-p3d).NormL2()*(tp3d-p3d).NormL2();
165 if ((tp3d-p3d).NormL2()>1.0){
166 cout << K << R0 << R1 << C0 << C1 << np0 << np1<<p3d<<gtp0<<gtp1<<endl;
167 ofstream of(
"deb.txt");
168 of << K << R0 << R1 << C0 << C1 << np0 << np1 << p3d<<gtp0<<gtp1<<endl;
180 cout <<
"optimal triangulation failed\n";
190 cout <<
"kanatani triangulated 3D point : "<<tp3d<<endl;
192 cout <<
"kanatani euclidean dist. in 3D: "<<(tp3d-p3d).NormL2()<<endl;
193 ksum+=(tp3d-p3d).NormL2();
194 ksum2+=(tp3d-p3d).NormL2()*(tp3d-p3d).NormL2();
199 cout <<
"kanatani triangulation failed\n";
209 cout <<
"2D triangulated 3D point : "<<tp3d<<endl;
211 cout <<
"2D euclidean dist. in 3D : "<<(tp3d-p3d).NormL2()<<
"\tdist: "
212 <<dist<<
"\tang: "<<ang<<endl;
213 ssum+=(tp3d-p3d).NormL2();
214 ssum2+=(tp3d-p3d).NormL2()*(tp3d-p3d).NormL2();
218 cout <<
"2D triangulation failed\n";
220 if (finished)
return -1;
224 if (onum>1 && knum>1 && snum>1){
225 cout <<
"optimal calculated "<<onum<<
" times with mean error "
226 <<osum/(double)onum<<
" +- "
227 << (osum2-(osum*osum)/(double)onum)/(double)(onum-1.0)
228 <<
"\t"<< ot.
GetRealTime()/(double)onum<<
" us "<<endl;
229 cout <<
"kanatani calculated "<<knum<<
" times with mean error "
230 <<ksum/(double)knum<<
" +- "
231 << (ksum2-(ksum*ksum)/(double)knum)/(double)(knum-1.0)
232 <<
"\t"<< kt.
GetRealTime()/(double)knum<<
" us "<<endl;
233 cout <<
"2D calculated "<<snum<<
" times with mean error "
234 <<ssum/(double)snum<<
" +- "
235 << (ssum2-(ssum*ssum)/(double)snum)/(double)(snum-1.0)
236 <<
"\t"<< st.
GetRealTime()/(double)snum<<
" us "<<endl;
void Set(const T *pv)
copy the array of vectorsize beginning at *T to this->data_
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
void AddDebugLevel(const long int lv)
void SetXYZ(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order XYZ.
void Set(const HOMGPOINT3D_TYPE &x, const HOMGPOINT3D_TYPE &y, const HOMGPOINT3D_TYPE &z)
set elementwise with given 3 euclidean scalar values.
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
int Triangulate2D(PMatrix &P1, PMatrix &P2, HomgPoint2D &p1, HomgPoint2D &p2, HomgPoint3D &point3d, double &dist, double &angle)
does not use BackprojectPseudoInverse but get NormRayWorldCoo
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Class for triangulation of 3Dpoints from 2D matches. Covariance matrix (refering to an uncertainty el...
bool DebugLevelIsSet(const long int lv) const
int Triangulate(PMatrix &P1, PMatrix &P2, const HomgPoint2D &p1, const HomgPoint2D &p2, BIAS::Vector3< double > &point3d)
Triangulation for metric PMatrices (using C and Hinf)
void InvalidateDecomposition()
to re-Decompose_() after filling with data use this.
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
int Optimal(PMatrix &P1, PMatrix &P2, HomgPoint2D &p1, HomgPoint2D &p2, HomgPoint3D &point3d)
method from Hartley Zisserman chapter 12.5 pp 315 first uses CorrectCorrespondences() and then calls ...
double GetRealTime() const
return real time (=wall time clock) in usec JW For Win32: real-time is measured differently from user...
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Implements a 3D rotation matrix.
double GetNormalDistributed(const double mean, const double sigma)
on succesive calls return normal distributed random variable with mean and standard deviation sigma ...
describes a projective 3D -> 2D mapping in homogenous coordinates
class for producing random numbers from different distributions
class TimeMeasure contains functions for timing real time and cpu time.
void Compose(const Matrix3x3< double > &K, const Matrix3x3< double > &R, const Vector3< double > &C)
composes this from K, R and C using P = [ K R' | -K R' C ] with R' = transpose(R) ...
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...