76 #ifndef SLIP_CAMERA_ALGO_HPP
77 #define SLIP_CAMERA_ALGO_HPP
131 template <
class Matrix1,
class Matrix2,
class Matrix3>
133 int rq_decomp(
const Matrix1 & A, Matrix2 & R, Matrix3 & Q)
135 assert(A.dim1()==A.dim2());
136 assert(A.dim1()==R.dim1());
137 assert(A.dim2()==R.dim2());
138 assert(A.dim1()==Q.dim1());
139 assert(A.dim2()==Q.dim2());
140 typedef typename Matrix1::value_type Type;
141 const std::size_t n = A.dim1();
144 for(std::size_t i = 0; i < n; ++i)
146 P[i][n-1-i] =
static_cast<Type
>(1.0);
186 template <
typename Type>
190 const std::size_t P_rows = P.
rows();
191 Type zero =
static_cast<Type
>(0.0);
192 const std::size_t A_rows = 2*P_rows;
193 const std::size_t A_cols = 11;
198 for(std::size_t i = 0; i < P_rows; ++i)
205 A[k][8]=-P[i][0]*P[i][2];
206 A[k][9]=-P[i][0]*P[i][3];
207 A[k][10]=-P[i][0]*P[i][4];
212 A[k+1][8]=-P[i][1]*P[i][2];
213 A[k+1][9]=-P[i][1]*P[i][3];
214 A[k+1][10]=-P[i][1]*P[i][4];
226 for(std::size_t i = 0; i < A_cols; ++i)
228 for(std::size_t j = 0; j < A_rows; ++j)
241 Mat[2][3] =
static_cast<Type
>(1.0);
261 template <
typename Type>
266 Type norm =
std::sqrt( Mat[2][0]*Mat[2][0]
267 + Mat[2][1]*Mat[2][1]
268 + Mat[2][2]*Mat[2][2]);
270 static_cast<Type>(-1.0)/norm,
296 template <
typename Type>
300 const std::size_t P_rows = P.
rows();
305 for(std::size_t i = 0; i < P_rows; ++i)
312 B[k][3]=
static_cast<Type
>(1.0);
317 B[k+1][7]=
static_cast<Type
>(1.0);
320 C[k][0]=-P[i][0]*P[i][2];
321 C[k][1]=-P[i][0]*P[i][3];
322 C[k][2]=-P[i][0]*P[i][4];
324 C[k+1][0]=-P[i][1]*P[i][2];
325 C[k+1][1]=-P[i][1]*P[i][3];
326 C[k+1][2]=-P[i][1]*P[i][4];
370 x3_1[0]=EigenVectors[0][2]; x3_1[1]=EigenVectors[1][2]; x3_1[2]=EigenVectors[2][2];
372 Type norm=
std::sqrt(x3_1[0]*x3_1[0]+x3_1[1]*x3_1[1]+x3_1[2]*x3_1[2]);
380 x9=x9_1[8]>0 ? -x9_1 : x9_1;
381 x3=x9_1[8]>0 ? -x3_1 : x3_1;
383 Mat[0][0]=x9[0]; Mat[0][1]=x9[1]; Mat[0][2]=x9[2]; Mat[0][3]=x9[3];
384 Mat[1][0]=x9[4]; Mat[1][1]=x9[5]; Mat[1][2]=x9[6]; Mat[1][3]=x9[7];
385 Mat[2][0]=x3[0]; Mat[2][1]=x3[1]; Mat[2][2]=x3[2]; Mat[2][3]=x9[8];
412 template <
typename Type>
418 const std::size_t P_rows = P.
rows();
423 for(
size_t i = 0; i < P_rows; i++)
425 A[i][0]=
static_cast<Type
>(1.0);
427 A[i][2]=P[i][2]*P[i][2];
428 A[i][3]=A[i][2]*P[i][2];
430 A[i][5]=P[i][2]*P[i][3];
431 A[i][6]=P[i][2]*A[i][5];
432 A[i][7]=P[i][3]*P[i][3];
433 A[i][8]=P[i][2]*A[i][7];
434 A[i][9]=A[i][7]*P[i][3];
436 A[i][11]=P[i][2]*P[i][4];
437 A[i][12]=P[i][2]*A[i][11];
438 A[i][13]=P[i][3]*P[i][4];
439 A[i][14]=P[i][2]*A[i][13];
440 A[i][15]=P[i][3]*A[i][13];
441 A[i][16]=P[i][4]*P[i][4];
442 A[i][17]=P[i][2]*A[i][16];
443 A[i][18]=P[i][3]*A[i][16];
467 for(
int i=0; i<19; i++)
469 mx2[i]=mx[i]; my2[i]=my[i];
500 template <
typename Type>
506 const std::size_t P_rows = P.
rows();
511 for(std::size_t i = 0; i < P_rows; ++i)
513 A[i][0]=
static_cast<Type
>(1.0);
515 A[i][2]=P[i][0]*P[i][0];
516 A[i][3]=P[i][0]*A[i][2];
518 A[i][5]=P[i][0]*P[i][1];
519 A[i][6]=P[i][0]*A[i][5];
520 A[i][7]=P[i][1]*P[i][1];
521 A[i][8]=P[i][0]*A[i][7];
522 A[i][9]=P[i][1]*A[i][7];
524 A[i][11]=P[i][0]*P[i][4];
525 A[i][12]=P[i][0]*A[i][11];
526 A[i][13]=P[i][1]*P[i][4];
527 A[i][14]=P[i][0]*A[i][13];
528 A[i][15]=P[i][1]*A[i][13];
529 A[i][16]=P[i][4]*P[i][4];
530 A[i][17]=P[i][0]*A[i][16];
531 A[i][18]=P[i][1]*A[i][16];
555 for(std::size_t i=0; i<19; ++i)
581 template <
typename Type>
590 Type D1 = M[1][2]*M[2][3] - M[2][2]*M[1][3];
591 Type D2 = M[1][1]*M[2][3] - M[2][1]*M[1][3];
592 Type D3 = M[1][1]*M[2][2] - M[2][1]*M[1][2];
593 Type D4 = M[1][0]*M[2][3] - M[2][0]*M[1][3];
594 Type D5 = M[1][0]*M[2][1] - M[2][0]*M[1][1];
595 Type D6 = M[1][0]*M[2][2] - M[2][0]*M[1][2];
598 c[0]= M[0][1]*D1 - M[0][2]*D2 + M[0][3]*D3;
599 c[1]= -M[0][0]*D1 + M[0][2]*D4 - M[0][3]*D6;
600 c[2]= M[0][0]*D2 - M[0][1]*D4 + M[0][3]*D5;
601 c[3]= -M[0][0]*D3 + M[0][1]*D6 - M[0][2]*D5;
629 template <
typename Type>
650 Type alpha_u = -tmp.Euclidean_norm();
652 Type alpha_v = tmp.Euclidean_norm();
653 Type zero =
static_cast<Type
>(0.0);
659 r1 = (m1-(u0*m3))/alpha_u;
660 r2 = (m2-(v0*m3))/alpha_v;
663 t[0] = (M[0][3]-u0*M[2][3])/alpha_u;
664 t[1] = (M[1][3]-v0*M[2][3])/alpha_v;
667 R[0][0]=r1[0]; R[0][1]=r1[1]; R[0][2]=r1[2];
668 R[1][0]=r2[0]; R[1][1]=r2[1]; R[1][2]=r2[2];
669 R[2][0]=r3[0]; R[2][1]=r3[1]; R[2][2]=r3[2];
671 K[0][0]=alpha_u; K[0][1]=s; K[0][2]=u0;
672 K[1][0]=zero; K[1][1]=alpha_v; K[1][2]=v0;
673 K[2][0]=zero; K[2][1]=zero; K[2][2]=
static_cast<Type
>(1.0);
695 template <
typename Type>
707 Type
epsilon =
static_cast<Type
>(1);
708 Type one =
static_cast<Type
>(1);
709 Type two =
static_cast<Type
>(2);
710 Type three =
static_cast<Type
>(3);
711 Type six =
static_cast<Type
>(6);
715 Type x_m_U0 = (x-p[12]);
716 Type y_m_V0 = (y-p[13]);
717 Type x_m_U02 = x_m_U0 * x_m_U0;
718 Type y_m_V02 = y_m_V0 * y_m_V0;
719 Type x_m_U0_y_m_V0 = x_m_U0 * y_m_V0;
720 Type r = x_m_U02 + y_m_V02;
722 Type z1 = p[14]*r + p[15]*r2 + p[16]*r2*r;
726 Type two_z2 = two*z2;
727 Type two_d1 = two*p[17];
728 Type two_d2 = two*p[18];
729 Type one_p_z1 = one + z1;
734 + (six*p[18]+two*p[19])*x_m_U0;
735 Type J01 = two_z2*x_m_U0_y_m_V0
737 + (two*(p[18] + p[19]))*y_m_V0 ;
738 Type J10 = two_z2*x_m_U0_y_m_V0
740 + (two*(p[17] + p[20]))*x_m_U0;
744 + (six*p[17]+ two*p[20])*y_m_V0;
746 Type det = J00*J11-J01*J10;
747 Type Jinv00 = J11/det;
748 Type Jinv01 = -J01/det;
749 Type Jinv10 = -J10/det;
750 Type Jinv11 = J00/det;
752 Type f = x + ( x_m_U0*z1
753 + two_d1*x_m_U0_y_m_V0
754 + p[18]*(three*x_m_U02 + y_m_V02)
756 Type g = y + ( y_m_V0*z1
757 + two_d2*x_m_U0_y_m_V0
758 + p[17]*(three*y_m_V02 + x_m_U02)
761 x -= (Jinv00*f + Jinv01*g);
762 y -= (Jinv10*f + Jinv11*g);
782 #endif //SLIP_CAMERA_ALGO_HPP
void hmatrix_matrix_multiplies(RandomAccessIterator2d1 M1_up, RandomAccessIterator2d1 M1_bot, RandomAccessIterator2d2 M2_up, RandomAccessIterator2d2 M2_bot, RandomAccessIterator2d3 result_up, RandomAccessIterator2d3 result_bot)
Computes the hermitian left multiplication of a matrix: .
Provides a class to modelize 3d points.
iterator2d upper_left()
Returns a read/write iterator2d that points to the first element of the Matrix. It points to the uppe...
slip::Point2d< Type > invert_distortion_model(const slip::Point2d< Type > &pd, const slip::Vector< Type > &p)
Inverts distortion model using the Newton-method.
size_type dim1() const
Returns the number of rows (first dimension size) in the Matrix.
int decompose_direct(const slip::Matrix< Type > &M, slip::Matrix< Type > &K, slip::Matrix< Type > &R, slip::Vector3d< Type > &c)
Direct-Decomposition a 3x4-Matrix into internal and external parameters.
iterator end()
Returns a read/write iterator that points one past the last element in the Vector. Iteration is done in ordinary element order.
This is a Vector3d struct. It is a specialization of kvector. It implements some specific 3d operatio...
iterator2d bottom_right()
Returns a read/write iterator2d that points to the past the end element of the Matrix. It points to past the end element of the bottom right element of the Matrix.
iterator begin()
Returns a read/write iterator that points to the first element in the Matrix. Iteration is done in or...
slip::lin_alg_traits< T >::value_type epsilon()
Returns the epsilon value of a real or a complex.
void matrix_vector_multiplies(RandomAccessIterator2d M_upper_left, RandomAccessIterator2d M_bottom_right, RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 result_first, RandomAccessIterator2 result_last)
Computes the multiplication of a Matrix and a Vector: Result=MV.
int decompose_RQ(const slip::Matrix< Type > &M, slip::Matrix< Type > &K, slip::Matrix< Type > &R, slip::Vector3d< Type > &c)
RQ-Decomposition 3x4-Matrix into internal and external parameters.
void getpars_SoloffUV(const slip::Matrix< Type > &P, slip::MultivariatePolynomial< Type, 3 > &Pol_x, slip::MultivariatePolynomial< Type, 3 > &Pol_y)
Get calibration parameters using a polynomial fit (computation "by hand")
This is a point2d class, a specialized version of Point<CoordType,DIM> with DIM = 2...
void getpars_DLT(const slip::Matrix< Type > &P, slip::Matrix< Type > &Mat)
Get calibration parameters using the DLT.
void hermitian_eigen(const Matrix1 &A, Vector1 &EigenValues, Matrix2 &EigenVectors)
Eigen Values Computation of an hermitian semi-definite positive matrix.
iterator begin()
Returns a read/write iterator that points to the first element in the kvector. Iteration is done in o...
void multiplies(InputIterator1 __first1, InputIterator1 __last1, InputIterator2 __first2, OutputIterator __result)
Computes the pointwise product of two ranges.
Provides some algorithms to computes eigenvalues and eigenvectors.
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
Provides a class to manipulate 3d Vector.
Provides some mathematical functors and constants.
HyperVolume< T > sqrt(const HyperVolume< T > &M)
void matrix_scalar_multiplies(RandomAccessIterator2d1 M_upper_left, RandomAccessIterator2d1 M_bottom_right, const T &scal, RandomAccessIterator2d2 R_upper_left, RandomAccessIterator2d2 R_bottom_right)
Computes the multiplication of a Matrix by a scalar R = M*scal.
row_iterator row_end(const size_type row)
Returns a read/write iterator that points one past the end element of the row row in the Matrix...
void matrix_matrix_multiplies(MatrixIterator1 M1_up, MatrixIterator1 M1_bot, MatrixIterator2 M2_up, MatrixIterator2 M2_bot, MatrixIterator3 R_up, MatrixIterator3 R_bot)
Computes the matrix matrix multiplication of 2 2d ranges.
static _Tp one()
Constant .
self product(const self &other) const
Computes the vector cross product betwin the current Vector3d and the Vector3d other.
void getpars_Faugeras(const slip::Matrix< Type > &P, slip::Matrix< Type > &Mat)
Get calibration parameters using the Faugeras-Algorithm.
void inverse(const Matrix1 &M, const std::size_t nr1, const std::size_t nc1, Matrix2 &IM, const std::size_t nr2, const std::size_t nc2)
Computes the inverse of a matrix using gaussian elimination.
size_type rows() const
Returns the number of rows (first dimension size) in the Matrix.
iterator end()
Returns a read/write iterator that points one past the last element in the kvector. Iteration is done in ordinary element order.
void householder_qr(Matrix1 &M, Vector &V0)
in place Householder QR decomposition M = QR Q is a rotation matrix and R is an upper triangular ma...
std::iterator_traits< RandomAccessIterator1 >::value_type inner_product(RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, typename std::iterator_traits< RandomAccessIterator1 >::value_type init=typename std::iterator_traits< RandomAccessIterator1 >::value_type())
Computes the inner_product of two ranges X and Y: .
Provides some QR decomposition algorithms.
void getpars_DLT_norm(const slip::Matrix< Type > &P, slip::Matrix< Type > &Mat)
Get calibration parameters using the DLT.
int rq_decomp(const Matrix1 &A, Matrix2 &R, Matrix3 &Q)
Computes the RQ decomposition of a matrix.
Provides a class to manipulate Numerical Matrix.
Provides a class to modelize 2d points.
void transpose(const Matrix1 &M, const std::size_t nr1, const std::size_t nc1, Matrix2 &TM, const std::size_t nr2, const std::size_t nc2)
Computes the transpose of a matrix .
size_type dim2() const
Returns the number of columns (second dimension size) in the Matrix.
row_iterator row_begin(const size_type row)
Returns a read/write iterator that points to the first element of the row row in the Matrix...
void getpars_SoloffXY(const slip::Matrix< Type > &P, slip::MultivariatePolynomial< Type, 3 > &Pol_x, slip::MultivariatePolynomial< Type, 3 > &Pol_y)
Get calibration parameters using a polynomial fit (computation "by hand")
Provides a class to manipulate numerical vectors.
iterator begin()
Returns a read/write iterator that points to the first element in the Vector. Iteration is done in or...
Provides a class to manipulate multivariate polynomial.
Provides some algorithms to compute norms.