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;
150 template<
typename Type>
151 void run_test(
const std::string &env_ipath,
bool opt_click_allowed,
bool opt_display,
bool use_parallel_ransac,
162 #if defined VISP_HAVE_X11 164 #elif defined VISP_HAVE_GTK 166 #elif defined VISP_HAVE_GDI 174 display.
init(I, 0, 0,
"ORB keypoints matching and pose estimation");
212 if (opt_display && opt_click_allowed) {
215 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
224 vpKeyPoint keypoints(
"ORB",
"ORB",
"BruteForce-Hamming");
225 keypoints.setRansacParallel(use_parallel_ransac);
226 #if (VISP_HAVE_OPENCV_VERSION >= 0x020400) 229 keypoints.setMatcher(
"FlannBased");
230 #if (VISP_HAVE_OPENCV_VERSION < 0x030000) 231 keypoints.setDetectorParameter(
"ORB",
"nLevels", 1);
233 cv::Ptr<cv::ORB> orb_detector = keypoints.getDetector(
"ORB").dynamicCast<cv::ORB>();
235 orb_detector->setNLevels(1);
241 std::vector<cv::KeyPoint> trainKeyPoints;
243 keypoints.detect(I, trainKeyPoints, elapsedTime);
246 std::vector<vpPolygon> polygons;
247 std::vector<std::vector<vpPoint> > roisPt;
248 std::pair<std::vector<vpPolygon>, std::vector<std::vector<vpPoint> > > pair =
250 polygons = pair.first;
251 roisPt = pair.second;
254 std::vector<cv::Point3f> points3f;
258 keypoints.buildReference(I, trainKeyPoints, points3f,
false, 1);
265 cMo.
buildFrom(0.02651282185, -0.03713587374, 0.6873765919, 2.314744454, 0.3492296488, -0.1226054828);
269 keypoints.detect(I, trainKeyPoints, elapsedTime);
274 polygons = pair.first;
275 roisPt = pair.second;
281 keypoints.buildReference(I, trainKeyPoints, points3f,
true, 2);
288 cMo.
buildFrom(0.02965448956, -0.07283091786, 0.7253526051, 2.300529617, -0.4286674806, 0.1788761025);
292 keypoints.detect(I, trainKeyPoints, elapsedTime);
296 polygons = pair.first;
297 roisPt = pair.second;
303 keypoints.buildReference(I, trainKeyPoints, points3f,
true, 3);
311 #if defined VISP_HAVE_X11 313 #elif defined VISP_HAVE_GTK 315 #elif defined VISP_HAVE_GDI 321 keypoints.createImageMatching(I, IMatching);
328 bool opt_click =
false;
331 std::vector<double> times_vec;
332 while ((opt_display && !g.
end()) || (!opt_display && g.
getFrameIndex() < 30)) {
339 keypoints.insertImageMatching(I, IMatching);
345 if (keypoints.matchPoint(I, cam, cMo, error, elapsedTime)) {
346 times_vec.push_back(elapsedTime);
355 std::vector<vpImagePoint> ransacInliers = keypoints.getRansacInliers();
356 std::vector<vpImagePoint> ransacOutliers = keypoints.getRansacOutliers();
358 for (std::vector<vpImagePoint>::const_iterator it = ransacInliers.begin(); it != ransacInliers.end(); ++it) {
361 imPt.set_u(imPt.get_u() + I.
getWidth());
362 imPt.set_v(imPt.get_v() + I.
getHeight());
366 for (std::vector<vpImagePoint>::const_iterator it = ransacOutliers.begin(); it != ransacOutliers.end();
370 imPt.set_u(imPt.get_u() + I.
getWidth());
371 imPt.set_v(imPt.get_v() + I.
getHeight());
375 keypoints.displayMatching(I, IMatching);
382 tracker.
setPose(IMatching, cMo);
393 if (opt_click_allowed && opt_display) {
413 if (!times_vec.empty()) {
425 int main(
int argc,
const char **argv)
428 std::string env_ipath;
429 bool opt_click_allowed =
true;
430 bool opt_display =
true;
431 bool use_parallel_ransac =
false;
434 if (getOptions(argc, argv, opt_click_allowed, opt_display, use_parallel_ransac) ==
false) {
442 if (env_ipath.empty()) {
443 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment " 452 std::cout <<
"-- Test on gray level images" << std::endl;
454 run_test(env_ipath, opt_click_allowed, opt_display, use_parallel_ransac, I, IMatching);
459 std::cout <<
"-- Test on color images" << std::endl;
461 run_test(env_ipath, opt_click_allowed, opt_display, use_parallel_ransac, I, IMatching);
465 std::cerr << e.
what() << std::endl;
469 std::cout <<
"testKeyPoint-2 is ok !" << std::endl;
475 std::cerr <<
"You need OpenCV library." << std::endl;
virtual std::pair< std::vector< vpPolygon >, std::vector< std::vector< vpPoint > > > getPolygonFaces(bool orderPolygons=true, bool useVisibility=true, bool clipPolygon=false)
void setMovingEdge(const vpMe &me)
long getFrameIndex() const
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
unsigned int getWidth() const
virtual unsigned int getClipping() const
virtual void setAngleDisappear(const double &a)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setMaskNumber(const unsigned int &a)
virtual void setDownScalingFactor(unsigned int scale)
static double getMedian(const std::vector< double > &v)
Display for windows using GDI (available on any windows 32 platform).
void setSampleStep(const double &s)
static double getStdev(const std::vector< double > &v, bool useBesselCorrection=false)
void setNbTotalSample(const int &nb)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, bool displayHelp=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
static const vpColor none
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Make the complete tracking of an object by using its CAD model.
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
void setMu1(const double &mu_1)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
virtual void setNearClippingDistance(const double &dist)
void open(vpImage< vpRGBa > &I)
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=NULL)
static double getMean(const std::vector< double > &v)
const char * what() const
void setMaskSize(const unsigned int &a)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Generic class defining intrinsic camera parameters.
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
void acquire(vpImage< vpRGBa > &I)
virtual void setFarClippingDistance(const double &dist)
virtual void setAngleAppear(const double &a)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
virtual void getCameraParameters(vpCameraParameters &cam) const
static void displayCircle(const vpImage< unsigned char > &I, const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
void setMu2(const double &mu_2)
virtual void loadConfigFile(const std::string &configFile, bool verbose=true)
virtual void getPose(vpHomogeneousMatrix &cMo) const
static void read(vpImage< unsigned char > &I, const std::string &filename)
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))
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
unsigned int getDownScalingFactor()
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
void setThreshold(const double &t)
void setFileName(const std::string &filename)
unsigned int getHeight() const
virtual void setCameraParameters(const vpCameraParameters &cam)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void setRange(const unsigned int &r)
virtual void setClipping(const unsigned int &flags)
Definition of the vpImage class member functions.