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/vision/vpKeyPoint.h>
56 #define GETOPTARGS "cdh"
58 void usage(
const char *name,
const char *badparam);
59 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
67 void usage(
const char *name,
const char *badparam)
70 Test keypoint descriptor extraction.\n\
73 %s [-c] [-d] [-h]\n", name);
79 Disable the mouse click. Useful to automaze the \n\
80 execution of this program without humain intervention.\n\
83 Turn off the display.\n\
89 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
103 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
111 click_allowed =
false;
117 usage(argv[0], NULL);
122 usage(argv[0], optarg_);
128 if ((c == 1) || (c == -1)) {
130 usage(argv[0], NULL);
131 std::cerr <<
"ERROR: " << std::endl;
132 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
147 std::string getOpenCVType(
const int type)
149 std::string type_string =
"";
153 type_string =
"CV_8U";
157 type_string =
"CV_8S";
161 type_string =
"CV_16U";
165 type_string =
"CV_16S";
169 type_string =
"CV_32S";
173 type_string =
"CV_32F";
177 type_string =
"CV_64F";
181 type_string =
"Problem with type !";
193 int main(
int argc,
const char **argv)
196 std::string env_ipath;
197 bool opt_click_allowed =
true;
198 bool opt_display =
true;
201 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
209 if (env_ipath.empty()) {
210 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment "
226 #if defined VISP_HAVE_X11
228 #elif defined VISP_HAVE_GTK
230 #elif defined VISP_HAVE_GDI
237 display.init(I, 0, 0,
"KeyPoints detection.");
242 std::vector<std::string> descriptorNames;
243 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
244 descriptorNames.push_back(
"SIFT");
245 descriptorNames.push_back(
"SURF");
247 descriptorNames.push_back(
"ORB");
248 #if (VISP_HAVE_OPENCV_VERSION >= 0x020403)
249 descriptorNames.push_back(
"BRISK");
251 #if defined(VISP_HAVE_OPENCV_XFEATURES2D) || (VISP_HAVE_OPENCV_VERSION < 0x030000)
252 descriptorNames.push_back(
"BRIEF");
253 #if (VISP_HAVE_OPENCV_VERSION >= 0x020402)
254 descriptorNames.push_back(
"FREAK");
257 #if defined(VISP_HAVE_OPENCV_XFEATURES2D)
258 descriptorNames.push_back(
"DAISY");
259 descriptorNames.push_back(
"LATCH");
261 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
262 descriptorNames.push_back(
"VGG");
263 descriptorNames.push_back(
"BoostDesc");
265 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
266 descriptorNames.push_back(
"KAZE");
267 descriptorNames.push_back(
"AKAZE");
270 std::string detectorName =
"FAST";
272 std::vector<cv::KeyPoint> kpts;
274 keyPoints.
detect(I, kpts);
275 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
277 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
281 for (std::vector<std::string>::const_iterator itd = descriptorNames.begin(); itd != descriptorNames.end(); ++itd) {
284 if (*itd ==
"KAZE") {
285 detectorName =
"KAZE";
287 keyPoints.
detect(I, kpts);
288 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
290 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
293 }
else if (*itd ==
"AKAZE") {
294 detectorName =
"AKAZE";
296 keyPoints.
detect(I, kpts);
297 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
299 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
302 }
else if (*itd ==
"BoostDesc") {
303 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
304 cv::Ptr<cv::Feature2D> boostDesc = keyPoints.
getExtractor(
"BoostDesc");
306 boostDesc = cv::xfeatures2d::BoostDesc::create(cv::xfeatures2d::BoostDesc::BINBOOST_256,
true, 5.0f);
312 keyPoints.
extract(I, kpts, descriptor);
315 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols
316 <<
" (rows x cols) ; type=" << getOpenCVType(descriptor.type()) <<
" for " << *itd <<
" method in " << t
317 <<
" ms." << std::endl;
318 if (descriptor.empty()) {
319 std::cerr <<
"No descriptor extracted with " << *itd <<
" and image:" << filename <<
"." << std::endl;
326 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
328 imPt.
set_uv(it->pt.x, it->pt.y);
335 if (opt_click_allowed) {
343 std::map<vpKeyPoint::vpFeatureDescriptorType, std::string> mapOfDescriptorNames = keyPoints.
getExtractorNames();
349 detectorName =
"KAZE";
351 keyPoints.
detect(I, kpts);
352 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
354 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
358 detectorName =
"AKAZE";
360 keyPoints.
detect(I, kpts);
361 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
363 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
367 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
368 detectorName =
"FAST";
370 keyPoints.
detect(I, kpts);
371 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
373 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
377 cv::Ptr<cv::Feature2D> boostDesc = keyPoints.
getExtractor(
"BoostDesc");
379 boostDesc = cv::xfeatures2d::BoostDesc::create(cv::xfeatures2d::BoostDesc::BINBOOST_256,
true, 5.0f);
385 keyPoints.
extract(I, kpts, descriptor);
388 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols
389 <<
" (rows x cols) ; type=" << getOpenCVType(descriptor.type()) <<
" for "
392 if (descriptor.empty()) {
394 <<
" and image:" << filename <<
"." << std::endl;
401 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
403 imPt.
set_uv(it->pt.x, it->pt.y);
410 if (opt_click_allowed) {
417 std::cerr << e.
what() << std::endl;
421 std::cout <<
"testKeyPoint-6 is ok !" << std::endl;
429 std::cerr <<
"You need OpenCV library." << std::endl;