Example of the HLM (Malis) homography estimation algorithm with a 3D object using vpHomography class.
#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 11
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 3D 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], NULL);
return false;
break;
default:
usage(argv[0], optarg_);
return false;
break;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], NULL);
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) {
exit(-1);
}
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 << "Compare with built homography H = R + t/d n " << std::endl;
std::cout << "aHb built from the displacement: \n" << 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 << "aMb " << std::endl << aMb << std::endl;
std::cout << "-------------------------------" << std::endl;
std::cout << "aHb computed using the Malis paralax algorithm" << std::endl;
aHb /= aHb[2][2];
std::cout << std::endl << 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 << "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];
}
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
}