Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProjectionParametersBase.hh
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8  BIAS is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 2.1 of the License, or
11  (at your option) any later version.
12 
13  BIAS is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with BIAS; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
21 #ifndef __BIAS_ProjectionParametersBase_hh__
22 #define __BIAS_ProjectionParametersBase_hh__
23 
24 #include <bias_config.h>
25 
26 #include <math.h>
27 
28 #include <Geometry/Pose.hh>
29 
30 #include <Base/Common/BIASpragmaStart.hh>
31 
32 #include <Base/Common/CompareFloatingPoint.hh>
33 #include <Base/Math/Vector3.hh>
34 #include <Base/Math/Matrix3x4.hh>
35 #include <Base/Math/Matrix4x4.hh>
36 #include <Base/Geometry/HomgPoint2D.hh>
37 #include <Base/Geometry/Quaternion.hh>
38 #include <Base/Debug/Exception.hh>
39 #include <Geometry/PMatrix.hh>
40 #include <MathAlgo/UnscentedTransform.hh>
41 
42 #include <Base/Debug/Debug.hh>
43 #ifdef BIAS_HAVE_XML2
44 # include <Base/Common/XMLBase.hh>
45 #endif
46 
47 #include <Geometry/RMatrix.hh>
48 
49 
50 namespace BIAS {
51 
52  /** @class PixelIterator
53  @brief Can be used to run along the image border.
54  @author koeser 09/2007 */
55  class PixelIterator {
56  public:
57  /** If using BorderPixel methods these are the coordinates of the pixel.
58  In the image, (0,0) is center of upper left, and (w-1, h-1) is the
59  center of lower right pixel.
60  If using EdgePosition methods this is (-0.5, -0.5) for the upper left
61  image corner and (w-0.5, h-0.5) for the lower right image corner.
62  */
63  double x,y;
64  PixelIterator(): x(-1.0), y(-1.0) {}
65  PixelIterator(const double& xx, const double& yy): x(xx), y(yy) {}
66  };
67 
68  /** @class ProjectionParametersBase
69  * @test tested with TestProjectionParametersBase.cpp
70  @brief Camera parameters which define the mapping between rays in the
71  camera coordinate system and pixels in the image as well as camera pose.
72  @author koeser/evers/streckel
73  */
74  class BIASGeometry_EXPORT ProjectionParametersBase
75  : protected UnscentedTransform
76 #ifdef BIAS_HAVE_XML2
77  , public XMLBase
78 #endif
79  {
80  public:
81 
82  ProjectionParametersBase(const unsigned int width = 0,
83  const unsigned int height = 0);
84 
86  const ProjectionParametersBase& p)
87  {
88  Pose_ = p.Pose_;
89  width_= p.width_;
90  height_= p.height_;
91  principalX_= p.principalX_;
92  principalY_= p.principalY_;
93  aspectratio_= p.aspectratio_;
94  QValid_ = p.QValid_;
95  CValid_ = p.CValid_;
96  identifier_ = p.identifier_;
97  videoSourceType_ = p.videoSourceType_;
98  return *this;
99  }
100 
101  virtual ~ProjectionParametersBase();
102 
103 
104  /** @brief call this to start a run at the outer boundary of an image.
105  *
106  * You get the first boundary position in it, e.g. (0,0) for a perspective
107  * image. Feed this into GetNextBorderPixel to get the next position.
108  * @author koeser 09/2007 */
109  virtual void GetFirstBorderPixel(PixelIterator& it);
110 
111  /** @brief call this iteratively to run at the outer boundary of an image.
112  *
113  * All returned coordinates must have valid local rays in the camera
114  * coordinate system (e.g. in fisheye cams, we run at the fov circle) and
115  * must be in the image. Two subsequent coordinates must not be more
116  * distant than 1 pixel.
117  * @param it must be initialized by GetFirstBorderPixel
118  * @return false if the returned position closes the loop around the image
119  * @author koeser 09/2007 */
120  virtual bool GetNextBorderPixel(PixelIterator& it);
121 
122  /** @brief call this to start a run at the outer boundary of an image.
123  *
124  * You get the first edge position i.e. (-0.5, -0.5) for a perspective
125  * image. Feed this into GetNextBorderPixel to get the next position.
126  * @author bartczak 06/2009 */
127  virtual void GetFirstEdgePosition(PixelIterator& it);
128 
129  /** @brief call this iteratively to run at the outer edge of an image.
130  *
131  * Like the GetNextBorderPixel() method, however runs along the
132  * outer rim of an image, i.e. the coordinate range (-0.5, -0.5) and (W-0.5, H-0.5).
133  * The positions returned are the upper left corner of the pixels.
134  * These are at the same time the upper right corners of the neighboring pixel.
135  *
136  * @param it must be initialized by GetFirstBorderPixel
137  * @return false if the returned position closes the loop around the image
138  * @author bartczak 06/2009 */
139 
140  virtual bool GetNextEdgePosition(PixelIterator& it);
141 
142  /** Determines the maximal and minimal viewing range in means of
143  * spherical coordinates. The spherical coordinates are calculated
144  * relatively to the passed coordinate frame.
145  * The method is using the class SphericalCoordinates, see also the
146  * documentation there in order to understand the meaning of the
147  * sphericalReferenceFrame.
148  *
149  * \attention in order to make sense the sphericalReferenceFrame
150  * must have the same origin as the ProjectionParameters.
151  *
152  * \param sphericalReferenceFrame reference frame for the calculation of
153  * spherical coordinates belonging to optical rays, must be defined in the
154  * same coordinate frame like the local frame of the ProjectionParameters.
155  *
156  * \returns minPhi phi angle from (-M_PI, M_PI] with smallest value
157  * within viewing range.
158  * \returns maxPhi phi angle from (-M_PI, M_PI] with largest value
159  * within viewing range.
160  * \returns centerPhi phi angle from (-M_PI, M_PI] belonging to the
161  * optical ray passing through the image center. This angle
162  * allows to determine which direction the camera was facing
163  * in the sphericalReferenceFrame.
164  * \returns minTheta theta angle from [0, M_PI] with smallest value
165  * within viewing range.
166  * \returns maxTheta theta angle from [0, M_PI] with largest value
167  * within viewing range.
168  *
169  * \author bartczak 10/2007
170  **/
171  virtual int
172  GetSphericalViewingRange(const CoordinateTransform3D& sphericalReferenceFrame,
173  double& minPhi, double& maxPhi, double& centerPhi,
174  double& minTheta, double& maxTheta);
175 
176  /** Delivers the assumed minimal angular distance between two optical rays
177  * belonging to integer image coordinates within the FoV.
178  * \author bartczak 10/2007
179  **/
180  virtual int GetMinimalAngularSamplingStep(double& minAngleStep)
181  {
182  BIASERR("To be implemented in specialized child class!");
183  return -1;
184  }
185 
186  virtual const bool
187  DoExtrinsicsDiffer(const ProjectionParametersBase* p) const;
188 
189  virtual const bool
190  DoIntrinsicsDiffer(const ProjectionParametersBase* p) const;
191 
192  /** Checks if 3D point projects into specified image and returns
193  * belonging 2D image point.
194  * @param X assumes homogenized point!
195  * @author bartczak
196  */
197  virtual bool
198  DoesPointProjectIntoImage(const HomgPoint3D& X, HomgPoint2D& x,
199  bool IgnoreDistortion = false) const;
200 
201  /** Checks if 3D point projects into specified image and returns
202  * belonging 2D image point.
203  * @param localX assumes homogenized point!
204  * @author bartczak
205  */
206  virtual bool
208  HomgPoint2D& x,
209  bool IgnoreDistortion = false) const
210  {
211  BIASERR("To be implemented in specialized child class!");
212  return false;
213  }
214 
215 
216  /** @brief calculates the projection of a point in the world coordinate
217  system to a pixel in the image plane of the camera
218  !warning! the function my return an invalid point (0,0,0) in certain
219  cases (3d point) behind camera or 3d point to close to camera center
220  @author woelk 05/2006 */
221  virtual inline HomgPoint2D Project(const HomgPoint3D &X,
222  bool IgnoreDistortion = false) const {
223  Vector3<double> x;
224  GetExternals().Mult(X, x);
225  return ProjectLocal(x, IgnoreDistortion);
226  }
227 
228  /** @brief calculates the projection of a point in the world coordinate
229  system to a pixel in the image plane of the camera. The
230  only case when this function may not compute the 2d point is when the
231  camera center and the 3d point coincide. This case must be indicated
232  by a negative return value. In all other cases, a valid 2d point is
233  computed, *particularily* when the 3d point is behind the camera
234  or when the resulting 2d point is at infinity.
235  returns negative, when 3d point and camera center coincide
236  @author woelk 05/2006 */
237  virtual inline int Project(const HomgPoint3D &X, HomgPoint2D &p2d,
238  bool IgnoreDistortion = false) const {
239  Vector3<double> x;
240  GetExternals().Mult(X, x);
241  return ProjectLocal(x, p2d, IgnoreDistortion);
242  }
243 
244  /** @brief calculates the projection of a point in the local camera
245  coordinate system to a pixel in the image plane of the camera
246 
247  !warning! function return an invalid 2d point (0,0,0) in certain cases
248 
249  In the simplest case perspective pinhole projection x = K * point
250  where point is transformed of X using point = (R^T | -R^T C) X */
251  virtual HomgPoint2D
252  ProjectLocal(const Vector3<double>& point,
253  bool IgnoreDistortion = false) const = 0;
254 
255  /** @brief calculates the projection of a point in the local camera
256  coordinate system to a pixel in the image plane of the camera. The
257  only case when this function may not compute the 2d point is when the
258  camera center and the 3d point coincide. This case must be indicated
259  by a negative return value. In all other cases, a 2d point must be
260  computed, *particularily* when the 3d point is behind the camera
261  or when the resulting 2d point is at infinity.
262 
263  In the simplest case perspective pinhole projection x = K * point
264  where point is transformed of X using point = (R^T | -R^T C) X
265  @author woelk 08/2008 (c) www.vision-n.de */
266  virtual int
267  ProjectLocal(const Vector3<double>& point, HomgPoint2D &p2d,
268  bool IgnoreDistortion = false) const = 0;
269 
270  /**
271  * @brief Calculates the view ray, which belongs to the given position
272  * on the image plane, in local coordinates.
273  * @param pos position on the image plane
274  * @param origin origin of the ray
275  * @param direction will be the direction of the ray
276  * @param ignoreDistortion optional parameter which specifies
277  * if potential distortions are ignored
278  * (is false by default)
279  * @author Koeser, Evers, Streckel, Husvogt
280  *
281  * In case of a perspective projection, the ray goes through the optical
282  * center of the projection ((0, 0, 0) in local coordinates) and the
283  * given position on the image plane.
284  */
285  virtual void
286  UnProjectLocal(const HomgPoint2D& pos, Vector3<double>& origin,
287  Vector3<double>& direction,
288  bool ignoreDistortion = false) const = 0;
289 
290  /*virtual Vector3<double>
291  UnProjectLocal(const HomgPoint2D& pos,
292  bool IgnoreDistortion = false) const = 0;*/
293 
294  /** @brief map points from image onto unit diameter image plane in 3D.
295  */
296  virtual HomgPoint3D
297  UnProjectToImagePlane(const HomgPoint2D& pos,
298  const double& depth = 1.0,
299  bool IgnoreDistortion = false) const = 0;
300 
301  /** @brief unprojects the covariance matrices to K=Identity camera
302 
303  This uses the unscented transform to propagate covariance. Use a faster
304  or better specialization in derived class if you want.
305  @author koeser 06/2006 */
306  virtual Matrix3x3<double>
307  UnProjectCovLocal(const HomgPoint2D& pos, const Matrix3x3<double>& cov2D,
308  bool IgnoreDistortion = false, bool Normalize = false);
309 
310  /**
311  * @brief Calculates the view ray, which belongs to the given position
312  * on the image plane, in global coordinates.
313  * @param pos position on the image plane
314  * @param origin origin of the ray
315  * @param direction will be the direction of the ray
316  * @param ignoreDistortion optional parameter which specifies
317  * if potential distortions are ignored
318  * (is false by default)
319  * @author Woelk, Husvogt
320  * @date May 2006, March 2012
321  *
322  * In case of a perspective projection, the ray goes through the optical
323  * center of the projection and the given position on the image plane.
324  */
325  virtual inline void UnProjectToRay(
326  const HomgPoint2D& pos, Vector3<double>& origin,
327  Vector3<double>& direction, bool ignoreDistortion=false) const
328  {
329  Vector3<double> point, dir;
330  UnProjectLocal(pos, point, dir, ignoreDistortion);
331  RMatrix R = GetR();
332  R.Mult(dir, direction);
333  R.Mult(point, origin);
334  origin += GetC();
335  }
336 
337  /**
338  * @brief Calculates the view ray, which belongs to the given position
339  * on the image plane, in global coordinates.
340  * @param pos position on the image plane
341  * @param direction will be the direction of the ray
342  * @param ignoreDistortion optional parameter which specifies
343  * if potential distortions are ignored
344  * (is false by default)
345  * @author Woelk, Husvogt
346  * @date May 2006, March 2012
347  *
348  * In case of a perspective projection, the ray goes through the optical
349  * center of the projection and the given position on the image plane.
350  */
351  virtual inline void UnProjectToRay(
352  const HomgPoint2D& pos, Vector3<double>& direction, bool ignoreDistortion=false) const
353  {
354  Vector3<double> point, dir;
355  UnProjectLocal(pos, point, dir, ignoreDistortion);
356  RMatrix R = GetR();
357  R.Mult(dir, direction);
358  }
359 
360  /**
361  * @brief Calculates the view ray, which belongs to the given position
362  * on the image plane, using the given projection.
363  * @param pos position on the image plane
364  * @param origin origin of the ray
365  * @param direction will be the direction of the ray
366  * @param proj reference to the projection which is used
367  * @param ignoreDistortion optional parameter which specifies
368  * if potential distortions are ignored
369  * (is false by default)
370  * @author Woelk, Husvogt
371  * @date May 2006, March 2012
372  *
373  * In case of a perspective projection, the ray goes through the optical
374  * center of the given projection and the given position on the
375  * image plane.
376  */
377  virtual inline void UnProjectToRay(
378  const HomgPoint2D& pos, Vector3<double>& origin,
379  Vector3<double>& direction, const ProjectionParametersBase &proj,
380  bool ignoreDistortion=false) const
381  {
382  Vector3<double> point, dir;
383  proj.UnProjectLocal(pos, point, dir, ignoreDistortion);
384  RMatrix R = GetR();
385  R.Mult(dir, direction);
386  R.Mult(point, origin);
387  origin += GetC();
388  }
389 
390  /** @brief calculates a 3D point in
391  the global (not the rig) coordinate system, which
392  belongs to the image position pos with distance depth to the
393  camera center.
394  @return: (0,0,0,0) is returned on failure */
395  virtual HomgPoint3D UnProjectToPoint(const HomgPoint2D& pos, double depth,
396  bool IgnoreDistortion = false) const;
397 
398  virtual HomgPoint3D UnProjectToPoint(
399  const HomgPoint2D& pos, const double depth,
400  const ProjectionParametersBase &proj,
401  bool IgnoreDistortion = false) const;
402 
403  /** @brief calculates a 3D point in
404  the local camera coordinate system, which
405  belongs to the image position pos in cam with distance depth to the
406  camera center cam.
407  @author koeser */
408  virtual Vector3<double>
409  UnProjectToPointLocal(const HomgPoint2D& pos, const double& depth,
410  bool IgnoreDistortion = false) const;
411 
412  /** Interface defintion for lens distortion function, implemented by
413  derived classes */
414  virtual bool Distort(BIAS::HomgPoint2D& point2d) const = 0;
415 
416  /** Interface defintion for lens undistortion function, implemented by
417  derived classes */
418  virtual bool Undistort(BIAS::HomgPoint2D& point2d) const = 0;
419 
420 
421  /** @brief Get warp (local magnification/shear/...) when going from the
422  * real image to ideal image with focal length = 1.
423  *
424  * When an image is undistorted to an ideal perspective camera with
425  * K=id, the region around each pixel must be warped. For perspective
426  * cameras without radial distortion this is the undoing (inverse) of
427  * the upper 2x2 part of the KMatrix (simply a rescale of coordinates).
428  * If radial distortion is present, the local warp depends on the image
429  * position. Same for most other camera models. This matrix is closely
430  * related to the absolute local image resolution.
431  *
432  * Instead of going to the w=1 (homogenized) ideal image, we can as well
433  * go to a tangent image. This can be steered by the parameter
434  * homogenized (if false, we use normalized mode).
435  *
436  * @author koeser 06/2008
437  */
438  virtual int GetUnProjectionJacobian(const HomgPoint2D& x,
439  Matrix2x2<double>& Jac,
440  const bool homogenized = true) const;
441 
442  /**
443  * @brief Returns true if the camera represented by this
444  * ProjectionParametersBase is left of the given one.
445  *
446  * Computes the baseline vector and rotates it so that this cam would
447  * have zero rotation. This cam is left of the given one if the x component
448  * of the transformed baseline is non-negative.
449  *
450  * Note that the orientation of the given camere is not considered, only
451  * its position.
452  *
453  * @param ppb
454  * the parameters of the cam to compare this to
455  *
456  * @author rwulff
457  * @date 09/2011
458  */
459  bool IsLeftOf(const ProjectionParametersBase& ppb) const;
460 
461  // ---- Getter methods -------------------------------------------
462 
463  /** @brief Get projection center. */
464  virtual BIAS::Vector3<double> GetC() const
465  {
466  if(!CValid_) {
467  BIASWARN("Projection is not valid");
468  BEXCEPTION("ProjectionParametersBase::GetC(): Extrinsics are invalid.");
469  }
470  return Pose_.GetC();
471  }
472 
473  /** @brief Get orientation as unit quaternion. */
475  {
476  if(!QValid_ ) {
477  BIASWARN("Projection is not valid");
478  BEXCEPTION("ProjectionParametersBase::GetQ(): Extrinsics are invalid.");
479  }
480  return Pose_.GetQ();
481  }
482 
483  /** @brief Return pose as 7 vector (first projection center C, then
484  unit quaternion Q representing orientation). */
485  virtual BIAS::Vector<double> GetCQ() const
486  {
487  //if(!QValid_ || !CValid_) BIASWARN("Projection is not valid");
488  BIAS::Vector<double> CQ(7);
489  const BIAS::Vector3<double> C = Pose_.GetC();
490  const BIAS::Quaternion<double> Q = Pose_.GetQ();
491  CQ[0] = C[0]; CQ[1] = C[1]; CQ[2] = C[2];
492  CQ[3] = Q[0]; CQ[4] = Q[1]; CQ[5] = Q[2]; CQ[6] = Q[3];
493  return CQ;
494  }
495 
496  /** @brief Get orientation as rotation matrix R. */
497  virtual BIAS::RMatrix GetR() const;
498 
499  /** @brief Return pose covariance as 7x7 matrix with respect to C, Q. */
500  virtual BIAS::Matrix<POSE_TYPE> GetCov() const {
501  return Pose_.GetCovariance();
502  }
503 
504  /** @brief Return complete pose object. */
505  virtual const BIAS::Pose& GetPose() const
506  {
507  //if(!QValid_ || !CValid_) {
508  // BIASWARN("Projection is not valid");
509  // //BEXCEPTION("ProjectionParametersBase::GetPose(): "
510  // // "Extrinsics are invalid.");
511  // //BIASABORT;
512  //}
513  return Pose_;
514  }
515 
516  /** @brief Return copy of pose parametrization object. */
518  {
519  //if(!QValid_ || !CValid_) {
520  // BIASWARN("Projection is not valid");
521  // //BEXCEPTION("ProjectionParametersBase::GetPoseParametrization(): "
522  // // "Extrinsics are invalid.");
523  // //BIASABORT;
524  //}
525  return Pose_.GetPoseParameters();
526  }
527 
528  /** @brief Set pose from pose parametrization. */
529  virtual inline void SetPoseParametrization(const BIAS::PoseParametrization& pp)
530  { Pose_.Set(pp); QValid_ = CValid_ = true; }
531 
532  /** @brief Return cached 3x4 representation of external matrix [R|C] */
534  {
535  //if(!QValid_ || !CValid_) {
536  // BIASWARN("Projection is not valid");
537  // //BEXCEPTION("ProjectionParametersBase::GetExternals(): "
538  // // "Extrinsics are invalid.");
539  // //BIASABORT;
540  //}
541  return Pose_.GetMatrix3x4();
542  }
543 
544  /** @brief Obtain image dimensions. */
545  virtual inline int GetImageSize(unsigned int& Width, unsigned int& Height) const {
546  Width = width_;
547  Height = height_;
548  return 0;
549  }
550 
551  /**
552  * @brief Returns the image width.
553  *
554  * @return the image width
555  */
556  virtual inline
557  const unsigned int& GetImageWidth() const
558  {
559  return width_;
560  }
561 
562  /**
563  * @brief Returns the image height.
564  *
565  * @return the image height
566  */
567  virtual inline
568  const unsigned int& GetImageHeight() const
569  {
570  return height_;
571  }
572 
573  virtual inline std::string GetIdentifier() const {
574  return identifier_;
575  }
576 
577  virtual inline std::string GetVideoSourceType() const {
578  return videoSourceType_;
579  }
580 
581  /** @brief Return aspectratio (i.e. cellsizeX / cellsizeY). */
582  virtual inline double GetAspectratio() const {
583  return aspectratio_;
584  }
585 
586  /** @brief Get principal point (in pixels relative to top left corner). */
587  virtual inline int GetPrincipal(double& PrincipalX, double& PrincipalY) const {
588  PrincipalX = principalX_;
589  PrincipalY = principalY_;
590  return 0;
591  }
592 
593  // ---- Setter methods ------------------------------------------------
594 
595  /** @brief Set CCD aspect ratio (i.e. cellsizeX / cellsizeY).
596  @author streckel */
597  virtual inline void SetAspectratio(const double AspectRatio) {
598  aspectratio_ = AspectRatio;
599  }
600 
601  /** @brief Set principal point (in pixels relative to top left corner).
602  @author streckel */
603  virtual inline void SetPrincipal(const double x, const double y) {
604  principalX_ = x;
605  principalY_ = y;
606  }
607 
608  /** @brief Set image dimensions (in pixels). */
609  virtual inline void SetImageSize(const unsigned int w,
610  const unsigned int h) {
611  width_ = w;
612  height_ = h;
613  }
614 
615  /** @brief Set the identification string */
616  virtual inline void SetIdentifier(std::string name ){
617  identifier_ = name;
618  }
619 
620  /** @brief Set the camera source type */
621  virtual void SetVideoSourceType(const std::string &name);
622 
623  /** @brief Adapt internal parameters to resampled image
624  @param ratio 2.0 = downsample by 2, 0.5 = upsample by 2.
625  @param offset Offset for principal point (applied before down/upsampling!)
626  \attention Delivers only correct results if ratio is chosen
627  to rescale image size to integral image dimensions
628  in both directions. Image size is rounded!
629  */
630  virtual void Rescale(double ratio, const double offset = 0.0);
631 
632  /**
633  * @brief adapt internal parameters to new image size
634  * @param width and height are the new images sizes
635  * \attention Delivers only correct results if ratio is chosen
636  * to rescale image size to integral image dimensions in both directions.
637  */
638  virtual void Rescale(unsigned int width, unsigned int height);
639 
640  /** @brief Covariant virtual copy constructor used in #BIAS::Projection. */
641  virtual ProjectionParametersBase* Clone() const = 0;
642 
643  /** @brief Set orientation from unit quaternion Q. */
644  virtual void SetQ(const BIAS::Quaternion<double>& Q)
645  { Pose_.SetQ(Q); QValid_ = true; }
646 
647  /** @brief Set projection center. */
648  virtual void SetC(const BIAS::Vector3<double>& C)
649  { Pose_.SetC(C); CValid_ = true; }
650 
651  /** @brief Set pose from unit quaternion Q and projection center C. */
652  virtual void SetQC(const BIAS::Quaternion<double>& Q,
653  const BIAS::Vector3<double>& C)
654  { Pose_.Set(Q,C); QValid_ = CValid_ = true; }
655 
656  /** @brief Set pose from pose object. */
657  virtual void SetPose(const BIAS::Pose pose)
658  { Pose_ = pose; QValid_ = CValid_ = true; }
659 
660  /** @brief Set orientation from rotation matrix R. */
661  virtual void SetR(const BIAS::RMatrix& R) {
663  R.GetQuaternion(Q);
664  Pose_.SetQ(Q);
665  QValid_ = true;
666  }
667 
668  /** @brief Set pose covariance matrix with respect to C, Q. */
669  virtual void SetCov(const Matrix<POSE_TYPE>& Cov)
670  { Pose_.SetCovariance(Cov); }
671 
672  /** @brief Check of current projection center is valid. */
673  virtual inline bool CValid() const { return CValid_; }
674 
675  /** @brief Check if current orientation is valid. */
676  virtual inline bool QValid() const { return QValid_; }
677 
678  /** @brief Check if current pose is valid. */
679  virtual inline bool PoseValid() const
680  { return (CValid_ && QValid_); }
681 
682  /** @brief Invalidate currently set pose. */
683  virtual inline void InvalidatePose()
684  { CValid_ = QValid_ = false; }
685 
686  /** @brief Validate currently set pose. */
687  virtual void ValidatePose() {
688  QValid_= true;
689  CValid_ = true;
690  }
691 
692  /** @brief Returns a fake KMatrix for the camera.
693 
694  @attention Stolen from PPSpherical, since this is a general issue.
695  THERE MAY BE PROBLEMS FOR OTHER THAN FISHEYE CAMERAS (UNTESTED)
696  If this implementation is not correct for your derived projection
697  parameters you have to reimplement it in the derived class.
698 
699  The FoV of the KMatrix is specified by maxangle (PI*80/180 for 160deg)
700  or the max angle, if this is <160deg.
701  @param resolution The resolution parameter influences the
702  Resolution of the perspective image that is represented by the camera.
703  0 - The perspective image has the same size as the this image
704  1 - The perspective image has the same resolution as this
705  image in the center (highest resolution)
706  2 - The perspective image has the same resolution as this
707  image near the border (lowest resolution)
708  @param imgsize returns the image size
709  @param maxangle maximum theta in rad, e.g. (PI*80/180 for 160deg fov)
710  @author streckel 05/2006 (moved here by koeser)
711  */
712  virtual BIAS::KMatrix GetFakeKMatrix(double& imgsize, int resolution = 0,
713  const double& maxangle = 1.4) const;
714  virtual BIAS::KMatrix GetFakeKMatrix(int resolution = 0,
715  const double& maxangle = 1.4) const;
716 
717  /** @brief Returns difference between two projections like |C1-C2|.
718  This function can be used to calculate inter-camera distance e.g.
719  for ordering purposes.
720  @author koeser 03/2006
721  */
722  virtual double ViewDifference(const ProjectionParametersBase*) const;
723 
724 #ifdef BIAS_HAVE_XML2
725  /** @brief Specialization of XML block name function. */
726  virtual int XMLGetClassName(std::string& TopLevelTag,
727  double& Version) const;
728 
729  /** @brief Specialization of XML write function. */
730  virtual int XMLOut(const xmlNodePtr Node, XMLIO& XMLObject) const;
731 
732  /** @brief Specialization of XML read function. */
733  virtual int XMLIn(const xmlNodePtr Node, XMLIO& XMLObject);
734 #endif
735 
736  /** Worker function for Unscented Transform.
737  @author koeser
738  */
739  virtual int Transform_(const Vector<double>& src,
740  Vector<double>& dst) const;
741 
742  friend std::ostream&
743  operator<<(std::ostream &os, const ProjectionParametersBase& p);
744 
745  /** @brief Looks at given point, similar to gluLookAt
746  @param eye Eye coordinate
747  @param center 3D point to look at
748  @param up Up vector of the camera
749  @return true, if everything is fine - false, otherwise
750  */
751  const inline bool LookAt(const Vector3<double> &eye, const Vector3<double> &center, const Vector3<double> &up){
752  return Pose_.LookAt(eye, center, up);
753  };
754 
755  /** @brief Looks at given point, similar to gluLookAt
756  @param center 3D point to look at
757  @param up Up vector of the camera
758  @return true, if everythings fine - false, otherwise
759  */
760  const inline bool LookAt(const Vector3<double> &center, const Vector3<double> &up){
761  return Pose_.LookAt(GetC(), center, up);
762  };
763 
764  /** @brief Looks at given point, similar to gluLookAt
765  @param eye Eye coordinate
766  @param center 3D point to look at
767  @param up Up vector of the camera
768  @return true, if everything is fine - false, otherwise
769  */
770  const inline bool LookAtGL(const Vector3<double> &eye, const Vector3<double> &center, const Vector3<double> &up){
771  return Pose_.LookAtGL(eye, center, up);
772  };
773 
774  /** @brief Looks at given point, similar to gluLookAt
775  @param center 3D point to look at
776  @param up Up vector of the camera
777  @return true, if everythings fine - false, otherwise
778  */
779  const inline bool LookAtGL(const Vector3<double> &center, const Vector3<double> &up){
780  return Pose_.LookAtGL(GetC(), center, up);
781  };
782 
783  protected:
784 
785  /// pose
786  Pose Pose_;
787  /// validity flag for orientation and position
788  bool QValid_, CValid_;
789 
790  /// width of image in pixels
791  unsigned int width_;
792  /// height of image in pixels
793  unsigned int height_;
794 
795  /// principal point in pixel coordinates (one for all zoom settings)
796  double principalX_, principalY_;
797 
798  /// aspect ratio of the camera CCD
799  double aspectratio_;
800 
801  /// unscented transform worker variables
805  /** Multifunctional identifier. */
806  std::string identifier_;
807  std::string videoSourceType_;
808  };
809 
810  inline std::ostream& operator<<(std::ostream &os,
811  const ProjectionParametersBase& p)
812  {
813  // os<<"Type: "<<typeid(p).name()<<std::endl;
814  os<<"Identifier: "<<p.GetIdentifier()<<std::endl;
815  if (p.CValid_) os <<"C:"<<p.GetC()<<std::endl;
816  else os<<"C: invalid"<<std::endl;
817  if (p.QValid_) os <<"Q: "<<p.GetQ()<<std::endl;
818  else os<<"Q: invalid"<<std::endl;
819  os<<"ImageSize: "<<p.width_<<" x "<<p.height_<<std::endl;
820  os<<"Principal: "<<p.principalX_<<" x "<<p.principalY_<<std::endl;
821  os<<"Aspectratio:"<<p.GetAspectratio()<<std::endl;
822  //os<<"Cov: "<<p.GetCov()<<endl;
823  return os;
824  }
825 } // end namespace
826 
827 #include <Base/Common/BIASpragmaEnd.hh>
828 
829 #endif
830 
virtual BIAS::Vector3< double > GetC() const
Get projection center.
virtual void SetCov(const Matrix< POSE_TYPE > &Cov)
Set pose covariance matrix with respect to C, Q.
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.
Definition: HomgPoint2D.hh:67
virtual BIAS::Vector< double > GetCQ() const
Return pose as 7 vector (first projection center C, then unit quaternion Q representing orientation)...
const bool LookAtGL(const Vector3< double > &eye, const Vector3< double > &center, const Vector3< double > &up)
Looks at given point, similar to gluLookAt.
virtual void SetR(const BIAS::RMatrix &R)
Set orientation from rotation matrix R.
virtual int Project(const HomgPoint3D &X, HomgPoint2D &p2d, bool IgnoreDistortion=false) const
calculates the projection of a point in the world coordinate system to a pixel in the image plane of ...
virtual const unsigned int & GetImageHeight() const
Returns the image height.
const bool LookAtGL(const Vector3< double > &center, const Vector3< double > &up)
Looks at given point, similar to gluLookAt.
virtual int GetPrincipal(double &PrincipalX, double &PrincipalY) const
Get principal point (in pixels relative to top left corner).
virtual void SetIdentifier(std::string name)
Set the identification string.
virtual BIAS::Matrix< POSE_TYPE > GetCov() const
Return pose covariance as 7x7 matrix with respect to C, Q.
virtual BIAS::Matrix3x4< double > GetExternals() const
Return cached 3x4 representation of external matrix [R|C].
virtual void SetImageSize(const unsigned int w, const unsigned int h)
Set image dimensions (in pixels).
virtual std::string GetIdentifier() const
Slim class bundeling pose parametrization and associated covariance matrix.
Down-, Upsampling routines and Resize.
Definition: Rescale.hh:71
virtual void UnProjectToRay(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &direction, const ProjectionParametersBase &proj, bool ignoreDistortion=false) const
Calculates the view ray, which belongs to the given position on the image plane, using the given proj...
virtual void UnProjectToRay(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &direction, bool ignoreDistortion=false) const
Calculates the view ray, which belongs to the given position on the image plane, in global coordinate...
virtual const unsigned int & GetImageWidth() const
Returns the image width.
int GetQuaternion(Quaternion< ROTATION_MATRIX_TYPE > &quat) const
Calculates quaternion representation for this rotation matrix.
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.
3D rotation matrix
Definition: RMatrix.hh:49
std::string identifier_
Multifunctional identifier.
virtual void SetQ(const BIAS::Quaternion< double > &Q)
Set orientation from unit quaternion Q.
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
Definition: Pose.hh:73
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
void Mult(const Vector3< T > &argvec, Vector3< T > &destvec) const
matrix - vector multiplicate this matrix with Vector3, storing the result in destvec calculates: dest...
Definition: Matrix3x3.hh:302
virtual bool DoesPointProjectIntoImageLocal(const Vector3< double > &localX, HomgPoint2D &x, bool IgnoreDistortion=false) const
Checks if 3D point projects into specified image and returns belonging 2D image point.
virtual bool PoseValid() const
Check if current pose is valid.
virtual double GetAspectratio() const
Return aspectratio (i.e.
virtual BIAS::PoseParametrization GetPoseParametrization() const
Return copy of pose parametrization object.
void Mult(const T &scalar, Vector3< T > &dest) const
Definition: Vector3.hh:332
unsigned int height_
height of image in pixels
virtual bool QValid() const
Check if current orientation is valid.
virtual void UnProjectToRay(const HomgPoint2D &pos, Vector3< double > &direction, bool ignoreDistortion=false) const
Calculates the view ray, which belongs to the given position on the image plane, in global coordinate...
virtual bool CValid() const
Check of current projection center is valid.
virtual void UnProjectLocal(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &direction, bool ignoreDistortion=false) const =0
Calculates the view ray, which belongs to the given position on the image plane, in local coordinates...
Base class with interface for xml output.
Definition: XMLBase.hh:56
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
Definition: Array2D.hh:260
virtual std::string GetVideoSourceType() const
Can be used to run along the image border.
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
unsigned int width_
width of image in pixels
double x
If using BorderPixel methods these are the coordinates of the pixel.
bool ustTransformIntoImage_
unscented transform worker variables
const bool LookAt(const Vector3< double > &center, const Vector3< double > &up)
Looks at given point, similar to gluLookAt.
const bool LookAt(const Vector3< double > &eye, const Vector3< double > &center, const Vector3< double > &up)
Looks at given point, similar to gluLookAt.
uses the unscented transformation to map a normal distribututed random variable using a nonlinear tra...
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
class BIASGeometry_EXPORT ProjectionParametersBase
double principalX_
principal point in pixel coordinates (one for all zoom settings)
double aspectratio_
aspect ratio of the camera CCD
Transforms 3d points between two different coodinate systems, e.g.
virtual void ValidatePose()
Validate currently set pose.
virtual void SetAspectratio(const double AspectRatio)
Set CCD aspect ratio (i.e.
virtual void SetQC(const BIAS::Quaternion< double > &Q, const BIAS::Vector3< double > &C)
Set pose from unit quaternion Q and projection center C.
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual BIAS::Quaternion< double > GetQ() const
Get orientation as unit quaternion.
virtual const BIAS::Pose & GetPose() const
Return complete pose object.
virtual int GetMinimalAngularSamplingStep(double &minAngleStep)
Delivers the assumed minimal angular distance between two optical rays belonging to integer image coo...
virtual void SetPoseParametrization(const BIAS::PoseParametrization &pp)
Set pose from pose parametrization.
virtual void SetC(const BIAS::Vector3< double > &C)
Set projection center.
bool QValid_
validity flag for orientation and position
PixelIterator(const double &xx, const double &yy)
virtual ProjectionParametersBase & operator=(const ProjectionParametersBase &p)
virtual void InvalidatePose()
Invalidate currently set pose.