36 #include <visp3/core/vpConfig.h>
38 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_FEATURES2D) && defined(HAVE_OPENCV_VIDEO)
40 #include <visp3/core/vpImage.h>
41 #include <visp3/core/vpIoTools.h>
42 #include <visp3/gui/vpDisplayGDI.h>
43 #include <visp3/gui/vpDisplayGTK.h>
44 #include <visp3/gui/vpDisplayOpenCV.h>
45 #include <visp3/gui/vpDisplayX.h>
46 #include <visp3/io/vpImageIo.h>
47 #include <visp3/io/vpParseArgv.h>
48 #include <visp3/io/vpVideoReader.h>
49 #include <visp3/mbt/vpMbEdgeTracker.h>
50 #include <visp3/vision/vpKeyPoint.h>
53 #define GETOPTARGS "cdph"
55 void usage(
const char *name,
const char *badparam);
56 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
66 void usage(
const char *name,
const char *badparam)
69 Test keypoints matching.\n\
72 %s [-c] [-d] [-p] [-h]\n",
79 Disable the mouse click. Useful to automate the \n\
80 execution of this program without human intervention.\n\
83 Turn off the display.\n\
86 Use parallel RANSAC.\n\
92 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
106 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display,
bool &use_parallel_ransac)
114 click_allowed =
false;
120 use_parallel_ransac =
true;
123 usage(argv[0],
nullptr);
128 usage(argv[0], optarg_);
134 if ((c == 1) || (c == -1)) {
136 usage(argv[0],
nullptr);
137 std::cerr <<
"ERROR: " << std::endl;
138 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
145 template <
typename Type>
146 void run_test(
const std::string &env_ipath,
bool opt_click_allowed,
bool opt_display,
bool use_parallel_ransac,
149 #if VISP_HAVE_DATASET_VERSION >= 0x030600
150 std::string ext(
"png");
152 std::string ext(
"pgm");
162 #if defined(VISP_HAVE_X11)
164 #elif defined(VISP_HAVE_GTK)
166 #elif defined(VISP_HAVE_GDI)
168 #elif defined(HAVE_OPENCV_HIGHGUI)
174 display.init(I, 0, 0,
"ORB keypoints matching and pose estimation");
182 #if defined(VISP_HAVE_PUGYXML)
214 if (opt_display && opt_click_allowed) {
218 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
227 vpKeyPoint keypoints(
"ORB",
"ORB",
"BruteForce-Hamming");
228 keypoints.setRansacParallel(use_parallel_ransac);
229 #if (VISP_HAVE_OPENCV_VERSION >= 0x020400)
232 keypoints.setMatcher(
"FlannBased");
233 #if (VISP_HAVE_OPENCV_VERSION < 0x030000)
234 keypoints.setDetectorParameter(
"ORB",
"nLevels", 1);
236 cv::Ptr<cv::ORB> orb_detector = keypoints.getDetector(
"ORB").dynamicCast<cv::ORB>();
238 orb_detector->setNLevels(1);
244 std::vector<cv::KeyPoint> trainKeyPoints;
246 keypoints.detect(I, trainKeyPoints, elapsedTime);
249 std::vector<vpPolygon> polygons;
250 std::vector<std::vector<vpPoint> > roisPt;
251 std::pair<std::vector<vpPolygon>, std::vector<std::vector<vpPoint> > > pair =
253 polygons = pair.first;
254 roisPt = pair.second;
257 std::vector<cv::Point3f> points3f;
261 keypoints.buildReference(I, trainKeyPoints, points3f,
false, 1);
268 cMo.
buildFrom(0.02651282185, -0.03713587374, 0.6873765919, 2.314744454, 0.3492296488, -0.1226054828);
272 keypoints.detect(I, trainKeyPoints, elapsedTime);
277 polygons = pair.first;
278 roisPt = pair.second;
284 keypoints.buildReference(I, trainKeyPoints, points3f,
true, 2);
291 cMo.
buildFrom(0.02965448956, -0.07283091786, 0.7253526051, 2.300529617, -0.4286674806, 0.1788761025);
295 keypoints.detect(I, trainKeyPoints, elapsedTime);
299 polygons = pair.first;
300 roisPt = pair.second;
306 keypoints.buildReference(I, trainKeyPoints, points3f,
true, 3);
314 #if defined(VISP_HAVE_X11)
316 #elif defined(VISP_HAVE_GTK)
318 #elif defined(VISP_HAVE_GDI)
320 #elif defined(HAVE_OPENCV_HIGHGUI)
324 keypoints.createImageMatching(I, IMatching);
331 bool opt_click =
false;
334 std::vector<double> times_vec;
335 while ((opt_display && !g.
end()) || (!opt_display && g.
getFrameIndex() < 30)) {
342 keypoints.insertImageMatching(I, IMatching);
348 if (keypoints.matchPoint(I, cam, cMo, error, elapsedTime)) {
349 times_vec.push_back(elapsedTime);
358 std::vector<vpImagePoint> ransacInliers = keypoints.getRansacInliers();
359 std::vector<vpImagePoint> ransacOutliers = keypoints.getRansacOutliers();
361 for (std::vector<vpImagePoint>::const_iterator it = ransacInliers.begin(); it != ransacInliers.end(); ++it) {
364 imPt.set_u(imPt.get_u() + I.
getWidth());
365 imPt.set_v(imPt.get_v() + I.
getHeight());
369 for (std::vector<vpImagePoint>::const_iterator it = ransacOutliers.begin(); it != ransacOutliers.end(); ++it) {
372 imPt.set_u(imPt.get_u() + I.
getWidth());
373 imPt.set_v(imPt.get_v() + I.
getHeight());
377 keypoints.displayMatching(I, IMatching);
384 tracker.
setPose(IMatching, cMo);
395 if (opt_click_allowed && opt_display) {
417 if (!times_vec.empty()) {
429 int main(
int argc,
const char **argv)
432 std::string env_ipath;
433 bool opt_click_allowed =
true;
434 bool opt_display =
true;
435 bool use_parallel_ransac =
false;
438 if (getOptions(argc, argv, opt_click_allowed, opt_display, use_parallel_ransac) ==
false) {
446 if (env_ipath.empty()) {
447 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment "
456 std::cout <<
"-- Test on gray level images" << std::endl;
458 run_test(env_ipath, opt_click_allowed, opt_display, use_parallel_ransac, I, IMatching);
463 std::cout <<
"-- Test on color images" << std::endl;
465 run_test(env_ipath, opt_click_allowed, opt_display, use_parallel_ransac, I, IMatching);
470 std::cerr << e.
what() << std::endl;
474 std::cout <<
"testKeyPoint-2 is ok !" << std::endl;
480 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
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="") vp_override
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.
const char * what() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
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.
unsigned int getWidth() const
unsigned int getHeight() const
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
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.
virtual void setNearClippingDistance(const double &dist) vp_override
virtual void setFarClippingDistance(const double &dist) vp_override
virtual void loadConfigFile(const std::string &configFile, bool verbose=true) vp_override
virtual void setClipping(const unsigned int &flags) vp_override
virtual void setCameraParameters(const vpCameraParameters &cam) vp_override
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false) vp_override
void setMovingEdge(const vpMe &me)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) vp_override
virtual void getCameraParameters(vpCameraParameters &cam) const
virtual void getPose(vpHomogeneousMatrix &cMo) const
virtual void setAngleDisappear(const double &a)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, bool displayHelp=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void setAngleAppear(const double &a)
virtual std::pair< std::vector< vpPolygon >, std::vector< std::vector< vpPoint > > > getPolygonFaces(bool orderPolygons=true, bool useVisibility=true, bool clipPolygon=false)
virtual unsigned int getClipping() const
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 acquire(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
long getFrameIndex() const
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.