Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProjectionParametersSphericalFast.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #include "Geometry/ProjectionParametersSphericalFast.hh"
27 #include <Base/Common/CompareFloatingPoint.hh>
28 #include <MathAlgo/PolynomialSolve.hh>
29 #include <MathAlgo/Minpack.hh>
30 
31 using namespace BIAS;
32 using namespace std;
33 
35 Distort(BIAS::HomgPoint2D& point2d) const {
36  BIASERR("unfinished");
37  BIASABORT;
38  return false;
39 }
40 
41 
43 Undistort(BIAS::HomgPoint2D& point2d) const {
44  BIASERR("unfinished");
45  BIASABORT;
46  return false;
47 }
48 
52  return true;
53 
55  dynamic_cast<const ProjectionParametersSphericalFast*>(p);
56  if(pps == NULL){
57  cout << "casted to null pointer " << endl;
58  return true;
59  }
60 
61  if(!BIAS::Equal(radius_, pps->radius_, 1e-8)){
62  cout << "radii do not match " << endl;
63  return true;
64  }
65 
66  if(!BIAS::Equal(maxCamAngle_, pps->maxCamAngle_, 1e-8)){
67  cout << "cam angles do not match " << endl;
68  return true;
69  }
70 
71  return false;
72 }
73 
74 
77  HomgPoint2D& x,
78  bool IgnoreDistortion) const {
79 
80  ProjectLocal(localX, x, IgnoreDistortion);
81  double radius =
82  sqrt( (x[0]-principalX_) * (x[0]-principalX_) +
83  (x[1]-principalY_) * (x[1]-principalY_) );
84 
85  return (x[0]>=0.0 && x[1]>=0.0 &&
86  x[0]<=(double)(width_-1) && x[1]<=(double)(height_-1) &&
87  radius <= radius_);
88 }
89 
90 
93  bool IgnoreDistortion) const {
94 
95  Vector3<double> rPhiTheta = point.CoordEuclideanToSphere();
96  if (Equal(rPhiTheta[0], 0.0)) {
97  p2d.SetZero();
98  return 0;
99  }
100 
101  TransfCoordSphere2Image_(rPhiTheta[2], rPhiTheta[1], p2d);
102  return 0;
103 }
104 
105 
107 UnProjectToImagePlane(const HomgPoint2D& pos, const double& depth,
108  bool IgnoreDistortion) const {
109  Vector3<double> d, p;
110  UnProjectLocal(pos, p, d, IgnoreDistortion);
111  double radius = sqrt(d[2]*d[2] + d[1]*d[1] + d[0]*d[0]);
112  if(Equal(radius, 0.0))
113  return HomgPoint3D(0,0,0,0);
114  d*= depth/radius;
115  if(Equal(d.NormL2(), 0.0))
116  return HomgPoint3D(0,0,0,0);
117  HomgPoint3D local(d);
118  local[3] = 1.0;
119  return Pose_.LocalToGlobal(local);
120 }
121 
122 
123 
126  Vector3<double>& direction, bool IgnoreDistortion) const {
127 
128  Vector3<double> rPhiTheta(1,0,0);
129  TransfCoordImage2Sphere_(pos, rPhiTheta[2], rPhiTheta[1]);
130 
131  direction = rPhiTheta.CoordSphereToEuclidean();
132  direction.Normalize();
133  origin = Vector3<double>(0.0);
134 }
135 
136 
139  const double& depth,
140  bool IgnoreDistortion) const {
141  Vector3<double> x, p;
142  UnProjectLocal(pos, p, x, IgnoreDistortion);
143  x *= depth;
144  return x;
145 }
146 
147 
148 
150 SetMaxCamAngle(const double maxCamAngle){
151  maxCamAngle_ = maxCamAngle;
152 }
153 
154 
155 
157 InitPolyCoeffs(const double maxCamAngle,
158  const std::vector<double>& coefficients,
159  const bool undistCoeffs) {
160 
161  // calculate distortion function
162  maxCamAngle_ = maxCamAngle;
163 
164  if (undistCoeffs) { // coefficients describe undistortion
165  coeffsUndist_ = coefficients;
166  // degree is the number of coefficients
167  EstimateDistortionPolynomial(coeffsDist_, coeffsUndist_.size());
168  } else { // coefficients described distortion
169  coeffsDist_ = coefficients;
170  // degree is the number of coefficients
171  EstimateUndistortionPolynomial(coeffsUndist_, coeffsDist_.size());
172  }
173 
174 
175  return 0;
176 }
177 
178 
180 
181  double avgError = 0;
182  double error = 0;
183  double val = 0;
184  double valInv = 0;
185  unsigned int counter = 0;
186  for(double a=0.0; a < maxCamAngle_; a+=0.1){
187  val = EvaluatePolynomial(a, coeffsDist_);
188  valInv = EvaluatePolynomial(val, coeffsUndist_);
189  error = fabs(a-valInv);
190  avgError += error;
191  counter++;
192  }
193 
194  cout << "TestPolynomial Inversion: average error " << error/(double)counter << endl;
195 
196 }
197 
198 
201  double &theta, double &phi) const {
202 
203  HomgPoint2D sourceH = Source;
204  sourceH.Homogenize();
205 
206  double rSrc = sqrt((sourceH[0]-principalX_)*(sourceH[0]-principalX_)+
207  (sourceH[1]-principalY_)*(sourceH[1]-principalY_));
208  phi = atan2(sourceH[1]-principalY_,sourceH[0]-principalX_);
209 
210  double calMaxCamAngle = EvaluatePolynomial(maxCamAngle_, coeffsDist_);
211 
212  // calculate calibrated maximum radius
213  double RadiusCalMax = maxCamAngle_ / calMaxCamAngle * radius_;
214  // calculate calibrated theta and inverse
215  double calTheta = rSrc /RadiusCalMax * maxCamAngle_;
216  theta = EvaluatePolynomial(calTheta, coeffsUndist_);
217 }
218 
219 
220 
221 
223 TransfCoordSphere2Image_(double theta, double phi,
224  HomgPoint2D &Source) const {
225  EnforceNormalRange_(theta, phi);
226 
227  if(theta > maxCamAngle_){
228  // point is outside of image, return zero point
229  Source.SetZero();
230  return;
231  }
232 
233  double rSrc = 0;
234  // calculate calibrated angles
235  double calMaxCamAngle = EvaluatePolynomial(maxCamAngle_, coeffsDist_);
236  double calTheta = EvaluatePolynomial(theta, coeffsDist_);
237 
238  // apply calculate calibrated radius from calibrated angles
239  rSrc = radius_ * calTheta / calMaxCamAngle;
240 
241  Source[0] = rSrc * cos(phi) + principalX_;
242  Source[1] = rSrc * sin(phi) + principalY_;
243  Source[2] = 1;
244 }
245 
247 EnforceNormalRange_(double& theta, double& phi) const {
248  // theta and phi are periodic in 2*M_PI, if they are out of a suitable
249  // range, try to find best equivalent angle by adding 2*l*M_PI
250 
251  // make sure phi and theta dont contain illegal numbers
252  INFNANCHECK(theta);
253  INFNANCHECK(phi);
254 
255  // the following range adaption performs only if theta and phi are close to [0;2pi[
256  // what they ALWAYS should be, check it just for safety:
257  BIASASSERT(fabs(theta)<20.0);
258  BIASASSERT(fabs(phi)<20.0);
259 
260  // bring theta to range [0;2pi[
261  while (theta >= M_PI*2.0) theta -= M_PI*2.0;
262  while (theta < 0.0) theta += M_PI*2.0;
263 
264  // bring phi to range [-pi;pi[
265  while (phi >= M_PI) phi -= M_PI*2.0;
266  while (phi < -M_PI) phi += M_PI*2.0;
267 }
268 
269 
273  dynamic_cast<const ProjectionParametersSphericalFast* >(pPPB);
274  // different projection model has a very different view
275  if (!pPPS) {
276  BIASERR("View difference for different projection models requested !");
277  return DBL_MAX;
278  }
279 
280  Vector3<double> C0 = pPPS->GetC();
281  // Optical axes of the 2 cameras
282  Vector3<double> A0, A;
283 
284  RMatrix R = GetR(), R0 = pPPS->GetR();
285 
286  A[0] = R[0][2]; A[1] = R[1][2]; A[2] = R[2][2];
287  A.Normalize();
288 
289  A0[0] = R0[0][2]; A0[1] = R0[1][2]; A0[2] = R0[2][2];
290  A0.Normalize();
291 
292  // compute field of view, assuming const K !
293  double coshalffieldofview = cos(maxCamAngle_);
294 
295  double newness = (GetC()-C0).NormL2();
296  newness += 1.0/(1.0-coshalffieldofview)*(1.0-fabs(A.ScalarProduct(A0)));
297  return newness;
298 }
299 
300 
303  const double perspHalfViewingAngleDEG,
305  double halffov = perspHalfViewingAngleDEG * M_PI/180.0;
306 
307  // calculate rotation quaternion
308  double viewTheta, viewPhi;
309  TransfCoordImage2Sphere_(viewCenter, viewTheta, viewPhi);
310  Vector3<double> vecAxis(cos(viewPhi+M_PI/2), sin(viewPhi+M_PI/2), 0);
311  Quaternion<double> rot;
312  rot.SetValueAsAxisRad (vecAxis, viewTheta);
313 
314  // measure 1 deg angle in pixel at viewCenter
315  vector<Vector3<double> > vecRPT;//unit sphere points spanning 1Deg theta area
316  vector<HomgPoint2D> vecSpProj; //projected into image
317  vecRPT.push_back(Vector3<double>(1.0, -M_PI, 0.5/180.0*M_PI));
318  vecRPT.push_back(Vector3<double>(1.0, 0, 0.5/180.0*M_PI));
319  vecRPT.push_back(Vector3<double>(1.0, -M_PI/2, 0.5/180.0*M_PI));
320  vecRPT.push_back(Vector3<double>(1.0, M_PI/2, 0.5/180.0*M_PI));
321  for (unsigned int i=0; i<vecRPT.size(); i++) {
322  Vector3<double>vecRot;
323  rot.MultVec(vecRPT[i].CoordSphereToEuclidean(), vecRot);
324  vecSpProj.push_back(ProjectLocal(vecRot));
325  }
326  double MaxPixDiff=0;
327  for (unsigned int i=0; i<vecSpProj.size(); i+=2) {
328  if ((vecSpProj[i]-vecSpProj[i+1]).NormL2()>MaxPixDiff) {
329  MaxPixDiff = (vecSpProj[i]-vecSpProj[i+1]).NormL2();
330  }
331  }
332  int imgsize = int(MaxPixDiff*tan(halffov)/tan(M_PI/180.0));
333  double focallength = imgsize/tan(halffov);
334 
335  // set ProjectionParametersPerspective
336  pp.SetPose(Pose_);
337  pp.SetImageSize(imgsize*2,imgsize*2);
338  pp.SetFocalLengthAndAspect(focallength, 1);
339  pp.SetPrincipal(imgsize,imgsize);
340  pp.SetUndistortion(0,0,0,0);
341 
342  return true;
343 }
344 
345 
347 GetFakeKMatrix(double& imgsize, int resolution, const double& maxangle) const {
348  imgsize = 0;
349  // try user specified maxangle
350  double ang = maxangle;
351  // check if camera supports such large angles, otherwise clip
352  if (ang > GetMaxCamAngle()) ang = GetMaxCamAngle() - 0.01;
353  return ProjectionParametersBase::GetFakeKMatrix(imgsize, resolution, ang);
354 }
355 
356 
357 #ifdef BIAS_HAVE_XML2
358 
360  double& Version) const {
361  TopLevelTag = "ProjectionParametersSphericalFast";
362  Version = 0.1;
363  return 0;
364 }
365 
366 
368  XMLIO& XMLObject) const {
369  xmlNodePtr theNode;
370  string TopLevelName;
371  double Version;
372  ProjectionParametersBase::XMLGetClassName(TopLevelName, Version);
373  theNode = XMLObject.addChildNode(Node, TopLevelName);
374  XMLObject.addAttribute(theNode, "Version", Version);
375  ProjectionParametersBase::XMLOut(theNode, XMLObject);
376 
377  xmlNodePtr childNode, childNode2;
378  XMLObject.addAttribute(Node,"Radius", radius_);
379  XMLObject.addAttribute(Node,"MaxAngle", maxCamAngle_);
380  childNode = XMLObject.addChildNode(Node,"Distortion");
381  for (unsigned int i=0; i< coeffsDist_.size(); i++) {
382  childNode2= XMLObject.addChildNode(childNode,"coeffsDist");
383  XMLObject.addAttribute(childNode2, "coeff", coeffsDist_[i]);
384  }
385  childNode = XMLObject.addChildNode(Node,"Undistortion");
386  for (unsigned int i=0; i< coeffsUndist_.size(); i++) {
387  childNode2= XMLObject.addChildNode(childNode,"coeffsUndist");
388  XMLObject.addAttribute(childNode2, "coeff", coeffsUndist_[i]);
389  }
390  return 0;
391 }
392 
393 
395  XMLIO& XMLObject) {
396  string TopLevelName;
397  double Version;
398  xmlNodePtr childNode;
399 
400  ProjectionParametersBase::XMLGetClassName(TopLevelName, Version);
401  if ((childNode = XMLObject.getChild(Node, TopLevelName))==NULL) {
402  BIASERR("Error in xml, no tag" << TopLevelName);
403  return -1;
404  }
405  if (ProjectionParametersBase::XMLIn(childNode, XMLObject)!=0) return -1;
406 
407  radius_ = XMLObject.getAttributeValueDouble(Node, "Radius");
408  xmlAttrPtr maxAngleAttr = XMLObject.getAttributeByName(Node, "MaxAngle");
409  if (maxAngleAttr)
410  maxCamAngle_ = XMLObject.getAttributeValueDouble(maxAngleAttr);
411 
412  // Read distortion, if given, either as control points from spline interpolation
413  // or as the values of the polynom
414  childNode = XMLObject.getChild(Node, "Distortion");
415  if (childNode) {
416  xmlNodePtr childNode2 = XMLObject.getFirstChild(childNode);
417  string nodeName2 = (childNode2 ? XMLObject.getNodeName(childNode2) : "");
418  if (nodeName2.compare("coeffsDist") == 0){
419  // here we have the coefficients for the distortion polynomial
420  coeffsDist_.clear();
421  while (childNode2) {
422  nodeName2 = XMLObject.getNodeName(childNode2);
423  if (nodeName2.compare("coeffsDist") == 0) {
424  double c = XMLObject.getAttributeValueDouble(childNode2, "coeff");
425  coeffsDist_.push_back(c);
426  }
427  childNode2 = XMLObject.getNextChild(childNode2);
428  }
429  InitPolyCoeffs(maxCamAngle_, coeffsDist_, false);
430  }
431  }
432  return 0;
433 }
434 #endif
435 
436 
437 
438 
439 int InvertPolynomialErrorFunction(void *p,int m, int n, const double *x,
440  double *fvec, int iflag) {
441 
443 
444  vector<double> params;
445  for (int i=0; i<n; i++){
446  params.push_back(x[i]);
447  }
448 
449  double error = 0;
450  for (int j=0; j<m; j++){
451  fvec[j] = pps->myvaluesPolynomial[j] - pps->EvaluatePolynomial(pps->mylocationsPolynomial[j], params);
452  error += fvec[j];
453  }
454 // cout << "error " << error/(double)m << "num params " << n
455 // << " numObs " << m << " size localtions " << pps->mylocationsPolynomial.size()
456 // << " values size " << pps->myvaluesPolynomial.size() << endl;
457 
458  return 0;
459 }
460 
461 
462 int ProjectionParametersSphericalFast::FitPolynomial(std::vector<double>& coefficients,
463  std::vector<double>& a,
464  std::vector<double>& b,
465  unsigned int degree){
466 
467  // cout << "fitting poly linearily " << endl;
468 
469  coefficients.clear();
470  coefficients.resize(degree, 0.0);
471  Matrix<double> A(a.size(), degree);
472  Vector<double> B(b.size()), X(degree);
473  for (unsigned int row=0; row < a.size(); row++) {
474  A[row][0] = a[row];
475  for (unsigned int col=1; col < degree; col++) {
476  A[row][col] = A[row][col-1]*a[row]*a[row];
477  }
478  B[row] = b[row];
479  }
480 
481 
482  SVD mySVD;
483  int result = mySVD.Solve(A, B, X);
484  if (result!=0) {
485  BIASERR("linear solution failed");
486  return -1;
487  }
488 // cout << "linear result " << X << endl;
489 // cout << "non-linear fitting " << endl;
490  Vector<double> resultcoeff(degree);
491  resultcoeff = X;
492 
493  // optimize numerically unstable linear result
494  myvaluesPolynomial = b;
495  mylocationsPolynomial = a;
496 
497  if ((result = LevenbergMarquardt(&InvertPolynomialErrorFunction, (void*)(this), a.size(), degree,
498  X,resultcoeff,
499  MINPACK_DEF_TOLERANCE))!=0) {
500  BIASERR("Error in Levenberg-Marquardt-Optimization of Polynomial: "<< result);
501  // use linear solution
502  for (unsigned int col=0; col<degree; col++) coefficients[col] = X[col];
503  } else {
504  // use these coefficients
505  for (unsigned int col=0; col<degree; col++) {
506  coefficients[col] = resultcoeff[col];
507  }
508  }
509 
510  // cout << "nonlinear result " << resultcoeff << endl;
511 
512 
513  // optimization falied, but linear ok:
514  if (result!=0) return 1;
515 
516  return 0;
517 
518 }
519 
520 
522 EstimateUndistortionPolynomial(std::vector<double>& coefficients,
523  const unsigned int degree) {
524 
525  // cout << "estimating undistortion poly" << endl;
526 
527  double stepSize = 1.0/180*M_PI;
528  unsigned int numSamples = (unsigned int)(maxCamAngle_/stepSize+1);
529  vector<double> a(numSamples), b(numSamples);
530 
531  // cout << "num samples " << numSamples << endl;
532 
533  unsigned int counter=0;
534  for(double theta=0.0; theta < maxCamAngle_ && counter < numSamples; theta+=stepSize, counter++){
535  double calTheta = EvaluatePolynomial(theta, coeffsDist_);
536  a[counter] = calTheta;
537  b[counter] = theta;
538  // cout << "counter " << counter << " a " << a[counter] << " b " << b[counter] << endl;
539  }
540 // cout << "done sampling " << endl;
541 
542  return FitPolynomial(coefficients, a, b, degree);
543 
544 }
545 
547 EstimateDistortionPolynomial(std::vector<double>& coefficients,
548  const unsigned int degree) {
549 
550  //cout << "estimating distortion poly" << endl;
551 
552  double calTheta = 0;
553  double stepSize = 1.0/180*M_PI;
554  double theta = 0;
555  // int case of weird polynomials, maxCamAngle may never be reached, so make
556  // sure the while loop does not create a memory leak
557  unsigned int counter = 0;
558  unsigned int highBoundary = (unsigned int)(maxCamAngle_/stepSize*2);
559 
560  vector<double> a,b;
561  a.reserve(highBoundary);
562  b.reserve(highBoundary);
563 
564  while(calTheta <= maxCamAngle_ && counter < highBoundary){
565  calTheta = EvaluatePolynomial(theta, coeffsUndist_);
566  a.push_back(theta);
567  b.push_back(calTheta);
568  theta += stepSize;
569  counter++;
570  }
571 
572  // cout << "done sampling " << endl;
573 
574  return FitPolynomial(coefficients, a, b, degree);
575 
576 
577 }
578 
580 ProjectOutsidePositions_(int& posX, int& posY) {
581  if(posX<0) posX=0;
582  if(posY<0) posY=0;
583  if(posX>static_cast<int>(width_-1)) posX=width_-1;
584  if(posY>static_cast<int>(height_-1)) posY=height_-1;
585 }
586 
588  //as no double bresenham circle implementation exists yet, we reduce the radius
589  int rad = (int)rint(floor(radius_));
590  int center[2] = {(int)rint(principalX_), (int)rint(principalY_)};
591  fovCircle_.Init(center,rad);
592  int next[2];
593  fovCircle_.GetNext(next);
594  ProjectOutsidePositions_(next[0], next[1]);
595  it.x = next[0];
596  it.y = next[1];
597 
598 }
599 
601  int next[2];
602  bool res = fovCircle_.GetNext(next);
603  ProjectOutsidePositions_(next[0], next[1]);
604  it.x = next[0];
605  it.y = next[1];
606  return res;
607 }
608 
virtual BIAS::KMatrix GetFakeKMatrix(double &imgsize, int resolution=0, const double &maxangle=1.4) const
Returns a fake KMatrix for the camera.
virtual BIAS::Vector3< double > GetC() const
Get projection center.
void addAttribute(const xmlNodePtr Node, const std::string &AttributeName, bool AttributeValue)
Add an attribute to a node.
Definition: XMLIO.cpp:156
virtual bool Distort(BIAS::HomgPoint2D &point2d) const
Interface defintion for lens distortion function, implemented by derived classes. ...
xmlNodePtr getNextChild()
Get the next child of the parent specified in the last getFirstChild() call, the class remembers the ...
Definition: XMLIO.cpp:466
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
Definition: SVD.hh:92
BIAS::Vector3< T > CoordEuclideanToSphere() const
coordinate transform.
Definition: Vector3.cpp:113
Vector< double > Solve(const Vector< double > &y) const
Definition: SVD.cpp:135
virtual int XMLOut(const xmlNodePtr Node, XMLIO &XMLObject) const
specialization of XML write function
spherical camera that uses polynomial only and should therefore be faster than other spherical camera...
virtual int XMLIn(const xmlNodePtr Node, XMLIO &XMLObject)
specialization of XML read function
virtual int XMLOut(const xmlNodePtr Node, XMLIO &XMLObject) const
Specialization of XML write function.
HomgPoint3D UnProjectToImagePlane(const HomgPoint2D &pos, const double &depth=1.0, bool IgnoreDistortion=false) const
map points from image onto unit diameter image plane in 3D.
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual void SetPrincipal(const double x, const double y)
Set principal point in pixels relative to top left corner, virtual overload to recalculate K_...
xmlNodePtr getChild(const xmlNodePtr ParentNode, const std::string &ChildName)
Get a child of a Parent node by specifying the childs name, NULL is returned if the ParentNode has no...
Definition: XMLIO.cpp:489
void ScalarProduct(const Vector3< T > &argvec, T &result) const
scalar product (=inner product) of two vectors, storing the result in result
Definition: Vector3.hh:603
virtual void SetImageSize(const unsigned int w, const unsigned int h)
Set image dimensions (in pixels).
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
Definition: HomgPoint2D.hh:215
virtual const bool DoIntrinsicsDiffer(const ProjectionParametersBase *p) const
virtual void UnProjectLocal(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &direction, bool IgnoreDistortion=false) const
calculates the viewing ray from the camera center (in the camera coordinate system) which belongs to ...
void SetZero()
set all values to 0
Definition: Vector3.hh:559
bool GetPerspectiveCutOutParameters(const BIAS::HomgPoint2D &viewCenter, const double perspHalfViewingAngleDEG, ProjectionParametersPerspective &pp) const
Calculates perspective camera with specified viewing angle and optical axis aligned with the optical ...
int FitPolynomial(std::vector< double > &coefficients, std::vector< double > &a, std::vector< double > &b, unsigned int degree)
void SetMaxCamAngle(const double maxCamAngle)
Set maximal camera angle (in rad), i.e.
int MultVec(const Vector3< QUAT_TYPE > &vec, Vector3< QUAT_TYPE > &res) const
rotates the given Vector qith the quaternion ( q v q* ) the resulting vector is given in res ...
Definition: Quaternion.hh:136
virtual bool Undistort(BIAS::HomgPoint2D &point2d) const
Interface defintion for lens undistortion function, implemented by derived classes.
virtual int XMLIn(const xmlNodePtr Node, XMLIO &XMLObject)
Specialization of XML read function.
virtual void SetPose(const BIAS::Pose pose)
Set pose from pose object.
3D rotation matrix
Definition: RMatrix.hh:49
virtual bool GetNextBorderPixel(PixelIterator &it)
call this iteratively to run at the outer boundary of an image.
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
int InitPolyCoeffs(const double maxCamAngle, const std::vector< double > &coefficients, const bool undistCoeffs=true)
Set undistortion polynomial from from polynomial coefficients of undistortion (mapping radius to z co...
xmlNodePtr addChildNode(const xmlNodePtr ParentNode, const std::string &NewNodeName)
Add a child node to an incoming node with the given name.
Definition: XMLIO.cpp:131
virtual HomgPoint2D ProjectLocal(const Vector3< double > &point, bool IgnoreDistortion=false) const
calculates the projection of a point in the local camera coordinate system to a pixel in the image pl...
virtual BIAS::RMatrix GetR() const
Get orientation as rotation matrix R.
virtual BIAS::KMatrix GetFakeKMatrix(double &imgsize, int resolution=0, const double &maxangle=1.4) const
Returns a fake KMatrix for the fisheye camera.
long int LevenbergMarquardt(minpack_funcder_mn fun, void *p, long int m, long int n, Vector< double > &InitialGuess, Vector< double > &Result, double Tolerance)
Solves an overdetermined system f(x) = 0 of m non-linear equations with n parameters using the Levenb...
Definition: Minpack.cpp:97
xmlNodePtr getFirstChild(const xmlNodePtr ParentNode)
Get the first child of a given parent, or NULL for no childs.
Definition: XMLIO.cpp:452
virtual double ViewDifference(const ProjectionParametersBase *pPPB) const
Returns difference between two projections like |C1-C2|.
virtual void GetFirstBorderPixel(PixelIterator &it)
call this to start a run at the outer boundary of an image.
double EvaluatePolynomial(const double x, const std::vector< double > &coeff) const
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
Can be used to run along the image border.
int EstimateUndistortionPolynomial(std::vector< double > &coefficients, const unsigned int degree=5)
Estimates undistortion polynomial mapping z coordinates to radius according to Scaramuzza&#39;s Matlab to...
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_...
xmlAttrPtr getAttributeByName(const xmlNodePtr Node, const std::string &attribute_name)
search for a specific attribute
Definition: XMLIO.cpp:650
int EstimateDistortionPolynomial(std::vector< double > &coefficients, const unsigned int degree=5)
Estimates distortion polynomial mapping angle theta to radius according to Scaramuzza&#39;s Matlab toolbo...
virtual Vector3< double > UnProjectToPointLocal(const HomgPoint2D &pos, const double &depth, bool IgnoreDistortion=false) const
calculates a 3D point in a local camera coordinate system specified by camSystem, which belongs to th...
double x
If using BorderPixel methods these are the coordinates of the pixel.
BIAS::Vector3< T > CoordSphereToEuclidean() const
coordinate transfrom.
Definition: Vector3.cpp:78
double getAttributeValueDouble(const xmlAttrPtr Attribute) const
Definition: XMLIO.cpp:736
std::string getNodeName(const xmlNodePtr Node) const
Get the name of a given Node.
Definition: XMLIO.cpp:543
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
virtual const bool DoIntrinsicsDiffer(const ProjectionParametersBase *p) const
bool DoesPointProjectIntoImageLocal(const BIAS::Vector3< double > &localX, HomgPoint2D &x, bool IgnoreDistortion=false) const
Checks if 3D point projects into specified image and returns belonging 2D image point.
void SetFocalLengthAndAspect(double f, double AspectRatio)
Set the current camera focal length in pixel and the a spect ratio.
virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
specialization of XML block name function
virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
Specialization of XML block name function.
void TransfCoordSphere2Image_(double theta, double phi, HomgPoint2D &Source) const
Transforms a calibrated pair of polar coordinates phi, theta to a coordinate pair of image coordinate...
void TransfCoordImage2Sphere_(const HomgPoint2D &Source, double &theta, double &phi) const
Transforms a coordinate pair of image coordinates x, y in the uncalibrated spherical image...
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
void EnforceNormalRange_(double &theta, double &phi) const
theta and phi are periodic in 2*M_PI, if they are out of a suitable range, try to find best equivalen...
Vector3< T > & Normalize()
normalize this vector to length 1
Definition: Vector3.hh:663
class BIASGeometryBase_EXPORT HomgPoint3D
void SetValueAsAxisRad(const Vector3< QUAT_TYPE > &axis, QUAT_TYPE angle)
sets the quaternion with given rotation axis and angle (in rad)
Definition: Quaternion.hh:183