33 #include "Geometry/FMatrix.hh"
34 #include "Geometry/RMatrix.hh"
35 #include "Geometry/EMatrix.hh"
36 #include "Base/Geometry/KMatrix.hh"
37 #include "../FMatrixEstimation.hh"
38 #include "../PMatrixEstimation.hh"
39 #include "../PMatrixLinear.hh"
40 #include "../Triangulation.hh"
41 #include "../../Base/Math/Random.hh"
42 #include "Utils/ThreeDOut.hh"
59 R2.
SetXYZ(0, 10.0*M_PI/180.0, 0);
86 cout <<
"R1 " << R1 << endl;
87 cout <<
"R2 " << R2 << endl;
88 cout <<
"C1 " << C1 << endl;
89 cout <<
"C2 " << C2 << endl;
90 cout <<
"K " << K << endl;
91 cout <<
"P1 " << P1 << endl;
92 cout <<
"P2 " << P2 << endl;
96 vector<HomgPoint3D> points, pointsComp;
97 vector<HomgPoint2D> p1, p2;
99 cout <<
"Randomized correspondences are "<<endl;
102 for (
int p=0; p<numPoints; p++) {
107 p1.push_back(P1 * points[p]);
113 cout <<
"{ "<<p1[p]<<
" ";
114 p2.push_back(P2 * points[p]);
120 cout << p2[p]<<
" } "<<endl;
124 int numPointsOnLines = 20;
125 vector<HomgPoint3D> line1, line2, line1Comp, line2Comp;
126 vector<HomgPoint2D> l1P1, l1P2, l2P1, l2P2;
127 double randLambda = 0.0;
128 for (
int i = 0; i < numPointsOnLines; i++) {
130 line1.push_back(
HomgPoint3D(-1.0 + randLambda, 1.0 + randLambda, 1.0
132 l1P1.push_back(P1 * line1[i]);
133 l1P1[i].Homogenize();
134 l1P2.push_back(P2 * line1[i]);
135 l1P2[i].Homogenize();
137 line2.push_back(
HomgPoint3D(1.0 + randLambda, -1.0 + randLambda, 1.0
139 l2P1.push_back(P1 * line2[i]);
140 l2P1[i].Homogenize();
141 l2P2.push_back(P2 * line2[i]);
142 l2P2[i].Homogenize();
147 bool NormalizeHartley =
true;
149 FEstimator.EightPoint(F, p1, p2);
151 FEstimator.Optimize(F_opt, p1, p2);
156 cout <<
"F " << F << endl;
159 cout <<
"F " << F_opt << endl;
161 testCompF.Normalize();
162 cout <<
"testCompF " << testCompF << endl;
163 cout <<
"testCompF " << testCompF.GetResidualError(p1, p2) << endl;
174 KFalsch[1][1] = KFalsch[0][0];
176 cout <<
"disturbed kmatrix " << KFalsch << endl;
186 cout <<
"Epipole1 " << Epipole1.
Homogenize() <<
" Epipole2 "
191 double BaselineMagnitude = (C1-C2).NormL2();
199 if (P2Comp.
GetC().ScalarProduct(C2) < 0.0)
204 P1Comp = KFalsch * P1Comp;
206 P2Comp = KFalsch * P2Comp;
209 cout <<
"P2COMP IS " << P2Comp << endl;
210 cout<<
"Resulting C vectors " << P1Comp.GetC() <<
" " << P2Comp.GetC()
215 double almostZero = 1e-10;
217 REst = (
RMatrix) P2Comp.GetR();
221 cout <<
"resulting rotation matrices " << P1Comp.GetR() <<
" " << REst
223 cout <<
"Det of P2 " << det << endl;
224 cout <<
id <<
" identity test: " <<
id.
IsIdentity(1) << endl;
226 double phiX, phiY, phiZ;
228 cout <<
"Rotation angles " << phiX*180.0/M_PI <<
" " << phiY*180.0 /M_PI
229 <<
" " << phiZ*180.0/M_PI << endl;
232 bool isOrthonormal =
true;
237 if (fabs(scalarProduct1) >= almostZero)
238 isOrthonormal =
false;
239 if (fabs(scalarProduct2) >= almostZero)
240 isOrthonormal =
false;
241 if (fabs(scalarProduct3) >= almostZero)
242 isOrthonormal =
false;
244 if (!
id.IsIdentity(1.0))
245 isOrthonormal =
false;
247 cout <<
"sp 1 " << scalarProduct1 <<
" sp 2 " << scalarProduct2 <<
" sp 3 "
248 << scalarProduct3 <<
" orthonormal columns " << isOrthonormal
251 cout <<
"p1 est " << P1Comp << endl;
252 cout <<
"p2 est " << P2Comp << endl;
258 for (
int i = 0; i < numPoints; i++) {
259 cout <<
"point " << i <<
" triangulation "
261 triangulator.
Triangulate(P1Comp, P2Comp, p1[i], p2[i], tempPoint)
267 for (
int i = 0; i < numPointsOnLines; i++) {
268 triangulator.
Triangulate(P1Comp, P2Comp, l1P1[i], l1P2[i],
271 triangulator.
Triangulate(P1Comp, P2Comp, l2P1[i], l2P2[i],
284 for (
int i = 0; i < numPoints; i++) {
285 threeDOut.AddPoint(points[i],
RGBAuc(0, 0, 255, 127));
288 for (
int i = 0; i < numPoints; i++) {
289 threeDOut.AddPoint(pointsComp[i],
RGBAuc(255, 0, 0, 127));
291 for (
int i = 0; i < numPointsOnLines; i++) {
292 threeDOut.AddPoint(line1[i],
RGBAuc(0, 255, 255, 127));
293 threeDOut.AddPoint(line2[i],
RGBAuc(255, 255, 255, 127));
296 for (
int i = 0; i < numPointsOnLines; i++) {
297 threeDOut.AddPoint(line1Comp[i],
RGBAuc(255, 255, 0, 127));
298 threeDOut.AddPoint(line2Comp[i],
RGBAuc(255, 0, 255, 127));
301 threeDOut.AddPMatrix(P1, 512, 512, RGBAuc_WHITE_OPAQUE, 0.1);
302 threeDOut.AddPMatrix(P2, 512, 512,
RGBAuc(255, 0, 0, 127), 0.1);
303 threeDOut.AddPMatrix(P1Comp, 512, 512,
RGBAuc(0, 255, 255, 127), 0.1);
304 threeDOut.AddPMatrix(P2Comp, 512, 512,
RGBAuc(255, 0, 255, 127), 0.1);
307 threeDOut.AddLine(start, end,
RGBAuc(255, 0, 0, 127));
308 end.Set(0.0, 1.0, 0.0);
309 threeDOut.AddLine(start, end,
RGBAuc(0, 255, 0, 127));
310 end.Set(0.0, 0.0, 1.0);
311 threeDOut.AddLine(start, end,
RGBAuc(0, 0, 255, 127));
312 threeDOut.VRMLOut(
"test.wrl");
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
void SetXYZ(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order XYZ.
Unified output of 3D entities via OpenGL or VRML.
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
configuration struct for drawing styles of various 3d objects
void SetSkew(const KMATRIX_TYPE &val)
void GetColumn(const unsigned int col, Vector3< T > &r) const
extract one column ('Spalte') from this matrix (for convenience)
bool IsIdentity(const T eps=std::numeric_limits< T >::epsilon()) const
class representing an Essential matrix
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
CameraDrawingStyle CameraStyle
Class for triangulation of 3Dpoints from 2D matches. Covariance matrix (refering to an uncertainty el...
bool DrawUncertaintyEllipsoids
double GetResidualError(const std::vector< BIAS::HomgPoint2D > &p1, const std::vector< BIAS::HomgPoint2D > &p2)
returns residual error as in Zisserman p.
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 (!)...
class representing a Fundamental matrix
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.
functions for estimating a fundamental matrix (FMatrix) given a set of 2d-2d correspondences (no outl...
LineDrawingStyle LineStyle
BIAS::Vector4< unsigned char > RGBAuc
int InitFromF(const FMatrixBase &F, const KMatrix &K1, const KMatrix &K2)
assuming K1 and K2 as calibrations of the cameras which refer to the fmatrix, create the nearest vali...
compute standard P1/P2 from F.
void SetFx(const KMATRIX_TYPE &val)
int ComputeFromFDirect(BIAS::FMatrix &F, const double &BaselineMagnitude, BIAS::PMatrix &P1, BIAS::PMatrix &P2)
given an FMatrix set P1 as identity and compute P2 to be consistent with F and P1 such that P2 is euc...
int GetC(Vector3< double > &C)
computes translation vector origin world coo -> origin camera coo (center), uses decomposition, which is cached
Matrix3x3< T > Transpose() const
returns transposed matrix tested 12.06.2002
int GetRotationAnglesXYZ(double &PhiX, double &PhiY, double &PhiZ) const
Get Euler angles for this rotation matrix in order XYZ.
void SetHy(const KMATRIX_TYPE &val)
void SetFy(const KMATRIX_TYPE &val)
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
T GetDeterminant() const
returns the Determinant |A| of this
int GetEpipoles(HomgPoint2D &Epipole1, HomgPoint2D &Epipole2) const
Computes the epipoles from this F 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
PointDrawingStyle PointStyle
void SetHx(const KMATRIX_TYPE &val)
class for producing random numbers from different distributions
T Normalize()
divide this by biggest absolute entry, returns biggest entry
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) ...
class BIASGeometryBase_EXPORT HomgPoint3D
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...