41 #include <visp3/core/vpConfig.h>
43 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020301)
45 #include <visp3/core/vpImage.h>
46 #include <visp3/core/vpIoTools.h>
47 #include <visp3/gui/vpDisplayGDI.h>
48 #include <visp3/gui/vpDisplayGTK.h>
49 #include <visp3/gui/vpDisplayOpenCV.h>
50 #include <visp3/gui/vpDisplayX.h>
51 #include <visp3/io/vpImageIo.h>
52 #include <visp3/io/vpParseArgv.h>
53 #include <visp3/io/vpVideoReader.h>
54 #include <visp3/mbt/vpMbEdgeTracker.h>
55 #include <visp3/vision/vpKeyPoint.h>
58 #define GETOPTARGS "cdph"
60 void usage(
const char *name,
const char *badparam);
61 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
71 void usage(
const char *name,
const char *badparam)
74 Test keypoints matching.\n\
77 %s [-c] [-d] [-p] [-h]\n", name);
83 Disable the mouse click. Useful to automaze the \n\
84 execution of this program without humain intervention.\n\
87 Turn off the display.\n\
90 Use parallel RANSAC.\n\
96 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
110 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display,
111 bool &use_parallel_ransac)
119 click_allowed =
false;
125 use_parallel_ransac =
true;
128 usage(argv[0], NULL);
133 usage(argv[0], optarg_);
139 if ((c == 1) || (c == -1)) {
141 usage(argv[0], NULL);
142 std::cerr <<
"ERROR: " << std::endl;
143 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
155 int main(
int argc,
const char **argv)
158 std::string env_ipath;
159 bool opt_click_allowed =
true;
160 bool opt_display =
true;
161 bool use_parallel_ransac =
false;
164 if (getOptions(argc, argv, opt_click_allowed, opt_display, use_parallel_ransac) ==
false) {
172 if (env_ipath.empty()) {
173 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment "
189 #if defined VISP_HAVE_X11
191 #elif defined VISP_HAVE_GTK
193 #elif defined VISP_HAVE_GDI
201 display.init(I, 0, 0,
"ORB keypoints matching and pose estimation");
209 #ifdef VISP_HAVE_XML2
239 if (opt_display && opt_click_allowed) {
242 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
251 vpKeyPoint keypoints(
"ORB",
"ORB",
"BruteForce-Hamming");
252 keypoints.setRansacParallel(use_parallel_ransac);
253 #if (VISP_HAVE_OPENCV_VERSION >= 0x020400)
256 keypoints.setMatcher(
"FlannBased");
257 #if (VISP_HAVE_OPENCV_VERSION < 0x030000)
258 keypoints.setDetectorParameter(
"ORB",
"nLevels", 1);
260 cv::Ptr<cv::ORB> orb_detector = keypoints.getDetector(
"ORB").dynamicCast<cv::ORB>();
262 orb_detector->setNLevels(1);
268 std::vector<cv::KeyPoint> trainKeyPoints;
270 keypoints.detect(I, trainKeyPoints, elapsedTime);
273 std::vector<vpPolygon> polygons;
274 std::vector<std::vector<vpPoint> > roisPt;
275 std::pair<std::vector<vpPolygon>, std::vector<std::vector<vpPoint> > > pair =
277 polygons = pair.first;
278 roisPt = pair.second;
281 std::vector<cv::Point3f> points3f;
285 keypoints.buildReference(I, trainKeyPoints, points3f,
false, 1);
292 cMo.
buildFrom(0.02651282185, -0.03713587374, 0.6873765919, 2.314744454, 0.3492296488, -0.1226054828);
296 keypoints.detect(I, trainKeyPoints, elapsedTime);
301 polygons = pair.first;
302 roisPt = pair.second;
308 keypoints.buildReference(I, trainKeyPoints, points3f,
true, 2);
315 cMo.
buildFrom(0.02965448956, -0.07283091786, 0.7253526051, 2.300529617, -0.4286674806, 0.1788761025);
319 keypoints.detect(I, trainKeyPoints, elapsedTime);
323 polygons = pair.first;
324 roisPt = pair.second;
330 keypoints.buildReference(I, trainKeyPoints, points3f,
true, 3);
338 #if defined VISP_HAVE_X11
340 #elif defined VISP_HAVE_GTK
342 #elif defined VISP_HAVE_GDI
350 keypoints.createImageMatching(I, IMatching);
357 bool opt_click =
false;
360 std::vector<double> times_vec;
361 while ((opt_display && !g.
end()) || (!opt_display && g.
getFrameIndex() < 30)) {
368 keypoints.insertImageMatching(I, IMatching);
374 if (keypoints.matchPoint(I, cam, cMo, error, elapsedTime)) {
375 times_vec.push_back(elapsedTime);
384 std::vector<vpImagePoint> ransacInliers = keypoints.getRansacInliers();
385 std::vector<vpImagePoint> ransacOutliers = keypoints.getRansacOutliers();
387 for (std::vector<vpImagePoint>::const_iterator it = ransacInliers.begin(); it != ransacInliers.end(); ++it) {
390 imPt.set_u(imPt.get_u() + I.
getWidth());
391 imPt.set_v(imPt.get_v() + I.
getHeight());
395 for (std::vector<vpImagePoint>::const_iterator it = ransacOutliers.begin(); it != ransacOutliers.end();
399 imPt.set_u(imPt.get_u() + I.
getWidth());
400 imPt.set_v(imPt.get_v() + I.
getHeight());
404 keypoints.displayMatching(I, IMatching);
411 tracker.
setPose(IMatching, cMo);
422 if (opt_click_allowed && opt_display) {
442 if (!times_vec.empty()) {
449 std::cerr << e.
what() << std::endl;
453 std::cout <<
"testKeyPoint-2 is ok !" << std::endl;
459 std::cerr <<
"You need OpenCV library." << std::endl;