40 #include <visp3/core/vpConfig.h>
42 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020301)
44 #include <visp3/vision/vpKeyPoint.h>
45 #include <visp3/core/vpImage.h>
46 #include <visp3/io/vpImageIo.h>
47 #include <visp3/gui/vpDisplayX.h>
48 #include <visp3/gui/vpDisplayGTK.h>
49 #include <visp3/gui/vpDisplayGDI.h>
50 #include <visp3/gui/vpDisplayOpenCV.h>
51 #include <visp3/io/vpVideoReader.h>
52 #include <visp3/core/vpIoTools.h>
53 #include <visp3/mbt/vpMbEdgeTracker.h>
54 #include <visp3/io/vpParseArgv.h>
57 #define GETOPTARGS "cdh"
59 void usage(
const char *name,
const char *badparam);
60 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
70 void usage(
const char *name,
const char *badparam)
73 Test keypoints matching.\n\
76 %s [-c] [-d] [-h]\n", name);
82 Disable the mouse click. Useful to automaze the \n\
83 execution of this program without humain intervention.\n\
86 Turn off the display.\n\
92 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
106 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
113 case 'c': click_allowed =
false;
break;
114 case 'd': display =
false;
break;
115 case 'h': usage(argv[0], NULL);
return false;
break;
118 usage(argv[0], optarg_);
123 if ((c == 1) || (c == -1)) {
125 usage(argv[0], NULL);
126 std::cerr <<
"ERROR: " << std::endl;
127 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
139 int main(
int argc,
const char ** argv) {
141 std::string env_ipath;
142 bool opt_click_allowed =
true;
143 bool opt_display =
true;
146 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
153 if(env_ipath.empty()) {
154 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment variable value." << std::endl;
168 #if defined VISP_HAVE_X11
170 #elif defined VISP_HAVE_GTK
172 #elif defined VISP_HAVE_GDI
179 display.
init(I, 0, 0,
"ORB keypoints matching and pose estimation");
188 #ifdef VISP_HAVE_XML2
221 if (opt_display && opt_click_allowed) {
226 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
235 vpKeyPoint keypoints(
"ORB",
"ORB",
"BruteForce-Hamming");
236 #if (VISP_HAVE_OPENCV_VERSION >= 0x020400)
239 keypoints.setMatcher(
"FlannBased");
240 #if (VISP_HAVE_OPENCV_VERSION < 0x030000)
241 keypoints.setDetectorParameter(
"ORB",
"nLevels", 1);
243 cv::Ptr<cv::ORB> orb_detector = keypoints.getDetector(
"ORB").dynamicCast<cv::ORB>();
244 if(orb_detector != NULL) {
245 orb_detector->setNLevels(1);
251 std::vector<cv::KeyPoint> trainKeyPoints;
253 keypoints.detect(I, trainKeyPoints, elapsedTime);
256 std::vector<vpPolygon> polygons;
257 std::vector<std::vector<vpPoint> > roisPt;
258 std::pair<std::vector<vpPolygon>, std::vector<std::vector<vpPoint> > > pair = tracker.
getPolygonFaces(
false);
259 polygons = pair.first;
260 roisPt = pair.second;
263 std::vector<cv::Point3f> points3f;
267 keypoints.buildReference(I, trainKeyPoints, points3f,
false, 1);
275 cMo.
buildFrom(0.02651282185, -0.03713587374, 0.6873765919, 2.314744454, 0.3492296488, -0.1226054828);
279 keypoints.detect(I, trainKeyPoints, elapsedTime);
283 polygons = pair.first;
284 roisPt = pair.second;
290 keypoints.buildReference(I, trainKeyPoints, points3f,
true, 2);
298 cMo.
buildFrom(0.02965448956, -0.07283091786, 0.7253526051, 2.300529617, -0.4286674806, 0.1788761025);
302 keypoints.detect(I, trainKeyPoints, elapsedTime);
306 polygons = pair.first;
307 roisPt = pair.second;
313 keypoints.buildReference(I, trainKeyPoints, points3f,
true, 3);
322 #if defined VISP_HAVE_X11
324 #elif defined VISP_HAVE_GTK
326 #elif defined VISP_HAVE_GDI
334 keypoints.createImageMatching(I, IMatching);
337 display2.
init(IMatching, 0, (
int)I.
getHeight() + 80,
"IMatching");
340 bool opt_click =
false;
343 while((opt_display && !g.
end()) || (!opt_display && g.
getFrameIndex() < 30)) {
350 keypoints.insertImageMatching(I, IMatching);
356 if(keypoints.matchPoint(I, cam, cMo, error, elapsedTime)) {
364 std::vector<vpImagePoint> ransacInliers = keypoints.getRansacInliers();
365 std::vector<vpImagePoint> ransacOutliers = keypoints.getRansacOutliers();
367 for(std::vector<vpImagePoint>::const_iterator it = ransacInliers.begin(); it != ransacInliers.end(); ++it) {
370 imPt.set_u(imPt.get_u() + I.
getWidth());
371 imPt.set_v(imPt.get_v() + I.
getHeight());
375 for(std::vector<vpImagePoint>::const_iterator it = ransacOutliers.begin(); it != ransacOutliers.end(); ++it) {
378 imPt.set_u(imPt.get_u() + I.
getWidth());
379 imPt.set_v(imPt.get_v() + I.
getHeight());
383 keypoints.displayMatching(I, IMatching);
390 tracker.
setPose(IMatching, cMo);
401 if (opt_click_allowed && opt_display) {
423 std::cerr << e.
what() << std::endl;
427 std::cout <<
"testKeyPoint-2 is ok !" << std::endl;
432 std::cerr <<
"You need OpenCV library." << std::endl;
virtual void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void setMovingEdge(const vpMe &me)
long getFrameIndex() const
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)
Display for windows using GDI (available on any windows 32 platform).
void setSampleStep(const double &s)
void setNbTotalSample(const int &nb)
Define the X11 console to display images.
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.
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 setCameraParameters(const vpCameraParameters &camera)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
void loadConfigFile(const std::string &configFile)
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)
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
virtual void setNearClippingDistance(const double &dist)
void open(vpImage< vpRGBa > &I)
const char * what() const
void setMaskSize(const unsigned int &a)
void getPose(vpHomogeneousMatrix &cMo_) const
static void compute3DForPointsInPolygons(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, std::vector< cv::KeyPoint > &candidate, const std::vector< vpPolygon > &polygons, const std::vector< std::vector< vpPoint > > &roisPt, std::vector< cv::Point3f > &points, cv::Mat *descriptors=NULL)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
virtual void getCameraParameters(vpCameraParameters &camera) const
Generic class defining intrinsic camera parameters.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void acquire(vpImage< vpRGBa > &I)
virtual void setFarClippingDistance(const double &dist)
void setFileName(const char *filename)
virtual void setAngleAppear(const double &a)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, const bool displayHelp=false)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
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, vpImagePoint offset=vpImagePoint(0, 0))
void setMu2(const double &mu_2)
virtual void loadModel(const char *modelFile, const bool verbose=false)
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
void setThreshold(const double &t)
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)
unsigned int getHeight() const
virtual bool getClick(bool blocking=true)=0
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)
static void read(vpImage< unsigned char > &I, const char *filename)
virtual std::pair< std::vector< vpPolygon >, std::vector< std::vector< vpPoint > > > getPolygonFaces(const bool orderPolygons=true, const bool useVisibility=true)