Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
HMatrix.hh
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 #ifndef __HMatrix_hh__
26 #define __HMatrix_hh__
27 #include "bias_config.h"
28 
29 #include <Base/Geometry/HMatrixBase.hh>
30 #include <Base/Image/Image.hh>
31 #include <Geometry/PMatrix.hh>
32 
33 namespace BIAS {
34 
35 /** @class HMatrix
36  @ingroup g_geometry
37  @brief a 3x3 Matrix describing projective transformations between planes
38  */
39 class BIASGeometry_EXPORT HMatrix : public HMatrixBase
40 {
41 public:
42  HMatrix();
43 
44  explicit HMatrix(const MatrixInitType& i)
45  : HMatrixBase(i) {};
46 
48 
49  /** @brief homography induced by a plane (e.g. infinite homography)
50  @author koeser 06/2008 */
51  inline HMatrix(const PMatrix& P1, const PMatrix& P2,
52  const HomgPlane3D& scenePlane=HomgPlane3D(0,0,0,1)) {
53  MapAcrossPlane(P1,P2,scenePlane);
54  }
55 
56  ~HMatrix();
57 
58  HMatrix& operator=(const HMatrix& mat);
59 
60  /** maps the rectangle (0,0),(OrigWidth,OrigHeight) with this H
61  and computes mapped range as corner + size. JW 07/2003 */
62  void GetMappedRange(const unsigned int OrigWidth,
63  const unsigned int OrigHeight,
64  BIAS::Vector2<double> & corner,
65  double & sizeWidth, double & sizeHeight) const;
66 
67  /** @return the squared distance between the mapped point from
68  the first picture and the measured point in the second picture
69  @author mdunad 02 2004 */
70  double GetMappedError(const BIAS::HomgPoint2D &PointPicOne,
71  const BIAS::HomgPoint2D &PointPicTwo) const;
72 
73  /** @brief returns jacobian of H: R^2 --> R^2
74 
75  H as a mapping of 2D to 2D is not a linear mapping, because of
76  the nonlinear homogenization. This function returns the 2x2 Jacobian
77  matrix at the point x. You have to pass homogenized points and a
78  correctly sized jacobian
79 
80  @param x homogenized point (real point in R^2) for the jacobian
81  @param Jac (output) 2x2 jacobian at x
82  @author koeser 04/2005 */
83  void GetJacobian(const HomgPoint2D& x, Matrix<double>& Jac) const;
84 
85  /** @brief returns 1st order Taylor expansion of homography at x
86  @author koeser 06/2008 */
87  HMatrix GetLinearized(const HomgPoint2D& x) const;
88 
89 
90  /** @brief compute distance between y mapped with homography or first order
91  taylor approximation at development point x0 in pixel */
92  double ComputeLinearizationError(const HomgPoint2D& x0,
93  const HomgPoint2D& y) const;
94 
95  /** @brief Set (*this) to map coordinates from camera p1 to p2 using the
96  given scene plane. Infinite homography by default.
97  @author koeser 06/2008 */
98  void MapAcrossPlane(const PMatrix& P1, const PMatrix& P2,
99  const HomgPlane3D& scenePlane=HomgPlane3D(0,0,0,1));
100 
101  /** @brief decompose affine matrix into rotations and nonisotropic scalings
102  *
103  * if result=0 then A = theta * phi^-1 * d * phi
104  * where theta and phi are rotation matrices
105  *
106  * @author koeser 05/2007 */
107  static int FactorizeAffineMatrixRLeft(const Matrix2x2<double>& A,
108  Matrix2x2<double>& phi,
109  Matrix2x2<double>& theta,
110  double& d1, double& d2);
111 
112  /** @brief decompose affine matrix into rotations and nonisotropic scalings
113  *
114  * if result=0 then A = phi^-1 * d * phi * theta
115  * where theta and phi are rotation matrices
116  *
117  * @author koeser 05/2007 */
118  static int FactorizeAffineMatrixRRight(const Matrix2x2<double>& A,
119  Matrix2x2<double>& phi,
120  Matrix2x2<double>& theta,
121  double& d1, double& d2);
122 
123  /** @brief compose affine matrix from rotations and nonisotropic scalings
124  *
125  * if result=0 then A = theta * phi^-1 * d * phi
126  * where theta and phi must be rotation matrices
127  *
128  * @author koeser 10/2007 */
129  static int ComposeAffineMatrixRLeft(Matrix2x2<double>& A,
130  const Matrix2x2<double>& phi,
131  const Matrix2x2<double>& theta,
132  const double& d1, const double& d2);
133 
134  /** @brief compose affine matrix from rotations and nonisotropic scalings
135  *
136  * if result=0 then A = phi^-1 * d * phi * theta
137  * where theta and phi must be rotation matrices
138  *
139  * @author koeser 10/2007 */
140  static int ComposeAffineMatrixRRight(Matrix2x2<double>& A,
141  const Matrix2x2<double>& phi,
142  const Matrix2x2<double>& theta,
143  const double& d1, const double& d2);
144 
145  /** @brief compute reprojection error for both vectors of HomgPoint2D
146  *
147  * Computes sum of squared distances of projected points to real ones in both directions
148  *
149  * @author sedlazeck 05/2008 */
150  double GetReprojectionError(std::vector<BIAS::HomgPoint2D>& p1,
151  std::vector<BIAS::HomgPoint2D>& p2);
152 
153 };
154 
155 }
156 // namespace
157 
158 #endif // __HMatrix_hh__
MatrixInitType
can be passed to matrix constructors to init the matrix with the most often used values ...
Definition: Matrix.hh:59
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
a 3x3 Matrix describing projective transformations between planes
Definition: HMatrix.hh:39
HMatrix(const PMatrix &P1, const PMatrix &P2, const HomgPlane3D &scenePlane=HomgPlane3D(0, 0, 0, 1))
homography induced by a plane (e.g.
Definition: HMatrix.hh:51
describes a homography
Definition: HMatrixBase.hh:58
HMatrix(const MatrixInitType &i)
Definition: HMatrix.hh:44
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrix.hh:88
A homogeneous plane (in P^3) All points X on the plane p fulfill p &#39; * X = 0.
Definition: HomgPlane3D.hh:46