41 #include <visp3/core/vpConfig.h> 43 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020301) 45 #include <opencv2/core/core.hpp> 46 #include <opencv2/features2d/features2d.hpp> 47 #include <visp3/core/vpImage.h> 48 #include <visp3/io/vpImageIo.h> 49 #include <visp3/gui/vpDisplayX.h> 50 #include <visp3/gui/vpDisplayGTK.h> 51 #include <visp3/gui/vpDisplayGDI.h> 52 #include <visp3/gui/vpDisplayOpenCV.h> 53 #include <visp3/io/vpVideoReader.h> 54 #include <visp3/core/vpIoTools.h> 55 #include <visp3/io/vpParseArgv.h> 58 #define GETOPTARGS "cdh" 60 void usage(
const char *name,
const char *badparam);
61 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 automate the \n\ 83 execution of this program without human 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;
140 int main(
int argc,
const char ** argv) {
142 std::string env_ipath;
143 bool opt_click_allowed =
true;
144 bool opt_display =
true;
147 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
154 if(env_ipath.empty()) {
155 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment variable value." << std::endl;
170 cv::Ptr<cv::FeatureDetector> detector;
171 cv::Ptr<cv::DescriptorExtractor> extractor;
172 cv::Ptr<cv::DescriptorMatcher> matcher;
174 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) 175 detector = cv::ORB::create();
176 extractor = cv::ORB::create();
178 detector = cv::FeatureDetector::create(
"ORB");
179 extractor = cv::DescriptorExtractor::create(
"ORB");
181 matcher = cv::DescriptorMatcher::create(
"BruteForce-Hamming");
183 std::vector<cv::KeyPoint> trainKeyPoints;
184 cv::Mat matImg, trainDescriptors;
186 detector->detect(matImg, trainKeyPoints);
187 extractor->compute(matImg, trainKeyPoints, trainDescriptors);
197 #if defined VISP_HAVE_X11 199 #elif defined VISP_HAVE_GTK 201 #elif defined VISP_HAVE_GDI 208 display.
init(Imatch, 0, 0,
"ORB keypoints matching");
211 bool opt_click =
false;
222 std::vector<cv::KeyPoint> queryKeyPoints;
223 detector->detect(matImg, queryKeyPoints);
225 cv::Mat queryDescriptors;
226 extractor->compute(matImg, queryKeyPoints, queryDescriptors);
228 std::vector<std::vector<cv::DMatch> > knn_matches;
229 std::vector<cv::DMatch> matches;
230 matcher->knnMatch(queryDescriptors, trainDescriptors, knn_matches, 2);
231 for(std::vector<std::vector<cv::DMatch> >::const_iterator it = knn_matches.begin(); it != knn_matches.end(); ++it) {
233 double ratio = (*it)[0].distance / (*it)[1].distance;
235 matches.push_back((*it)[0]);
241 for(std::vector<cv::DMatch>::const_iterator it = matches.begin(); it != matches.end(); ++it) {
242 vpImagePoint leftPt(trainKeyPoints[(
size_t) it->trainIdx].pt.y, trainKeyPoints[(
size_t) it->trainIdx].pt.x);
243 vpImagePoint rightPt(queryKeyPoints[(
size_t) it->queryIdx].pt.y, queryKeyPoints[(
size_t) it->queryIdx].pt.x
252 if (opt_click_allowed && opt_display) {
273 std::cerr << e.
what() << std::endl;
277 std::cout <<
"testKeyPoint-3 is ok !" << std::endl;
282 std::cerr <<
"You need OpenCV library." << std::endl;
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Display for windows using GDI (available on any windows 32 platform).
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...
error that can be emited by ViSP classes.
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void open(vpImage< vpRGBa > &I)
const char * what() const
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void acquire(vpImage< vpRGBa > &I)
void resize(const unsigned int h, const unsigned int w)
set the size of the image without initializing it.
void setFileName(const char *filename)
void insert(const vpImage< Type > &src, const vpImagePoint topLeft)
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 ...
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
static void read(vpImage< unsigned char > &I, const char *filename)