55 #include <visp3/core/vpDebug.h>
56 #include <visp3/core/vpMath.h>
57 #include <visp3/core/vpRotationMatrix.h>
58 #include <visp3/core/vpThetaUVector.h>
59 #include <visp3/vision/vpHomography.h>
62 #include <visp3/core/vpDebug.h>
63 #include <visp3/core/vpHomogeneousMatrix.h>
64 #include <visp3/core/vpMath.h>
65 #include <visp3/core/vpPoint.h>
66 #include <visp3/io/vpParseArgv.h>
68 #define GETOPTARGS "h"
72 void usage(
const char *name,
const char *badparam);
73 bool getOptions(
int argc,
const char **argv);
84 void usage(
const char *name,
const char *badparam)
87 Test the HLM (Malis) homography estimation algorithm with a planar object.\n\
98 fprintf(stderr,
"ERROR: \n");
99 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
112 bool getOptions(
int argc,
const char **argv)
120 usage(argv[0], NULL);
125 usage(argv[0], optarg_);
131 if ((c == 1) || (c == -1)) {
133 usage(argv[0], NULL);
134 std::cerr <<
"ERROR: " << std::endl;
135 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
142 int main(
int argc,
const char **argv)
146 if (getOptions(argc, argv) ==
false) {
151 std::vector<double> xa(nbpt), ya(nbpt);
152 std::vector<double> xb(nbpt), yb(nbpt);
169 for (
unsigned int i = 0; i < nbpt; i++) {
172 xa[i] = P[i].
get_x();
173 ya[i] = P[i].
get_y();
176 for (
unsigned int i = 0; i < nbpt; i++) {
179 xb[i] = P[i].
get_x();
180 yb[i] = P[i].
get_y();
182 std::cout <<
"-------------------------------" << std::endl;
183 std::cout <<
"aMb " << std::endl << aMb << std::endl;
184 std::cout <<
"-------------------------------" << std::endl;
190 std::cout <<
"aHb computed using the Malis paralax algorithm: \n" << aHb << std::endl;
196 std::cout <<
"-------------------------------" << std::endl;
197 std::cout <<
"extract R, T and n " << std::endl;
199 std::cout <<
"Rotation: aRb" << std::endl;
200 std::cout << aRb << std::endl;
201 std::cout <<
"Translation: aTb" << std::endl;
202 std::cout << (aTb).t() << std::endl;
203 std::cout <<
"Normal to the plane: n" << std::endl;
204 std::cout << (n).t() << std::endl;
206 std::cout <<
"-------------------------------" << std::endl;
207 std::cout <<
"Compare with built homography H = R + t/d " << std::endl;
210 std::cout <<
"aHb built from the displacement " << std::endl;
211 std::cout << std::endl << aHb_built / aHb_built[2][2] << std::endl;
213 aHb_built.computeDisplacement(aRb, aTb, n);
214 std::cout <<
"Rotation: aRb" << std::endl;
215 std::cout << aRb << std::endl;
216 std::cout <<
"Translation: aTb" << std::endl;
217 std::cout << (aTb).t() << std::endl;
218 std::cout <<
"Normal to the plane: n" << std::endl;
219 std::cout << (n).t() << std::endl;
221 std::cout <<
"-------------------------------" << std::endl;
222 std::cout <<
"test if ap = aHb bp" << std::endl;
224 for (
unsigned int i = 0; i < nbpt; i++) {
225 std::cout <<
"Point " << i << std::endl;
229 std::cout <<
") = (";
234 std::cout <<
"-------------------------------" << std::endl;
235 std::cout <<
"test displacement" << std::endl;
237 std::list<vpRotationMatrix> laRb;
238 std::list<vpTranslationVector> laTb;
239 std::list<vpColVector> lnb;
243 std::list<vpRotationMatrix>::const_iterator it_laRb = laRb.begin();
244 std::list<vpTranslationVector>::const_iterator it_laTb = laTb.begin();
245 std::list<vpColVector>::const_iterator it_lnb = lnb.begin();
248 while (it_lnb != lnb.end()) {
249 std::cout <<
"Solution " << k++ << std::endl;
254 std::cout <<
"Rotation: aRb" << std::endl;
255 std::cout << aRb << std::endl;
256 std::cout <<
"Translation: aTb" << std::endl;
257 std::cout << (aTb).t() << std::endl;
258 std::cout <<
"Normal to the plane: n" << std::endl;
259 std::cout << (n).t() << std::endl;
267 std::cout <<
"Catch an exception: " << e << std::endl;