34 #include <Geometry/ProjectionParametersSpherical.hh>
35 #include <Geometry/Projection.hh>
36 #include "Base/Math/Random.hh"
37 #include "MathAlgo/PolynomialSolve.hh"
43 int main(
int argc,
char *argv[]) {
46 bool testDistortion =
true;
47 bool skipLinearMonom = !testDistortion;
51 cout<<
"error, no xml file given."<<endl;
54 if (P.
Load(argv[1])!=0) {
55 cout<<
"error, could not load xml."<<endl;
62 cout<<
"error, no spherical parameters."<<endl;
65 unsigned int width, height;
67 cout<<
"maxcamangle of loaded projection is "<< ppS->
GetMaxCamAngle()<<endl;
70 std::vector<double> coefficients;
71 coefficients.resize(degree+1);
73 cout<<endl<<endl<<endl<<
"now estimating polynomial"<<endl;
75 cout<<
"distortion function is used ..."<<endl;
78 cout<<
"undistortion function is used ..."<<endl;
81 cout<<
"coefficients are ";
82 for (
unsigned int i=0; i<coefficients.size(); i++) {
83 cout<<coefficients[i]<<
" ";
98 cout<<endl<<endl<<endl<<
"now initing with polynomial"<<endl;
112 cout<<endl<<endl<<endl<<
"now estimating polynomial again "<<endl;
115 if (testDistortion) {
116 cout<<
"distortion function is used ..."<<endl;
119 cout<<
"undistortion function is used ..."<<endl;
122 cout<<
"coefficients are ";
124 for (
unsigned int i=0; i<coefficients.size(); i++) {
125 cout<<coefficients[i]<<
" ";
129 cout<<
"generating some 3D points with original projection .."<<endl;
132 vector<HomgPoint3D> points3D;
133 vector<HomgPoint2D> points2D;
134 for (
unsigned int i=0; i<20; i++) {
138 if (X.NormL2()>0.1) {
139 points2D.push_back(x);
140 points3D.push_back(X);
149 double averageError = 0;
150 for (
unsigned int i=0; i<points3D.size(); i++) {
160 HomgPoint3D XCCS(thePose.GlobalToLocal(points3D[i]));
162 ProjectionRay.Normalize();
169 if (testDistortion) {
173 if(
Equal(rPhiTheta[0], 0.0)) {
174 BIASERR(
"sphere coordinate transform failed for ray "
178 double radius = PS.EvaluatePolynomial(rPhiTheta[2], coefficients);
180 result[0] = radius * cos(rPhiTheta[1]) + px;
181 result[1] = radius * sin(rPhiTheta[1]) + py;
182 cout<<
"projects to "<<result<<
", measured at "<<points2D[i]
183 <<
" diff is "<<(result-points2D[i]).NormL2()<<endl;
185 averageError += (result-points2D[i]).NormL2();
187 result = S2.
Project(points3D[i]);
188 cout<<
"Reconstructed projects to "<<result<<
", measured at "<<points2D[i]
189 <<
" diff is "<<(result-points2D[i]).NormL2()<<endl;
196 double radius = sqrt(ImageRay[0]*ImageRay[0] + ImageRay[1]*ImageRay[1]);
197 ImageRay[2] = -1.0*PS.EvaluatePolynomial(radius, coefficients);
200 ImageRay.Normalize();
202 if (ImageRay.ScalarProduct(ProjectionRay)<0.0)
204 cout<<
"ray error for manual polynomial projection in degree: ";
205 averageError += acos(ImageRay.ScalarProduct(ProjectionRay))*180.0/M_PI;
206 cout<<acos(ImageRay.ScalarProduct(ProjectionRay))*180.0/M_PI
208 cout<<
"ray error for reconstructed interpolator projection in degree: ";
209 cout<<acos(ImageRay.ScalarProduct(pRay))*180.0/M_PI<<
" degree"<<endl;
216 testpoint2 = points2D[i];
219 cout<<
"ray error (inconsistency) for original project/unproject: ";
229 averageError /= points3D.size();
230 cout<<
"Average angular error (manual) is "<<averageError <<endl;
virtual void SetPrincipal(const double x, const double y)
Set principal point (in pixels relative to top left corner).
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
BIAS::Vector3< T > CoordEuclideanToSphere() const
coordinate transform.
virtual int Load(const std::string &filename)
convenience wrapper which tries to read different formats
virtual int GetPrincipal(double &PrincipalX, double &PrincipalY) const
Get principal point (in pixels relative to top left corner).
virtual HomgPoint3D UnProjectToPoint(const HomgPoint2D &pos, double depth, bool IgnoreDistortion=false) const
calculates a 3D point in the global (not the rig) coordinate system, which belongs to the image posit...
void ScalarProduct(const Vector3< T > &argvec, T &result) const
scalar product (=inner product) of two vectors, storing the result in result
virtual void SetImageSize(const unsigned int w, const unsigned int h)
Set image dimensions (in pixels).
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
base class for solving polynomial equations
virtual HomgPoint2D Project(const HomgPoint3D &X, bool IgnoreDistortion=false) const
calculates the projection of a point in the world coordinate system to a pixel in the image plane of ...
virtual void SetPose(const BIAS::Pose pose)
Set pose from pose object.
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
This class hides the underlying projection model, like projection matrix, spherical camera...
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
bool Equal(const T left, const T right, const T eps)
comparison function for floating point values See http://www.boost.org/libs/test/doc/components/test_...
virtual const BIAS::Pose & GetPose() const
Return complete pose object.
Vector3< T > & Normalize()
normalize this vector to length 1
class for producing random numbers from different distributions