35 #include "Geometry/FMatrix.hh"
36 #include "Geometry/RMatrix.hh"
37 #include "Geometry/EMatrix.hh"
38 #include "Base/Geometry/KMatrix.hh"
39 #include "../FMatrixEstimation.hh"
40 #include "../PMatrixEstimation.hh"
41 #include "../PMatrixLinear.hh"
42 #include "../Triangulation.hh"
43 #include "../../Base/Math/Random.hh"
44 #include "Utils/ThreeDOut.hh"
45 #include "Utils/Param.hh"
51 int main(
int argc,
char *argv[]) {
57 p->
AddParamDouble(
"princPointX",
"x-coordinate of principle point", 199.5);
58 p->
AddParamDouble(
"princPointY",
"y_coordinate of principle point", 199.5);
60 p->
AddParamDouble(
"rotationX",
"Rotation of second cam in x-direction", 12.0);
61 p->
AddParamDouble(
"rotationY",
"Rotation of second cam in y-direction", 20.0);
62 p->
AddParamDouble(
"rotationZ",
"Rotation of second cam in z-direction", -2.0);
63 p->
AddParamDouble(
"transX",
"Translation of second cam in x-direction", -1.0/sqrt(2.0));
64 p->
AddParamDouble(
"transY",
"Translation of second cam in y-direction", 1.0 /sqrt(2.0));
65 p->
AddParamDouble(
"transZ",
"Translation of second cam in z-direction", 0.0);
67 p->
AddParamDouble(
"noiseUpper",
"Upper bound for noise on points in pixels", 0.0);
68 p->
AddParamDouble(
"noiseLower",
"Lower bound for noise on points in pixels", -0.0);
73 cout <<
"Could not read parameter file, using default parameters instead " <<res << endl;
80 BIASERR(
"Error could not write parameter file to: " << argv[1] << res);
85 BIASERR(
"Error could not write parameter file to: " <<
"autoCalib.param" << res);
92 std::vector<FMatrix> vecF;
122 K.
SetFx(focalLength);
123 K.
SetFy(focalLength);
135 cout <<
"R1 " << R1 << endl;
136 cout <<
"R2 " << R2 << endl;
137 cout <<
"C1 " << C1 << endl;
138 cout <<
"C2 " << C2 << endl;
139 cout <<
"K " << K << endl;
140 cout <<
"P1 " << P1 << endl;
141 cout <<
"P2 " << P2 << endl;
145 vector<HomgPoint3D> points, pointsComp;
146 vector<HomgPoint2D> p1, p2;
150 for (
int p=0; p<numPoints; p++) {
153 cout <<
"NO. " << points[p] << endl;
154 p1.push_back(P1 * points[p]);
157 p2.push_back(P2 * points[p]);
162 for (
int i = 0; i < numPoints; i++) {
164 *p->GetParamDouble(
"noiseUpper"));
166 *p->GetParamDouble(
"noiseUpper"));
168 *p->GetParamDouble(
"noiseUpper"));
170 *p->GetParamDouble(
"noiseUpper"));
204 bool NormalizeHartley =
true;
209 FEstimator.EightPoint(F, p1, p2);
214 cout <<
"True F matrix ----------- residual error " << F_gt.
GetResidualError(p1, p2) << endl;
215 cout <<
"Estimated F matrix ------ residual error " << F.
GetResidualError(p1, p2) << endl;
219 int res = pEstimator.
AutoCalib(F, width, height, p1, p2, P1Comp, P2Comp);
221 BIASERR(
"Couldn't determine f, P1 and P2" << res);
226 cout <<
"Results of AutoCalib: (true angle of view " << atan(width/(2.0*focalLength)) *180.0/M_PI
228 cout <<
"P1 " << P1Comp << endl;
229 cout <<
"P2 " << P2Comp << endl;
230 cout <<
"Resuting Kmatrix " << P2Comp.
GetK() << endl;
231 cout <<
"Resulting C vectors " << P1Comp.
GetC() <<
" "<< P2Comp.
GetC() <<endl;
232 cout <<
"Resulting Rmatrix " << P2Comp.
GetR() << endl;
236 double phiX, phiY, phiZ;
238 cout <<
"Rotation angles " << phiX*180.0/M_PI <<
" " << phiY*180.0/M_PI <<
" " << phiZ*180.0/M_PI
241 cout <<
"ERRORS " << endl;
242 cout <<
"Focal length " << (P2Comp.
GetK()).GetFx() << endl;
243 cout <<
"Diff P2 " << P2Comp - P2 << endl;
248 for (
int i = 0; i < numPoints; i++) {
249 triangulator.
Triangulate(P1Comp, P2Comp, p1[i], p2[i], tempPoint);
271 for (
int i = 0; i < numPoints; i++) {
272 threeDOut.AddPoint(points[i],
RGBAuc(0, 0, 255, 127));
275 for (
int i = 0; i < numPoints; i++) {
276 threeDOut.AddPoint(pointsComp[i],
RGBAuc(255, 0, 0, 127));
290 threeDOut.AddPMatrix(P1, 400, 400, RGBAuc_WHITE_OPAQUE, 0.1);
291 threeDOut.AddPMatrix(P2, 400, 400,
RGBAuc(255, 0, 0, 127), 0.1);
292 threeDOut.AddPMatrix(P1Comp, 400, 400,
RGBAuc(0, 255, 255, 127), 0.1);
293 threeDOut.AddPMatrix(P2Comp, 400, 400,
RGBAuc(255, 0, 255, 127), 0.1);
297 threeDOut.AddLine(start, end,
RGBAuc(255, 0, 0, 127));
298 end.Set(0.0, 1.0, 0.0);
299 threeDOut.AddLine(start, end,
RGBAuc(0, 255, 0, 127));
300 end.Set(0.0, 0.0, 1.0);
301 threeDOut.AddLine(start, end,
RGBAuc(0, 0, 255, 127));
302 threeDOut.VRMLOut(
"test.wrl");
double * GetParamDouble(const std::string &name) const
void SetXYZ(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order XYZ.
int AutoCalib(const BIAS::FMatrix &F, const int width, const int height, const std::vector< BIAS::HomgPoint2D > &p1, const std::vector< BIAS::HomgPoint2D > &p2, BIAS::PMatrix &P1, BIAS::PMatrix &P2)
given an FMatrix, width and height of the images, and the 2D-correspondences of two images...
Unified output of 3D entities via OpenGL or VRML.
double * AddParamDouble(const std::string &name, const std::string &help, double deflt=0.0, double min=-DBL_MAX, double max=DBL_MAX, char cmdshort=0, int Group=GRP_NOSHOW)
int ReadParameter(const std::string &filename)
read values for parameters from file
configuration struct for drawing styles of various 3d objects
void SetSkew(const KMATRIX_TYPE &val)
int GetR(Matrix3x3< double > &R)
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.
int WriteParameter(const std::string &filename)
store complete set of parameter in file if write_comments is set, alo the help strings are written to...
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)
int * GetParamInt(const std::string &name) const
functions for estimating a fundamental matrix (FMatrix) given a set of 2d-2d correspondences (no outl...
LineDrawingStyle LineStyle
void ComputeFromPMatrices(BIAS::PMatrix &P1, BIAS::PMatrix &P2)
computes an F matrix from two cameras (defined by arbitrary P matrices, not only metric ones) ...
BIAS::Vector4< unsigned char > RGBAuc
compute standard P1/P2 from F.
void SetFx(const KMATRIX_TYPE &val)
int GetC(Vector3< double > &C)
computes translation vector origin world coo -> origin camera coo (center), uses decomposition, which is cached
This class Param provides generic support for parameters.
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).
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
void ShowData(std::ostream &os=std::cout, int grp=GRP_ALL, bool showenhanced=true)
print all data in group grp including current values to os if grp = GRP_ALL, print all values if show...
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
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) ...
int GetK(KMatrix &K)
calibration matrix