50#include <visp3/core/vpConfig.h>
51#include <visp3/core/vpDebug.h>
52#include <visp3/core/vpMath.h>
53#include <visp3/core/vpRotationMatrix.h>
54#include <visp3/core/vpThetaUVector.h>
55#include <visp3/vision/vpHomography.h>
57#include <visp3/core/vpDebug.h>
58#include <visp3/core/vpHomogeneousMatrix.h>
59#include <visp3/core/vpMath.h>
60#include <visp3/core/vpPoint.h>
63#include <visp3/core/vpRansac.h>
64#include <visp3/io/vpParseArgv.h>
68#ifdef ENABLE_VISP_NAMESPACE
72void usage(
const char *name,
const char *badparam);
73bool getOptions(
int argc,
const char **argv);
83void usage(
const char *name,
const char *badparam)
86Test the Ransac homography estimation algorithm.\n\
98 fprintf(stderr,
"ERROR: \n");
99 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
112bool getOptions(
int argc,
const char **argv)
120 usage(argv[0],
nullptr);
124 usage(argv[0], optarg_);
129 if ((c == 1) || (c == -1)) {
131 usage(argv[0],
nullptr);
132 std::cerr <<
"ERROR: " << std::endl;
133 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
140int main(
int argc,
const char **argv)
142#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
145 if (getOptions(argc, argv) ==
false) {
150 unsigned int nbpt = 11;
152 std::vector<vpPoint> P(nbpt);
153 std::vector<double> xa(nbpt), ya(nbpt), xb(nbpt), yb(nbpt);
155 P[0].setWorldCoordinates(-L, -L, 0);
156 P[1].setWorldCoordinates(2 * L, -L, 0);
157 P[2].setWorldCoordinates(L, L, 0);
158 P[3].setWorldCoordinates(-L, 3 * L, 0);
159 P[4].setWorldCoordinates(0, 0, L);
160 P[5].setWorldCoordinates(L, -2 * L, L);
161 P[6].setWorldCoordinates(L, -4 * L, 2 * L);
162 P[7].setWorldCoordinates(-2 * L, -L, -3 * L);
163 P[8].setWorldCoordinates(-5 * L, -5 * L, 0);
164 P[9].setWorldCoordinates(-2 * L, +3 * L, 4 * L);
165 P[10].setWorldCoordinates(-2 * L, -0.5 * L, 0);
167 std::vector<bool> inliers_ground_truth(nbpt,
false);
168 inliers_ground_truth[0] =
true;
169 inliers_ground_truth[1] =
true;
170 inliers_ground_truth[2] =
true;
171 inliers_ground_truth[3] =
true;
172 inliers_ground_truth[8] =
true;
173 inliers_ground_truth[10] =
true;
178 for (
unsigned int i = 0;
i < nbpt;
i++) {
180 xa[
i] = P[
i].get_x();
181 ya[
i] = P[
i].get_y();
184 for (
unsigned int i = 0;
i < nbpt;
i++) {
186 xb[
i] = P[
i].get_x();
187 yb[
i] = P[
i].get_y();
189 std::cout <<
"-------------------------------" << std::endl;
194 std::cout <<
"Compare with built homography H = R + t/d n " << std::endl;
197 std::cout <<
"aHb built from the displacement: \n" << aHb_built / aHb_built[2][2] << std::endl;
199 aHb_built.computeDisplacement(aRb, aTb, n);
200 std::cout <<
"Rotation aRb: " << std::endl;
201 std::cout << aRb << std::endl;
202 std::cout <<
"Translation: aTb" << std::endl;
203 std::cout << (aTb).
t() << std::endl;
204 std::cout <<
"Normal to the plane: n" << std::endl;
205 std::cout << (n).
t() << std::endl;
207 std::cout <<
"-------------------------------" << std::endl;
209 std::vector<bool> inliers;
215 std::cout <<
"aHb estimated using ransac:\n" << aHb << std::endl;
216 std::cout <<
"Inliers indexes (should be 0,1,2,3,8,10): ";
217 for (
unsigned int i = 0;
i < inliers.size();
i++)
219 std::cout <<
i <<
",";
220 std::cout << std::endl;
222 if (inliers == inliers_ground_truth) {
223 std::cout <<
"Ransac estimation succeed" << std::endl;
227 std::cout <<
"Ransac estimation fails" << std::endl;
232 std::cout <<
"Catch an exception: " <<
e << std::endl;
238 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
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.
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 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.
Implementation of a rotation matrix and operations on such kind of matrices.
Class that consider the case of a translation vector.