Example of the HLM (Malis) homography estimation algorithm with a planar object using vpHomography class.
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpDebug.h>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpRotationMatrix.h>
#include <visp3/core/vpThetaUVector.h>
#include <visp3/vision/vpHomography.h>
#include <stdlib.h>
#include <visp3/core/vpDebug.h>
#include <visp3/core/vpHomogeneousMatrix.h>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpPoint.h>
#include <visp3/io/vpParseArgv.h>
#define GETOPTARGS "h"
#define L 0.1
#define nbpt 5
#ifdef ENABLE_VISP_NAMESPACE
#endif
void usage(const char *name, const char *badparam);
bool getOptions(int argc, const char **argv);
void usage(const char *name, const char *badparam)
{
fprintf(stdout, "\n\
Test the HLM (Malis) homography estimation algorithm with a planar object.\n\
\n\
SYNOPSIS\n\
%s [-h]\n",
name);
fprintf(stdout, "\n\
OPTIONS: Default\n\
-h\n\
Print the help.\n");
if (badparam) {
fprintf(stderr, "ERROR: \n");
fprintf(stderr, "\nBad parameter [%s]\n", badparam);
}
}
bool getOptions(int argc, const char **argv)
{
const char *optarg_;
int c;
switch (c) {
case 'h':
usage(argv[0], nullptr);
return false;
break;
default:
usage(argv[0], optarg_);
return false;
break;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], nullptr);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
return false;
}
return true;
}
int main(int argc, const char **argv)
{
#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
try {
if (getOptions(argc, argv) == false) {
return EXIT_FAILURE;
}
std::vector<double> xa(nbpt), ya(nbpt);
std::vector<double> xb(nbpt), yb(nbpt);
for (unsigned int i = 0; i < nbpt; i++) {
aP[i] = P[i];
}
for (unsigned int i = 0; i < nbpt; i++) {
bP[i] = P[i];
}
std::cout << "-------------------------------" << std::endl;
std::cout << "aMb " << std::endl << aMb << std::endl;
std::cout << "-------------------------------" << std::endl;
aHb /= aHb[2][2];
std::cout << "aHb computed using the Malis paralax algorithm: \n" << aHb << std::endl;
std::cout << "-------------------------------" << std::endl;
std::cout << "extract R, T and n " << std::endl;
std::cout << "Rotation: aRb" << std::endl;
std::cout << aRb << std::endl;
std::cout << "Translation: aTb" << std::endl;
std::cout << (aTb).t() << std::endl;
std::cout << "Normal to the plane: n" << std::endl;
std::cout << (n).t() << std::endl;
std::cout << "-------------------------------" << std::endl;
std::cout << "Compare with built homography H = R + t/d " << std::endl;
std::cout << "aHb built from the displacement " << std::endl;
std::cout << std::endl << aHb_built / aHb_built[2][2] << std::endl;
aHb_built.computeDisplacement(aRb, aTb, n);
std::cout << "Rotation: aRb" << std::endl;
std::cout << aRb << std::endl;
std::cout << "Translation: aTb" << std::endl;
std::cout << (aTb).t() << std::endl;
std::cout << "Normal to the plane: n" << std::endl;
std::cout << (n).t() << std::endl;
std::cout << "-------------------------------" << std::endl;
std::cout << "test if ap = aHb bp" << std::endl;
for (unsigned int i = 0; i < nbpt; i++) {
std::cout << "Point " << i << std::endl;
std::cout << "(";
std::cout << ") = (";
p = aHb * bP[i];
}
std::cout << "-------------------------------" << std::endl;
std::cout << "test displacement" << std::endl;
std::list<vpRotationMatrix> laRb;
std::list<vpTranslationVector> laTb;
std::list<vpColVector> lnb;
std::list<vpRotationMatrix>::const_iterator it_laRb = laRb.begin();
std::list<vpTranslationVector>::const_iterator it_laTb = laTb.begin();
std::list<vpColVector>::const_iterator it_lnb = lnb.begin();
int k = 1;
while (it_lnb != lnb.end()) {
std::cout << "Solution " << k++ << std::endl;
aRb = *it_laRb;
aTb = *it_laTb;
n = *it_lnb;
std::cout << "Rotation: aRb" << std::endl;
std::cout << aRb << std::endl;
std::cout << "Translation: aTb" << std::endl;
std::cout << (aTb).t() << std::endl;
std::cout << "Normal to the plane: n" << std::endl;
std::cout << (n).t() << std::endl;
++it_laRb;
++it_laTb;
++it_lnb;
}
return EXIT_SUCCESS;
}
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
#else
(void)argc;
(void)argv;
std::cout << "Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
return EXIT_SUCCESS;
#endif
}
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of an homography and operations on homographies.
void computeDisplacement(vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n)
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 double rad(double deg)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
This class defines the container for a plane geometrical structure.
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
double get_w() const
Get the point w coordinate in the image plane.
double get_y() const
Get the point y coordinate in the image plane.
double get_x() const
Get the point x coordinate in the image plane.
void setWorldCoordinates(double oX, double oY, double oZ)
Implementation of a rotation matrix and operations on such kind of matrices.
Class that consider the case of a translation vector.