42#include <visp3/core/vpConfig.h>
44#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) && \
45 (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_CALIB3D) && defined(HAVE_OPENCV_FEATURES2D)) || \
46 ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_3D) && defined(HAVE_OPENCV_FEATURES)))
48#include <visp3/core/vpImage.h>
49#include <visp3/core/vpIoTools.h>
50#include <visp3/gui/vpDisplayFactory.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#ifdef ENABLE_VISP_NAMESPACE
64void usage(
const char *name,
const char *badparam);
65bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display,
bool &use_parallel_ransac);
75void usage(
const char *name,
const char *badparam)
78Test keypoints matching.\n\
81 %s [-c] [-d] [-p] [-h]\n",
88 Disable the mouse click. Useful to automate the \n\
89 execution of this program without human intervention.\n\
92 Turn off the display.\n\
95 Use parallel RANSAC.\n\
101 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
115bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display,
bool &use_parallel_ransac)
123 click_allowed =
false;
129 use_parallel_ransac =
true;
132 usage(argv[0],
nullptr);
136 usage(argv[0], optarg_);
141 if ((c == 1) || (c == -1)) {
143 usage(argv[0],
nullptr);
144 std::cerr <<
"ERROR: " << std::endl;
145 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
152template <
typename Type>
153void run_test(
const std::string &env_ipath,
bool opt_click_allowed,
bool opt_display,
bool use_parallel_ransac,
156#if defined(VISP_HAVE_DATASET)
157#if VISP_HAVE_DATASET_VERSION >= 0x030600
158 std::string ext(
"png");
160 std::string ext(
"pgm");
164 std::string ext(
"png");
177#ifdef VISP_HAVE_DISPLAY
181 std::cout <<
"No image viewer is available..." << std::endl;
190#if defined(VISP_HAVE_PUGIXML)
191 tracker.loadConfigFile(tracker_config_file);
192 tracker.getCameraParameters(cam);
206 cam.initPersProjWithoutDistortion(547.7367575, 542.0744058, 338.7036994, 234.5083345);
207 tracker.setCameraParameters(cam);
208 tracker.setNearClippingDistance(0.01);
209 tracker.setFarClippingDistance(100.0);
218 tracker.loadModel(cao_model_file);
222 if (opt_display && opt_click_allowed) {
223 tracker.initClick(I, init_file);
226 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
235 vpKeyPoint keypoints(
"ORB",
"ORB",
"BruteForce-Hamming");
236 keypoints.setRansacParallel(use_parallel_ransac);
237#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020400)
240 keypoints.setMatcher(
"FlannBased");
241#if (VISP_HAVE_OPENCV_VERSION < 0x030000)
242 keypoints.setDetectorParameter(
"ORB",
"nLevels", 1);
244 cv::Ptr<cv::ORB> orb_detector = keypoints.getDetector(
"ORB").dynamicCast<cv::ORB>();
246 orb_detector->setNLevels(1);
252 std::vector<cv::KeyPoint> trainKeyPoints;
254 keypoints.detect(I, trainKeyPoints, elapsedTime);
257 std::vector<vpPolygon> polygons;
258 std::vector<std::vector<vpPoint> > roisPt;
259 std::pair<std::vector<vpPolygon>, std::vector<std::vector<vpPoint> > > pair =
261 polygons = pair.first;
262 roisPt = pair.second;
265 std::vector<cv::Point3f> points3f;
269 keypoints.buildReference(I, trainKeyPoints, points3f,
false, 1);
276 cMo.buildFrom(0.02651282185, -0.03713587374, 0.6873765919, 2.314744454, 0.3492296488, -0.1226054828);
280 keypoints.detect(I, trainKeyPoints, elapsedTime);
283 pair =
tracker.getPolygonFaces(
true,
true,
285 polygons = pair.first;
286 roisPt = pair.second;
292 keypoints.buildReference(I, trainKeyPoints, points3f,
true, 2);
299 cMo.buildFrom(0.02965448956, -0.07283091786, 0.7253526051, 2.300529617, -0.4286674806, 0.1788761025);
303 keypoints.detect(I, trainKeyPoints, elapsedTime);
306 pair =
tracker.getPolygonFaces(
false);
307 polygons = pair.first;
308 roisPt = pair.second;
314 keypoints.buildReference(I, trainKeyPoints, points3f,
true, 3);
324 keypoints.createImageMatching(I, IMatching);
327#ifdef VISP_HAVE_DISPLAY
333 bool opt_click =
false;
336 std::vector<double> times_vec;
337 while ((opt_display && !g.
end()) || (!opt_display && g.
getFrameIndex() < 30)) {
344 keypoints.insertImageMatching(I, IMatching);
350 if (keypoints.matchPoint(I, cam, cMo, error, elapsedTime)) {
351 times_vec.push_back(elapsedTime);
353 tracker.setCameraParameters(cam);
360 std::vector<vpImagePoint> ransacInliers = keypoints.getRansacInliers();
361 std::vector<vpImagePoint> ransacOutliers = keypoints.getRansacOutliers();
363 for (std::vector<vpImagePoint>::const_iterator it = ransacInliers.begin(); it != ransacInliers.end(); ++it) {
366 imPt.set_u(imPt.get_u() + I.getWidth());
367 imPt.set_v(imPt.get_v() + I.getHeight());
371 for (std::vector<vpImagePoint>::const_iterator it = ransacOutliers.begin(); it != ransacOutliers.end(); ++it) {
374 imPt.set_u(imPt.get_u() + I.getWidth());
375 imPt.set_v(imPt.get_v() + I.getHeight());
379 keypoints.displayMatching(I, IMatching);
384 cam.get_v0() + I.getHeight());
385 tracker.setCameraParameters(cam2);
386 tracker.setPose(IMatching, cMo);
397 if (opt_click_allowed && opt_display) {
426 if (!times_vec.empty()) {
433int main(
int argc,
const char **argv)
436 std::string env_ipath;
437 bool opt_click_allowed =
true;
438 bool opt_display =
true;
439 bool use_parallel_ransac =
false;
442 if (getOptions(argc, argv, opt_click_allowed, opt_display, use_parallel_ransac) ==
false) {
450 if (env_ipath.empty()) {
451 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment "
460 std::cout <<
"-- Test on gray level images" << std::endl;
462 run_test(env_ipath, opt_click_allowed, opt_display, use_parallel_ransac, I, IMatching);
467 std::cout <<
"-- Test on color images" << std::endl;
469 run_test(env_ipath, opt_click_allowed, opt_display, use_parallel_ransac, I, IMatching);
474 std::cerr <<
e.what() << std::endl;
478 std::cout <<
"testKeyPoint-2 is ok !" << std::endl;
484 std::cerr <<
"You need OpenCV library." << std::endl;
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
static const vpColor none
static const vpColor green
Class that defines generic functionalities for display.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void displayCircle(const vpImage< unsigned char > &I, const vpImageCircle &circle, const vpColor &color, bool fill=false, unsigned int thickness=1)
virtual void setDownScalingFactor(unsigned int scale)
static void display(const vpImage< unsigned char > &I)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void flush(const vpImage< unsigned char > &I)
unsigned int getDownScalingFactor()
error that can be emitted by ViSP classes.
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
Class that allows keypoints 2D features detection (and descriptors extraction) and matching thanks to...
static void compute3DForPointsInPolygons(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, std::vector< cv::KeyPoint > &candidates, const std::vector< vpPolygon > &polygons, const std::vector< std::vector< vpPoint > > &roisPt, std::vector< cv::Point3f > &points, cv::Mat *descriptors=nullptr)
static double rad(double deg)
static double getMedian(const std::vector< double > &v)
static double getStdev(const std::vector< double > &v, bool useBesselCorrection=false)
static double getMean(const std::vector< double > &v)
Make the complete tracking of an object by using its CAD model.
void setMu1(const double &mu_1)
void setRange(const unsigned int &range)
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
void setNbTotalSample(const int &ntotal_sample)
void setMaskNumber(const unsigned int &mask_number)
void setThreshold(const double &threshold)
void setSampleStep(const double &sample_step)
void setMaskSize(const unsigned int &mask_size)
void setMu2(const double &mu_2)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void open(vpImage< vpRGBa > &I) VP_OVERRIDE
void setFileName(const std::string &filename)
long getFrameIndex() const
void acquire(vpImage< vpRGBa > &I) VP_OVERRIDE
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.