Blender  V3.3
homography_error.h
Go to the documentation of this file.
1 // Copyright (c) 2011 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
21 #ifndef LIBMV_MULTIVIEW_HOMOGRAPHY_ERRORS_H_
22 #define LIBMV_MULTIVIEW_HOMOGRAPHY_ERRORS_H_
23 
25 
26 namespace libmv {
27 namespace homography {
28 namespace homography2D {
29 
50  static void Residuals(const Mat& H, const Mat& x1, const Mat& x2, Mat2X* dx) {
51  dx->resize(2, x1.cols());
52  Mat3X x2h_est;
53  if (x1.rows() == 2)
54  x2h_est = H * EuclideanToHomogeneous(static_cast<Mat2X>(x1));
55  else
56  x2h_est = H * x1;
57  dx->row(0) = x2h_est.row(0).array() / x2h_est.row(2).array();
58  dx->row(1) = x2h_est.row(1).array() / x2h_est.row(2).array();
59  if (x2.rows() == 2)
60  *dx = x2 - *dx;
61  else
62  *dx = HomogeneousToEuclidean(static_cast<Mat3X>(x2)) - *dx;
63  }
76  static void Residuals(const Mat& H, const Vec& x1, const Vec& x2, Vec2* dx) {
77  Vec3 x2h_est;
78  if (x1.rows() == 2)
79  x2h_est = H * EuclideanToHomogeneous(static_cast<Vec2>(x1));
80  else
81  x2h_est = H * x1;
82  if (x2.rows() == 2)
83  *dx = x2 - x2h_est.head<2>() / x2h_est[2];
84  else
85  *dx = HomogeneousToEuclidean(static_cast<Vec3>(x2)) -
86  x2h_est.head<2>() / x2h_est[2];
87  }
100  static double Error(const Mat& H, const Mat& x1, const Mat& x2) {
101  Mat2X dx;
102  Residuals(H, x1, x2, &dx);
103  return dx.squaredNorm();
104  }
116  static double Error(const Mat& H, const Vec& x1, const Vec& x2) {
117  Vec2 dx;
118  Residuals(H, x1, x2, &dx);
119  return dx.squaredNorm();
120  }
121 };
122 
143  static double Error(const Mat& H, const Vec& x1, const Vec& x2) {
144  // TODO(keir): This is awesomely inefficient because it does a 3x3
145  // inversion for each evaluation.
146  Mat3 Hinv = H.inverse();
147  return AsymmetricError::Error(H, x1, x2) +
148  AsymmetricError::Error(Hinv, x2, x1);
149  }
150  // TODO(julien) Add residuals function \see AsymmetricError
151 };
159  // TODO(julien) Make an AlgebraicError2Rows and AlgebraicError3Rows
160 
172  static void Residuals(const Mat& H, const Mat& x1, const Mat& x2, Mat3X* dx) {
173  dx->resize(3, x1.cols());
174  Vec3 col;
175  for (int i = 0; i < x1.cols(); ++i) {
176  Residuals(H, x1.col(i), x2.col(i), &col);
177  dx->col(i) = col;
178  }
179  }
191  static void Residuals(const Mat& H, const Vec& x1, const Vec& x2, Vec3* dx) {
192  Vec3 x2h_est;
193  if (x1.rows() == 2)
194  x2h_est = H * EuclideanToHomogeneous(static_cast<Vec2>(x1));
195  else
196  x2h_est = H * x1;
197  if (x2.rows() == 2)
198  *dx = SkewMat(EuclideanToHomogeneous(static_cast<Vec2>(x2))) * x2h_est;
199  else
200  *dx = SkewMat(x2) * x2h_est;
201  // TODO(julien) This is inefficient since it creates an
202  // identical 3x3 skew matrix for each evaluation.
203  }
215  static double Error(const Mat& H, const Mat& x1, const Mat& x2) {
216  Mat3X dx;
217  Residuals(H, x1, x2, &dx);
218  return dx.squaredNorm();
219  }
231  static double Error(const Mat& H, const Vec& x1, const Vec& x2) {
232  Vec3 dx;
233  Residuals(H, x1, x2, &dx);
234  return dx.squaredNorm();
235  }
236 };
237 // TODO(keir): Add error based on ideal points.
238 
239 } // namespace homography2D
240 // TODO(julien) add homography3D errors
241 } // namespace homography
242 } // namespace libmv
243 
244 #endif // LIBMV_MULTIVIEW_HOMOGRAPHY_ERRORS_H_
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble x2
uint col
#define H(x, y, z)
Eigen::VectorXd Vec
Definition: numeric.h:61
void EuclideanToHomogeneous(const Mat &X, Mat *H)
Definition: projection.cc:200
Eigen::Matrix< double, 3, 3 > Mat3
Definition: numeric.h:72
Eigen::Vector2d Vec2
Definition: numeric.h:105
void HomogeneousToEuclidean(const Mat &H, Mat *X)
Definition: projection.cc:166
Eigen::MatrixXd Mat
Definition: numeric.h:60
Mat3 SkewMat(const Vec3 &x)
Returns the skew anti-symmetric matrix of a vector.
Definition: numeric.h:468
Eigen::Vector3d Vec3
Definition: numeric.h:106
Eigen::Matrix< double, 3, Eigen::Dynamic > Mat3X
Definition: numeric.h:92
Eigen::Matrix< double, 2, Eigen::Dynamic > Mat2X
Definition: numeric.h:91
static void Residuals(const Mat &H, const Mat &x1, const Mat &x2, Mat3X *dx)
static double Error(const Mat &H, const Mat &x1, const Mat &x2)
static void Residuals(const Mat &H, const Vec &x1, const Vec &x2, Vec3 *dx)
static double Error(const Mat &H, const Vec &x1, const Vec &x2)
static double Error(const Mat &H, const Vec &x1, const Vec &x2)
static void Residuals(const Mat &H, const Mat &x1, const Mat &x2, Mat2X *dx)
static double Error(const Mat &H, const Mat &x1, const Mat &x2)
static void Residuals(const Mat &H, const Vec &x1, const Vec &x2, Vec2 *dx)
static double Error(const Mat &H, const Vec &x1, const Vec &x2)