Example of the HLM (Malis) homography estimation algorithm with a planar object using vpHomography class.
#include <visp/vpMath.h>
#include <visp/vpRotationMatrix.h>
#include <visp/vpHomography.h>
#include <visp/vpDebug.h>
#include <visp/vpThetaUVector.h>
#include <visp/vpPoint.h>
#include <visp/vpMath.h>
#include <visp/vpHomogeneousMatrix.h>
#include <visp/vpDebug.h>
#include <visp/vpParseArgv.h>
#include <stdlib.h>
#define GETOPTARGS "h"
#define L 0.1
#define nbpt 5
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], 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 (getOptions(argc, argv) == false) {
exit (-1);
}
int i ;
double xa[nbpt], ya[nbpt] ;
double xb[nbpt], yb[nbpt] ;
for(i=0 ; i < nbpt ; i++)
{
aP[i] = P[i] ;
}
for(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 ;
vpTRACE(
"aHb computed using the Malis paralax algorithm") ;
aHb /= aHb[2][2] ;
std::cout << std::endl << aHb<< std::endl ;
std::cout << "-------------------------------" <<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 ;
vpTRACE(
"Compare with built homography H = R + t/d ") ;
vpTRACE(
"aHb built from the displacement ") ;
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 ;
for(i=0 ; i < nbpt ; i++)
{
std::cout << "Point "<< i<< std::endl ;
std::cout << "(" ;
std::cout <<") = (" ;
p = aHb*bP[i] ;
}
std::cout << "-------------------------------" <<std::endl ;
std::list<vpRotationMatrix> laRb ;
std::list<vpTranslationVector> laTb ;
std::list<vpColVector> lnb ;
laRb, laTb, 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;
}
}