34 #include <Base/Common/BIASpragma.hh>
36 #include <Base/Geometry/HomgPoint2D.hh>
37 #include <Geometry/PMatrix.hh>
38 #include <Geometry/RMatrix.hh>
39 #include <Base/Geometry/KMatrix.hh>
40 #include <Base/Math/Random.hh>
43 #include <Geometry/PMatrixLinear.hh>
54 cout <<
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ExamplePMatrix $$$$$$$$$$$$$$$$$$$$$$"
79 if (P_current.
GetHinf(Hinf)!=0){
80 BIASERR(
"Error computing Hinf");
82 cout<<
"C is "<<P_current.
GetC()<<
" R is "<<P_current.
GetR()
83 <<
" K is "<<P_current.
GetK()<<
" Hinf is "<<Hinf<<endl;
85 cout<<
"C is "<<Pose.
GetC()<<
" R is "<<Pose.
GetR()
86 <<
" K is "<<Pose.
GetK()<<endl;
90 for (
unsigned int i=0; i<4; i++)
91 for (
unsigned int j=0; j<3; j++) {
92 double noise = 0.995+(0.01*rand()/(double)RAND_MAX);
93 P_current[j][i] *= noise;
99 cout <<
"Pcurrent is "<<P_current<<endl;
101 cout <<
"Pcurrent after normalizing is "<<P_current<<endl;
103 if (P_current.
GetHinf(Hinf)!=0){
104 BIASERR(
"Error computing Hinf");
107 cout<<
"C is "<<P_current.
GetC()<<
" R is "<<P_current.
GetR()
108 <<
" K is "<<P_current.
GetK()<<
" Hinf is "<<Hinf<<endl;
110 cout <<
" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
111 cout <<
" ++++++++++++++ linear p estimation ++++++++++++++++++++++"<<endl;
113 vector<HomgPoint3D> vecX;
114 vector<HomgPoint2D> vecx;
115 vector<HomgPoint3D*> vecpX;
116 vector<HomgPoint2D*> vecpx;
120 bool WantPlane=
true, WantNoise=
true;
121 unsigned int NumberOffPlane = 0;
133 for (
unsigned int i=0; i<n; i++) {
137 X = a*weight1 + b*weight2 + c*(1.0-weight1-weight2);
144 if (i<NumberOffPlane) {
149 cout <<
"using point X="<<X<<endl;
160 for (
unsigned int i=0; i<n; i++) {
161 vecpX.push_back(&vecX[i]);
162 vecpx.push_back(&vecx[i]);
169 cout <<
"Pose estimation:"<<endl;
172 cout <<
"Pose is "<<Pose<<endl;
173 cout <<
"P_current is "<<P_current<<endl;
174 cout <<
"Diff is "<<Pose-P_current<<endl;
178 cout <<
"complete PMatrix estimation:"<<endl;
180 if (!PLin.
Compute(vecpX, vecpx, Pose)) BIASERR(
"failed !");
182 if (Pose[2][0]*P_current[2][0]<0) Pose *= -1.0;
183 cout <<
"Pose is "<<Pose<<endl;
184 cout <<
"P_current is "<<P_current<<endl;
185 cout <<
"Diff is "<<Pose-P_current<<endl;
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
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
bool Compute(const std::vector< HomgPoint3D * > &points3D, const std::vector< HomgPoint2D * > &points2D, PMatrix &P)
computes a least squares solution P via SVD, if at least 6 2d-3d correspondences (pointers) are provi...
int GetR(Matrix3x3< double > &R)
This class computes a PMatrix from 2D/3D correspondences with linear methods.
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
void Set(const Vector3< ROTATION_MATRIX_TYPE > &w, const ROTATION_MATRIX_TYPE phi)
Set from rotation axis w and angle phi (in rad)
void SetZero()
Sets all values to zero.
void SetIdentity()
set the elements of this matrix to the matrix 1 0 0 0 0 1 0 0 0 0 1 0 which is no strict identity (!)...
void SetDebugLevel(const long int lv)
void InvalidateDecomposition()
to re-Decompose_() after filling with data use this.
bool ComputeCalibrated(const std::vector< HomgPoint3D * > &points3D, const std::vector< HomgPoint2D * > &points2D, PMatrix &Pose)
given n>=6 2D/3D correspondences, compute approximate R and C using linear methods (thats why we need...
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
int GetC(Vector3< double > &C)
computes translation vector origin world coo -> origin camera coo (center), uses decomposition, which is cached
int GetHinf(BIAS::Matrix3x3< double > &Hinf)
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
describes a projective 3D -> 2D mapping in homogenous coordinates
class for producing random numbers from different distributions
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) ...
void Normalize()
scale P such that optical axis (first three entries of last row) has unit length
int GetK(KMatrix &K)
calibration matrix