26 #include "Parametrization.hh"
27 #include <Base/Common/BIASpragma.hh>
28 #include <Base/Geometry/Quaternion.hh>
36 Parametrization::Parametrization() {}
37 Parametrization::~Parametrization() {}
39 bool Parametrization::FMatrixToParams(
const FMatrix &Mat,
40 vector<double> &Params )
44 BIASERR(
"A parametrization of a null matrix doesn't make sense!");
51 double scale = GetBiggestAbsEntry();
54 Mat.
Scale(Fscale_, F_);
59 F_.GetEpipoles(FEpipole1,FEpipole2);
63 if ( Frow_ == 0 && Fcol_ == 0 )
69 else if ( Frow_ == 1 && Fcol_ == 0 )
75 else if ( Frow_ == 0 && Fcol_ == 1 )
81 else if ( Frow_ == 1 && Fcol_ == 1 )
92 Params.push_back(-FEpipole1[0]);
93 Params.push_back(-FEpipole1[1]);
94 Params.push_back(-FEpipole2[0]);
95 Params.push_back(-FEpipole2[1]);
101 bool Parametrization::ParamsToFMatrix(
FMatrix &Mat,
102 const vector<double> &Params )
104 if ( Params.size() != 7 )
106 BIASERR(
"There must be 7 parameters to compose the F matrix!");
111 double a=0.0,b=0.0,c=0.0,d=0.0;
112 double e10,e11,e20,e21;
114 if ( Frow_ == 0 && Fcol_ == 0 )
121 else if ( Frow_ == 1 && Fcol_ == 0 )
128 else if ( Frow_ == 0 && Fcol_ == 1 )
135 else if ( Frow_ == 1 && Fcol_ == 1 )
150 Mat[0][2] = e10 * a + e11 * b;
154 Mat[1][2] = e10 * c + e11 * d;
156 Mat[2][0] = e20 * a + e21 * c;
157 Mat[2][1] = e20 * b + e21 * d;
158 Mat[2][2] = e20 * e10 * a + e20 * e11 * b + e21 * e10 * c + e21 * e11 * d;
164 bool Parametrization::HMatrixToParams(
const HMatrix &Mat,
165 vector<double> &Params )
169 BIASERR(
"A parametrization of a null matrix doesn't make sense!");
182 H_[0][0] * H_[0][0] + H_[0][1] * H_[0][1] + H_[0][2] * H_[0][2] +
183 H_[1][0] * H_[1][0] + H_[1][1] * H_[1][1] + H_[1][2] * H_[1][2] +
184 H_[2][0] * H_[2][0] + H_[2][1] * H_[2][1] + H_[2][2] * H_[2][2];
189 Params.push_back(H_[0][0]/Hnorm);
190 Params.push_back(H_[0][1]/Hnorm);
191 Params.push_back(H_[0][2]/Hnorm);
192 Params.push_back(H_[1][0]/Hnorm);
193 Params.push_back(H_[1][1]/Hnorm);
194 Params.push_back(H_[1][2]/Hnorm);
195 Params.push_back(H_[2][0]/Hnorm);
196 Params.push_back(H_[2][1]/Hnorm);
202 bool Parametrization::ParamsToHMatrix(
HMatrix &Mat,
203 const vector<double> &Params )
205 if ( Params.size() != 8 )
207 BIASERR(
"There must be 8 parameters to compose the H matrix!");
224 (Params[0] * Params[0] +
225 Params[1] * Params[1] +
226 Params[2] * Params[2] +
227 Params[3] * Params[3] +
228 Params[4] * Params[4] +
229 Params[5] * Params[5] +
230 Params[6] * Params[6] +
231 Params[7] * Params[7] ));
236 double Parametrization::GetBiggestAbsEntry()
239 for (
int r=0;r<2;r++)
240 for (
int c=0;c<2;c++)
241 if ( abs(F_[r][c])>abs(max) )
254 std::vector<BIAS::HomgPoint2D> &inlier1,
255 std::vector<BIAS::HomgPoint2D> &inlier2,
258 if (Params.
size() != ((UseQuaternion)?6:NUM_PARAM_ESSENTIAL)){
259 BIASERR (
" parameter vector must have length "
260 <<((UseQuaternion)?(6):(NUM_PARAM_ESSENTIAL))
261 <<
" instead of " << Params.
size());
271 Params[0] = CSpherical[1];
272 Params[1] = CSpherical[2];
277 BIASERR(
"unable to extract quaternion from R");
280 Params[2] = q[0]; Params[3]=q[1]; Params[4]=q[2]; Params[5]=q[3];
286 if (fabs(angle)<MINIMUM_ROTATION){
287 rax.
Set(1.0, 0.0, 0.0);
290 rax *= angle/rax.
NormL2();
294 Params[2] = rax[0]; Params[3]=rax[1]; Params[4]=rax[2];
310 if (Params.
size() != 6){
311 BIASERR(
"invalid length of parameter vector "<<Params.
Size());
317 if (Params.
size() != NUM_PARAM_ESSENTIAL){
318 BIASERR (
" parameter vector has length "<<Params.
size()<<
" instead of "
319 << NUM_PARAM_ESSENTIAL);
323 double angle = rax.
NormL2();
325 if (fabs(angle)<MINIMUM_ROTATION){
void Set(const T *pv)
copy the array of vectorsize beginning at *T to this->data_
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
BIAS::Vector3< T > CoordEuclideanToSphere() const
coordinate transform.
int GetRotationTranslation(RMatrix &R, Vector3< double > &C, const std::vector< HomgPoint2D > &inlier1, const std::vector< HomgPoint2D > &inlier2)
find R and C(direction), such that maximum number of 3d points triangulated from correspondences inli...
a 3x3 Matrix describing projective transformations between planes
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
void Set(const Vector3< FMATRIX_TYPE > &epipole, const RMatrixBase &R)
set it from epipole and rotation matrix in order to generate essential matrix from image 1 to image 2...
int SetFromQuaternion(const Quaternion< ROTATION_MATRIX_TYPE > &q)
Set rotation matrix from a quaternion.
unsigned int Size() const
length of the vector
class representing an Essential matrix
int GetQuaternion(Quaternion< ROTATION_MATRIX_TYPE > &quat) const
Calculates quaternion representation for this rotation matrix.
void Set(const Vector3< ROTATION_MATRIX_TYPE > &w, const ROTATION_MATRIX_TYPE phi)
Set from rotation axis w and angle phi (in rad)
double NormFrobenius() const
class representing a Fundamental matrix
bool IsZero(const T eps=std::numeric_limits< T >::epsilon()) const
BIAS::Vector3< T > CoordSphereToEuclidean() const
coordinate transfrom.
void Scale(const T &scalar, Matrix3x3< T > &destmat) const
scalar-matrix multiplication
int GetRotationAxisAngle(Vector3< ROTATION_MATRIX_TYPE > &axis, ROTATION_MATRIX_TYPE &angle) const
Calculates angle and rotation axis representation for this rotation matrix.
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)