ViSP  2.10.0

#include <vpHomography.h>

Public Member Functions

 vpHomography ()
 
 vpHomography (const vpHomography &H)
 
 vpHomography (const vpHomogeneousMatrix &aMb, const vpPlane &bP)
 
 vpHomography (const vpRotationMatrix &aRb, const vpTranslationVector &atb, const vpPlane &bP)
 
 vpHomography (const vpThetaUVector &tu, const vpTranslationVector &atb, const vpPlane &bP)
 
 vpHomography (const vpPoseVector &arb, const vpPlane &bP)
 
virtual ~vpHomography ()
 
void buildFrom (const vpRotationMatrix &aRb, const vpTranslationVector &atb, const vpPlane &bP)
 
void buildFrom (const vpThetaUVector &tu, const vpTranslationVector &atb, const vpPlane &bP)
 
void buildFrom (const vpPoseVector &arb, const vpPlane &bP)
 
void buildFrom (const vpHomogeneousMatrix &aMb, const vpPlane &bP)
 
void computeDisplacement (vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n)
 
void computeDisplacement (const vpColVector &nd, vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n)
 
unsigned int getRows () const
 
unsigned int getCols () const
 
vpHomography inverse () const
 
void inverse (vpHomography &Hi) const
 
void load (std::ifstream &f)
 
double * operator[] (unsigned int i)
 
double * operator[] (unsigned int i) const
 
vpHomography operator* (const vpHomography &H) const
 
vpHomography operator* (const double &v) const
 
vpColVector operator* (const vpColVector &b) const
 
vpHomography operator/ (const double &v) const
 
vpHomographyoperator/= (double v)
 
vpHomographyoperator= (const vpHomography &H)
 
vpHomographyoperator= (const vpMatrix &H)
 
void save (std::ofstream &f) const
 
void setIdentity ()
 

Static Public Member Functions

static void DLT (const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, vpHomography &aHb, bool normalization=true)
 
static void HLM (const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, bool isplanar, vpHomography &aHb)
 
static bool ransac (const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, vpHomography &aHb, std::vector< bool > &inliers, double &residual, unsigned int nbInliersConsensus, double threshold, bool normalization=true)
 
static vpImagePoint project (const vpCameraParameters &cam, const vpHomography &bHa, const vpImagePoint &iPa)
 
static vpPoint project (const vpHomography &bHa, const vpPoint &Pa)
 
static void robust (const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, vpHomography &aHb, std::vector< bool > &inlier, double &residual, double weights_threshold=0.4, unsigned int niter=4, bool normalization=true)
 

Public Attributes

double * data
 

Friends

VISP_EXPORT std::ostream & operator<< (std::ostream &s, const vpHomography &H)
 

Deprecated functions

vp_deprecated void print ()
 
static vp_deprecated void computeDisplacement (const vpMatrix H, const double x, const double y, vpList< vpRotationMatrix > &vR, vpList< vpTranslationVector > &vT, vpList< vpColVector > &vN)
 
static void DLT (unsigned int n, double *xb, double *yb, double *xa, double *ya, vpHomography &aHb)
 
static vp_deprecated void HartleyDLT (unsigned int n, double *xb, double *yb, double *xa, double *ya, vpHomography &aHb)
 
static void HLM (unsigned int n, double *xb, double *yb, double *xa, double *ya, bool isplan, vpHomography &aHb)
 
static vp_deprecated bool ransac (unsigned int n, double *xb, double *yb, double *xa, double *ya, vpHomography &aHb, int consensus=1000, double threshold=1e-6)
 
static vp_deprecated bool ransac (unsigned int n, double *xb, double *yb, double *xa, double *ya, vpHomography &aHb, vpColVector &inliers, double residual=0.1, int consensus=1000, double threshold=1e-6, double areaThreshold=0.0)
 

Detailed Description

This class aims to compute the homography wrt.two images.

These two images are both described by a set of points. The 2 sets (one per image) are sets of corresponding points : for a point in a image, there is the corresponding point (image of the same 3D point) in the other image points set. These 2 sets are the only data needed to compute the homography. One method used is the one introduced by Ezio Malis during his PhD [17]. A normalization is carried out on this points in order to improve the conditioning of the problem, what leads to improve the stability of the result.

Store and compute the homography such that

\[ ^a{\bf p} = ^a{\bf H}_b\; ^b{\bf p} \]

with

\[ ^a{\bf H}_b = ^a{\bf R}_b + \frac{^a{\bf t}_b}{^bd} { ^b{\bf n}^T} \]

The Tutorial: Homography estimation from points explains how to use this class.

The example below shows also how to manipulate this class to first compute a ground truth homography from camera poses, project pixel coordinates points using an homography and lastly estimate an homography from a subset of 4 matched points in frame a and frame b respectively.

#include <visp/vpHomogeneousMatrix.h>
#include <visp/vpHomography.h>
#include <visp/vpMath.h>
#include <visp/vpMeterPixelConversion.h>
int main()
{
// Initialize in the object frame the coordinates in meters of 4 points that
// belong to a planar object
vpPoint Po[4];
Po[0].setWorldCoordinates(-0.1, -0.1, 0);
Po[1].setWorldCoordinates( 0.2, -0.1, 0);
Po[2].setWorldCoordinates( 0.1, 0.1, 0);
Po[3].setWorldCoordinates(-0.1, 0.3, 0);
// Initialize the pose between camera frame a and object frame o
vpHomogeneousMatrix aMo(0, 0, 1, 0, 0, 0); // Camera is 1 meter far
// Initialize the pose between camera frame a and camera frame
// b. These two frames correspond for example to two successive
// camera positions
vpHomogeneousMatrix aMb(0.2, 0.1, 0, 0, 0, vpMath::rad(2));
// Compute the pose between camera frame b and object frame
vpHomogeneousMatrix bMo = aMb.inverse() * aMo;
// Initialize camera intrinsic parameters
// Compute the coordinates in pixels of the 4 object points in the
// camera frame a
vpPoint Pa[4];
std::vector<double> xa(4), ya(4); // Coordinates in pixels of the points in frame a
for(int i=0 ; i < 4 ; i++) {
Pa[i] = Po[i];
Pa[i].project(aMo); // Project the points from object frame to
// camera frame a
Pa[i].get_x(), Pa[i].get_y(),
xa[i], ya[i]);
}
// Compute the coordinates in pixels of the 4 object points in the
// camera frame b
vpPoint Pb[4];
std::vector<double> xb(4), yb(4); // Coordinates in pixels of the points in frame b
for(int i=0 ; i < 4 ; i++) {
Pb[i] = Po[i];
Pb[i].project(bMo); // Project the points from object frame to
// camera frame a
}
// Compute equation of the 3D plane containing the points in camera frame b
vpPlane bP(Pb[0], Pb[1], Pb[2]);
// Compute the corresponding ground truth homography
vpHomography aHb(aMb, bP);
std::cout << "Ground truth homography aHb: \n" << aHb<< std::endl;
// Compute the coordinates of the points in frame b using the ground
// truth homography and the coordinates of the points in frame a
vpHomography bHa = aHb.inverse();
for(int i = 0; i < 4 ; i++){
double inv_z = 1. / (bHa[2][0] * xa[i] + bHa[2][1] * ya[i] + bHa[2][2]);
xb[i] = (bHa[0][0] * xa[i] + bHa[0][1] * ya[i] + bHa[0][2]) * inv_z;
yb[i] = (bHa[1][0] * xa[i] + bHa[1][1] * ya[i] + bHa[1][2]) * inv_z;
}
// Estimate the homography from 4 points coordinates expressed in pixels
vpHomography::DLT(xb, yb, xa, ya, aHb, true);
aHb /= aHb[2][2]; // Apply a scale factor to have aHb[2][2] = 1
std::cout << "Estimated homography aHb: \n" << aHb<< std::endl;
}
Examples:
homographyHartleyDLT2DObject.cpp, homographyHLM2DObject.cpp, homographyHLM3DObject.cpp, homographyRansac2DObject.cpp, planarObjectDetector.cpp, testDisplacement.cpp, tutorial-homography-from-points.cpp, tutorial-matching-keypoint-homography.cpp, tutorial-matching-surf-homography-deprecated.cpp, and tutorial-template-tracker.cpp.

Definition at line 178 of file vpHomography.h.

Constructor & Destructor Documentation

vpHomography::vpHomography ( )

initialize an homography as Identity

Definition at line 64 of file vpHomography.cpp.

References data, and setIdentity().

vpHomography::vpHomography ( const vpHomography H)

initialize an homography from another homography

Definition at line 75 of file vpHomography.cpp.

References data.

vpHomography::vpHomography ( const vpHomogeneousMatrix aMb,
const vpPlane bP 
)

Construction from Translation and rotation and a plane.

initialize an homography from another homography

Definition at line 85 of file vpHomography.cpp.

References buildFrom(), and data.

vpHomography::vpHomography ( const vpRotationMatrix aRb,
const vpTranslationVector atb,
const vpPlane bP 
)

Construction from Translation and rotation and a plane.

Definition at line 99 of file vpHomography.cpp.

References buildFrom(), and data.

vpHomography::vpHomography ( const vpThetaUVector tu,
const vpTranslationVector atb,
const vpPlane bP 
)

Construction from Translation and rotation and a plane.

Definition at line 91 of file vpHomography.cpp.

References buildFrom(), and data.

vpHomography::vpHomography ( const vpPoseVector arb,
const vpPlane bP 
)

Construction from Translation and rotation and a plane.

Definition at line 107 of file vpHomography.cpp.

References buildFrom(), and data.

vpHomography::~vpHomography ( )
virtual

Definition at line 113 of file vpHomography.cpp.

References data.

Member Function Documentation

void vpHomography::buildFrom ( const vpRotationMatrix aRb,
const vpTranslationVector atb,
const vpPlane bP 
)

Construction from Translation and rotation and a plane.

Definition at line 141 of file vpHomography.cpp.

Referenced by vpHomography().

void vpHomography::buildFrom ( const vpThetaUVector tu,
const vpTranslationVector atb,
const vpPlane bP 
)

Construction from Translation and rotation and a plane.

Definition at line 130 of file vpHomography.cpp.

void vpHomography::buildFrom ( const vpPoseVector arb,
const vpPlane bP 
)

Construction from Translation and rotation and a plane.

Definition at line 152 of file vpHomography.cpp.

References vpHomogeneousMatrix::buildFrom().

void vpHomography::buildFrom ( const vpHomogeneousMatrix aMb,
const vpPlane bP 
)

Construction from homogeneous matrix and a plane.

Definition at line 121 of file vpHomography.cpp.

void vpHomography::computeDisplacement ( vpRotationMatrix aRb,
vpTranslationVector atb,
vpColVector n 
)

Compute the camera displacement between two images from the homography $ {^a}{\bf H}_b $ which is here an implicit parameter (*this).

Parameters
aRb: Rotation matrix as an output $ {^a}{\bf R}_b $.
atb: Translation vector as an output $ ^a{\bf t}_b $.
n: Normal vector to the plane as an output.
Examples:
homographyHartleyDLT2DObject.cpp, homographyHLM2DObject.cpp, homographyHLM3DObject.cpp, and tutorial-homography-from-points.cpp.

Definition at line 64 of file vpHomographyExtract.cpp.

Referenced by computeDisplacement().

void vpHomography::computeDisplacement ( const vpColVector nd,
vpRotationMatrix aRb,
vpTranslationVector atb,
vpColVector n 
)

Compute the camera displacement between two images from the homography $ {^a}{\bf H}_b $ which is here an implicit parameter (*this).

Camera displacement between $ {^a}{\bf p} $ and $ {^a}{\bf p} $ is represented as a rotation matrix $ {^a}{\bf R}_b $ and a translation vector $ ^a{\bf t}_b $ from which an homogenous matrix can be build (vpHomogeneousMatrix).

Parameters
nd: Input normal vector to the plane used to compar with the normal vector n extracted from the homography.
aRb: Rotation matrix as an output $ {^a}{\bf R}_b $.
atb: Translation vector as an output $ ^a{\bf t}_b $.
n: Normal vector to the plane as an output.

Definition at line 97 of file vpHomographyExtract.cpp.

References computeDisplacement().

void vpHomography::computeDisplacement ( const vpMatrix  H,
const double  x,
const double  y,
vpList< vpRotationMatrix > &  vR,
vpList< vpTranslationVector > &  vT,
vpList< vpColVector > &  vN 
)
static
Deprecated:
This method is deprecated. You should use computeDisplacement(const vpMatrix &, const double, const double, std::list<vpRotationMatrix> &, std::list<vpTranslationVector> &, std::list<vpColVector> &) instead.

Definition at line 1342 of file vpHomographyExtract.cpp.

References vpList< type >::addRight(), vpList< type >::kill(), vpRotationMatrix::setIdentity(), vpMath::sqr(), vpMatrix::svd(), and vpRotationMatrix::t().

void vpHomography::DLT ( const std::vector< double > &  xb,
const std::vector< double > &  yb,
const std::vector< double > &  xa,
const std::vector< double > &  ya,
vpHomography aHb,
bool  normalization = true 
)
static

From couples of matched points $^a{\bf p}=(x_a,y_a,1)$ in image a and $^b{\bf p}=(x_b,y_b,1)$ in image b with homogeneous coordinates, computes the homography matrix by resolving $^a{\bf p} = ^a{\bf H}_b\; ^b{\bf p}$ using the DLT (Direct Linear Transform) algorithm.

At least 4 couples of points are needed.

To do so, we use the DLT algorithm on the data, ie we resolve the linear system by SDV : $\bf{Ah} =0$ where $\bf{h}$ is the vector with the terms of $^a{\bf H}_b$ and $\mathbf{A}$ depends on the points coordinates.

For each point, in homogeneous coordinates we have:

\[ ^a{\bf p} = ^a{\bf H}_b\; ^b{\bf p} \]

which is equivalent to:

\[ ^a{\bf p} \times {^a{\bf H}_b \; ^b{\bf p}} =0 \]

If we note $\mathbf{h}_j^T$ the $j^{\textrm{th}}$ line of $^a{\bf H}_b$, we can write:

\[ ^a{\bf H}_b \; ^b{\bf p} = \left( \begin{array}{c}\mathbf{h}_1^T \;^b{\bf p} \\\mathbf{h}_2^T \; ^b{\bf p} \\\mathbf{h}_3^T \;^b{\bf p} \end{array}\right) \]

Setting $^a{\bf p}=(x_{a},y_{a},w_{a})$, the cross product can be rewritten by:

\[ ^a{\bf p} \times ^a{\bf H}_b \; ^b{\bf p} =\left( \begin{array}{c}y_{a}\mathbf{h}_3^T \; ^b{\bf p}-w_{a}\mathbf{h}_2^T \; ^b{\bf p} \\w_{a}\mathbf{h}_1^T \; ^b{\bf p} -x_{a}\mathbf{h}_3^T \; ^b{\bf p} \\x_{a}\mathbf{h}_2^T \; ^b{\bf p}- y_{a}\mathbf{h}_1^T \; ^b{\bf p}\end{array}\right) \]

\[ \underbrace{\left( \begin{array}{ccc}\mathbf{0}^T & -w_{a} \; ^b{\bf p}^T & y_{a} \; ^b{\bf p}^T \\ w_{a} \; ^b{\bf p}^T&\mathbf{0}^T & -x_{a} \; ^b{\bf p}^T \\ -y_{a} \; ^b{\bf p}^T & x_{a} \; ^b{\bf p}^T & \mathbf{0}^T\end{array}\right)}_{\mathbf{A}_i (3\times 9)} \underbrace{\left( \begin{array}{c}\mathbf{h}_{1}^{T} \\ \mathbf{h}_{2}^{T}\\\mathbf{h}_{3}^{T}\end{array}\right)}_{\mathbf{h} (9\times 1)}=0 \]

leading to an homogeneous system to be solved: $\mathbf{A}\mathbf{h}=0$ with $\mathbf{A}=\left(\mathbf{A}_1^T, ..., \mathbf{A}_i^T, ..., \mathbf{A}_n^T \right)^T$.

It can be solved using an SVD decomposition:

\[\bf A = UDV^T \]

h is the column of V associated with the smalest singular value of A

Parameters
xb,yb: Coordinates vector of matched points in image b. These coordinates are expressed in meters.
xa,ya: Coordinates vector of matched points in image a. These coordinates are expressed in meters.
aHb: Estimated homography that relies the transformation from image a to image b.
normalization: When set to true, the coordinates of the points are normalized. The normalization carried out is the one preconized by Hartley.
Exceptions
vpMatrixException::rankDeficient: When the rank of the matrix that should be 8 is deficient.
Examples:
homographyHartleyDLT2DObject.cpp, and tutorial-homography-from-points.cpp.

Definition at line 503 of file vpHomographyDLT.cpp.

References vpException::dimensionError, vpException::fatalError, vpMatrix::getCol(), vpMatrixException::rankDeficient, vpMatrix::resize(), vpMatrix::svd(), vpERROR_TRACE, and vpTRACE.

Referenced by HartleyDLT(), and ransac().

void vpHomography::DLT ( unsigned int  n,
double *  xb,
double *  yb,
double *  xa,
double *  ya,
vpHomography aHb 
)
static

Computes the homography matrix wrt. the data using the DLT (Direct Linear Transform) algorithm.

Deprecated:
You should rather use vpHomography::DLT(const std::vector<double> &, const std::vector<double> &, const std::vector<double> &, const std::vector<double> &, vpHomography &, bool)

Computes H such as

\[ ^a{\bf p} = ^a{\bf H}_b\; ^b{\bf p} \]

To do so, we use the DLT algorithm on the data, ie we resolve the linear system by SDV : $\bf{Ah} =0$. $\bf{h}$ is the vector with the terms of $\mathbf{H}$,

$\mathbf{A}$ depends on the points coordinates.

At least 4 correspondant points couples are needed.

For each point, in homogeneous coordinates we have:

\[ \mathbf{p}_{a}= \mathbf{H}\mathbf{p}_{b} \]

which is equivalent to:

\[ \mathbf{p}_{a} \times \mathbf{H}\mathbf{p}_{b} =0 \]

If we note $\mathbf{h}_j^T$ the $j^{\textrm{th}}$ line of $\mathbf{H}$, we can write:

\[ \mathbf{H}\mathbf{p}_{b} = \left( \begin{array}{c}\mathbf{h}_1^T\mathbf{p}_{b} \\\mathbf{h}_2^T\mathbf{p}_{b} \\\mathbf{h}_3^T \mathbf{p}_{b} \end{array}\right) \]

Setting $\mathbf{p}_{a}=(x_{a},y_{a},w_{a})$, the cross product can be rewritten by:

\[ \mathbf{p}_{a} \times \mathbf{H}\mathbf{p}_{b} =\left( \begin{array}{c}y_{a}\mathbf{h}_3^T\mathbf{p}_{b}-w_{a}\mathbf{h}_2^T\mathbf{p}_{b} \\w_{a}\mathbf{h}_1^T\mathbf{p}_{b} -x_{a}\mathbf{h}_3^T \mathbf{p}_{b} \\x_{a}\mathbf{h}_2^T \mathbf{p}_{b}- y_{a}\mathbf{h}_1^T\mathbf{p}_{b}\end{array}\right) \]

\[ \underbrace{\left( \begin{array}{ccc}\mathbf{0}^T & -w_{a} \mathbf{p}_{b}^T & y_{a} \mathbf{p}_{b}^T \\ w_{a} \mathbf{p}_{b}^T&\mathbf{0}^T & -x_{a} \mathbf{p}_{b}^T \\ -y_{a} \mathbf{p}_{b}^T & x_{a} \mathbf{p}_{b}^T & \mathbf{0}^T\end{array}\right)}_{\mathbf{A}_i (3\times 9)} \underbrace{\left( \begin{array}{c}\mathbf{h}_{1}^{T} \\ \mathbf{h}_{2}^{T}\\\mathbf{h}_{3}^{T}\end{array}\right)}_{\mathbf{h} (9\times 1)}=0 \]

leading to an homogeneous system to be solve: $\mathbf{A}\mathbf{h}=0$ with $\mathbf{A}=\left(\mathbf{A}_1^T, ..., \mathbf{A}_i^T, ..., \mathbf{A}_n^T \right)^T$.

It can be solved using an SVD decomposition:

\[\bf A = UDV^T \]

h is the column of V associated with the smalest singular value of A

Exceptions
vpMatrixException::rankDeficient: When the rank of the matrix that should be 8 is deficient.

Definition at line 338 of file vpHomographyDLT.cpp.

References vpMatrix::getCol(), vpMatrixException::rankDeficient, vpMatrix::resize(), vpMatrix::svd(), vpERROR_TRACE, and vpTRACE.

unsigned int vpHomography::getCols ( ) const
inline

Return the number of columns of the homography matrix.

Definition at line 259 of file vpHomography.h.

unsigned int vpHomography::getRows ( ) const
inline

Return the number of rows of the homography matrix.

Definition at line 257 of file vpHomography.h.

void vpHomography::HartleyDLT ( unsigned int  n,
double *  xb,
double *  yb,
double *  xa,
double *  ya,
vpHomography aHb 
)
static

Computes the homography matrix using the DLT (Direct Linear Transform) algorithm on normalized data.

Deprecated:
You should rather use vpHomography::DLT(const std::vector<double> &, const std::vector<double> &, const std::vector<double> &, const std::vector<double> &, vpHomography &, bool)

Normalizes data, computes H wrt. these normalized data and denormalizes the result. The normalization carried out is the one preconized by Hartley . At least 4 correspondant points couples are needed.

See also
DLT()
Exceptions
vpMatrixException::rankDeficient: When the rank of the matrix that should be 8 is deficient.

Definition at line 225 of file vpHomographyDLT.cpp.

References DLT(), and vpTRACE.

void vpHomography::HLM ( const std::vector< double > &  xb,
const std::vector< double > &  yb,
const std::vector< double > &  xa,
const std::vector< double > &  ya,
bool  isplanar,
vpHomography aHb 
)
static

From couples of matched points $^a{\bf p}=(x_a,y_a,1)$ in image a and $^b{\bf p}=(x_b,y_b,1)$ in image b with homogeneous coordinates, computes the homography matrix by resolving $^a{\bf p} = ^a{\bf H}_b\; ^b{\bf p}$ using Ezio Malis linear method (HLM) [16].

This method can consider points that are planar or non planar. The algorithm for planar scene implemented in this file is described in Ezio Malis PhD thesis [17].

Parameters
xb,yb: Coordinates vector of matched points in image b. These coordinates are expressed in meters.
xa,ya: Coordinates vector of matched points in image a. These coordinates are expressed in meters.
isplanar: If true the points are assumed to be in a plane, otherwise there are assumed to be non planar.
aHb: Estimated homography that relies the transformation from image a to image b.

If the boolean isplanar is true the points are assumed to be in a plane otherwise there are assumed to be non planar.

See also
DLT() when the scene is planar.
Examples:
homographyHLM2DObject.cpp, homographyHLM3DObject.cpp, and tutorial-homography-from-points.cpp.

Definition at line 828 of file vpHomographyMalis.cpp.

References vpException::dimensionError, and vpException::fatalError.

Referenced by HLM(), and vpPose::poseFromRectangle().

void vpHomography::HLM ( unsigned int  n,
double *  xb,
double *  yb,
double *  xa,
double *  ya,
bool  isplanar,
vpHomography aHb 
)
static

Computes the homography matrix from planar [17] or non planar points using Ezio Malis linear method (HLM) [16].

Computes H such as

\[ ^a{\bf p} = ^a{\bf H}_b\; ^b{\bf p} \]

The algorithm for 2D scene implemented in this file is described in Ezio Malis PhD thesis.

If the boolean isplanar is true the point is assumed to be in a plane otherwise there are assumed to be planar.

The reference planar is the plane build from the 3 first points.

Definition at line 783 of file vpHomographyMalis.cpp.

References HLM().

vpHomography vpHomography::inverse ( ) const

invert the homography

Invert the homography.

Returns
$\bf H^{-1}$

Definition at line 222 of file vpHomography.cpp.

References vpMatrix::pseudoInverse().

Referenced by vpTemplateTrackerWarpHomography::getParamInverse(), and inverse().

void vpHomography::inverse ( vpHomography bHa) const

invert the homography

Invert the homography.

Parameters
bHa: $\bf H^{-1}$ with H = *this.

Definition at line 243 of file vpHomography.cpp.

References inverse().

void vpHomography::load ( std::ifstream &  f)

Load an homography from a file.

Read an homography in a file, verify if it is really an homogeneous matrix.

Parameters
f: the file.

Definition at line 420 of file vpHomography.cpp.

References vpException::ioError.

vpHomography vpHomography::operator* ( const vpHomography H) const

Multiplication by an homography.

Parameters
H: Homography to multiply with.
vpHomography aHb, bHc;
// Initialize aHb and bHc homographies
vpHomography aHc = aHb * bHc;

Definition at line 275 of file vpHomography.cpp.

vpHomography vpHomography::operator* ( const double &  v) const

Multiply an homography by a scalar.

Parameters
v: Value of the scalar.
double v = 1.1;
// Initialize aHb
vpHomography H = aHb * v;

Definition at line 325 of file vpHomography.cpp.

References data.

vpColVector vpHomography::operator* ( const vpColVector b) const

Operation a = aHb * b.

Parameters
b: 3 dimension vector.

Definition at line 296 of file vpHomography.cpp.

References vpException::dimensionError, and vpColVector::size().

vpHomography vpHomography::operator/ ( const double &  v) const

Divide an homography by a scalar.

Parameters
v: Value of the scalar.
// Initialize aHb
vpHomography H = aHb / aHb[2][2];

Definition at line 349 of file vpHomography.cpp.

References data, and vpException::divideByZeroError.

vpHomography & vpHomography::operator/= ( double  v)

Divide all the element of the homography matrix by v : Hij = Hij / v.

Definition at line 365 of file vpHomography.cpp.

References data, and vpException::divideByZeroError.

vpHomography & vpHomography::operator= ( const vpHomography H)

Copy operator. Allow operation such as aHb = H

Parameters
H: Homography matrix to be copied.

Definition at line 386 of file vpHomography.cpp.

vpHomography & vpHomography::operator= ( const vpMatrix H)

Copy operator. Allow operation such as aHb = H

Parameters
H: Matrix to be copied.

Definition at line 401 of file vpHomography.cpp.

References vpException::dimensionError, vpMatrix::getCols(), and vpMatrix::getRows().

double* vpHomography::operator[] ( unsigned int  i)
inline

Write elements Hij (usage : H[i][j] = x )

Definition at line 270 of file vpHomography.h.

double* vpHomography::operator[] ( unsigned int  i) const
inline

Read elements Hij (usage : x = H[i][j] )

Definition at line 272 of file vpHomography.h.

void vpHomography::print ( )

Print the matrix.

Print the homography as a matrix.

Definition at line 440 of file vpHomography.cpp.

vpImagePoint vpHomography::project ( const vpCameraParameters cam,
const vpHomography bHa,
const vpImagePoint iPa 
)
static

Given iPa a point with coordinates $(u_a,v_a)$ expressed in pixel in image a, and the homography bHa that links image a and b, computes the coordinates of the point $(u_b,v_b)$ in the image b using the camera parameters matrix $\bf K$.

Compute $^b{\bf p} = {\bf K} \; {^b}{\bf H}_a \; {\bf K}^{-1} {^a}{\bf p}$ with $^a{\bf p}=(u_a,v_a,1)$ and $^b{\bf p}=(u_b,v_b,1)$

Returns
The coordinates in pixel of the point with coordinates $(u_b,v_b)$.
Examples:
tutorial-homography-from-points.cpp, tutorial-matching-keypoint-homography.cpp, and tutorial-matching-surf-homography-deprecated.cpp.

Definition at line 537 of file vpHomography.cpp.

References vpCameraParameters::get_K(), vpCameraParameters::get_K_inverse(), vpImagePoint::get_u(), and vpImagePoint::get_v().

vpPoint vpHomography::project ( const vpHomography bHa,
const vpPoint Pa 
)
static

Given Pa a point with normalized coordinates $(x_a,y_a,1)$ in the image plane a, and the homography bHa that links image a and b, computes the normalized coordinates of the point $(x_b,y_b,1)$ in the image plane b.

Compute $^b{\bf p} = {^b}{\bf H}_a \; {^a}{\bf p}$ with $^a{\bf p}=(x_a,y_a,1)$ and $^b{\bf p}=(x_b,y_b,1)$

Returns
The coordinates in meter of the point with coordinates $(x_b,y_b)$.

Definition at line 559 of file vpHomography.cpp.

References vpPoint::get_x(), vpPoint::get_y(), vpPoint::set_x(), and vpPoint::set_y().

bool vpHomography::ransac ( const std::vector< double > &  xb,
const std::vector< double > &  yb,
const std::vector< double > &  xa,
const std::vector< double > &  ya,
vpHomography aHb,
std::vector< bool > &  inliers,
double &  residual,
unsigned int  nbInliersConsensus,
double  threshold,
bool  normalization = true 
)
static

From couples of matched points $^a{\bf p}=(x_a,y_a,1)$ in image a and $^b{\bf p}=(x_b,y_b,1)$ in image b with homogeneous coordinates, computes the homography matrix by resolving $^a{\bf p} = ^a{\bf H}_b\; ^b{\bf p}$ using Ransac algorithm.

Parameters
xb,yb: Coordinates vector of matched points in image b. These coordinates are expressed in meters.
xa,ya: Coordinates vector of matched points in image a. These coordinates are expressed in meters.
aHb: Estimated homography that relies the transformation from image a to image b.
inliers: Vector that indicates if a matched point is an inlier (true) or an outlier (false).
residual: Global residual computed as $r = \sqrt{1/n \sum_{inliers} {\| {^a{\bf p} - {\hat{^a{\bf H}_b}} {^b{\bf p}}} \|}^{2}}$ with $n$ the number of inliers.
nbInliersConsensus: Minimal number of points requested to fit the estimated homography.
threshold: Threshold for outlier removing. A point is considered as an outlier if the reprojection error $\| {^a{\bf p} - {\hat{^a{\bf H}_b}} {^b{\bf p}}} \|$ is greater than this threshold.
normalization: When set to true, the coordinates of the points are normalized. The normalization carried out is the one preconized by Hartley.
Returns
true if the homography could be computed, false otherwise.
Examples:
homographyRansac2DObject.cpp, tutorial-matching-keypoint-homography.cpp, and tutorial-matching-surf-homography-deprecated.cpp.

Definition at line 435 of file vpHomographyRansac.cpp.

References vpException::dimensionError, DLT(), vpException::fatalError, and vpERROR_TRACE.

bool vpHomography::ransac ( unsigned int  n,
double *  xb,
double *  yb,
double *  xa,
double *  ya,
vpHomography aHb,
int  consensus = 1000,
double  threshold = 1e-6 
)
static
bool vpHomography::ransac ( unsigned int  n,
double *  xb,
double *  yb,
double *  xa,
double *  ya,
vpHomography bHa,
vpColVector inliers,
double  residual = 0.1,
int  consensus = 1000,
double  threshold = 1e-6,
double  areaThreshold = 0.0 
)
static
Deprecated:
This method is deprecated. You should rather use vpHomography::ransac(const std::vector<double> &, const std::vector<double> &, const std::vector<double> &, const std::vector<double> &, vpHomography &, std::vector<bool> &, double &, unsigned int, double, bool)

Computes homography matrix $ b^H_a $ such as $X_b = b^H_a X_a $ with $ X_a = (xa, ya)^t $ and $ X_b = (xb, yb)^t $.

Parameters
n: Number of points.
xb,yb: Coordinates of the points in $ X_b $ vector.
xa,ya: Coordinates of the points in $ X_a $ vector.
bHa: Homography matrix computed from $ X_a $ and $ X_b $ vectors.
inliers: n dimention vector indicating if a point is an inlier (value 1.0) or an outlier (value 0). Matches are stocked in inliers vector column.
residual: Residual. Not used.
consensus: Minimal number of points (less than n) fitting the model.
threshold: Threshold for outlier removing.
areaThreshold: Ensure that the area formed by every 3 points within the 4 points used to compute the homography is greater than this threshold. If the area is smaller, we are in a degenerate case.
Returns
true if the homography could be computed from 4 non-degenerated points.

Definition at line 379 of file vpHomographyRansac.cpp.

References data, and vpRansac< vpTransformation >::ransac().

void vpHomography::robust ( const std::vector< double > &  xb,
const std::vector< double > &  yb,
const std::vector< double > &  xa,
const std::vector< double > &  ya,
vpHomography aHb,
std::vector< bool > &  inliers,
double &  residual,
double  weights_threshold = 0.4,
unsigned int  niter = 4,
bool  normalization = true 
)
static

From couples of matched points $^a{\bf p}=(x_a,y_a,1)$ in image a and $^b{\bf p}=(x_b,y_b,1)$ in image b with homogeneous coordinates, computes the homography matrix by resolving $^a{\bf p} = ^a{\bf H}_b\; ^b{\bf p}$ using a robust estimation scheme.

This method is to compare to DLT() except that here a robust estimator is used to reject couples of points that are considered as outliers.

At least 4 couples of points are needed.

Parameters
xb,yb: Coordinates vector of matched points in image b. These coordinates are expressed in meters.
xa,ya: Coordinates vector of matched points in image a. These coordinates are expressed in meters.
aHb: Estimated homography that relies the transformation from image a to image b.
inliers: Vector that indicates if a matched point is an inlier (true) or an outlier (false).
residual: Global residual computed as $r = \sqrt{1/n \sum_{inliers} {\| {^a{\bf p} - {\hat{^a{\bf H}_b}} {^b{\bf p}}} \|}^{2}}$ with $n$ the number of inliers.
weights_threshold: Threshold applied on the weights updated during the robust estimation and used to consider if a point is an outlier or an inlier. Values should be in [0:1]. A couple of matched points that have a weight lower than this threshold is considered as an outlier. A value equal to zero indicates that all the points are inliers.
niter: Number of iterations of the estimation process.
normalization: When set to true, the coordinates of the points are normalized. The normalization carried out is the one preconized by Hartley.
See also
DLT(), ransac()
Examples:
tutorial-matching-keypoint-homography.cpp, and tutorial-matching-surf-homography-deprecated.cpp.

Definition at line 603 of file vpHomography.cpp.

References data, vpException::dimensionError, vpException::fatalError, vpRobust::MEstimator(), vpMatrix::pseudoInverse(), vpRobust::setIteration(), and vpRobust::TUKEY.

void vpHomography::save ( std::ofstream &  f) const

Save an homography in a file.

Definition at line 250 of file vpHomography.cpp.

References vpException::ioError.

void vpHomography::setIdentity ( )

Set the homography as identity transformation.

Definition at line 517 of file vpHomography.cpp.

Referenced by vpHomography().

Friends And Related Function Documentation

VISP_EXPORT std::ostream& operator<< ( std::ostream &  s,
const vpHomography H 
)
friend

std::cout a matrix

Definition at line 751 of file vpHomography.cpp.

Member Data Documentation

double* vpHomography::data

Data array.

Definition at line 182 of file vpHomography.h.

Referenced by operator*(), operator/(), operator/=(), ransac(), robust(), vpHomography(), and ~vpHomography().