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/vision/vpKeyPoint.h>
51 #define GETOPTARGS "cdh"
53 void usage(
const char *name,
const char *badparam);
54 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
62 void usage(
const char *name,
const char *badparam)
65 Test keypoint descriptor extraction.\n\
75 Disable the mouse click. Useful to automate the \n\
76 execution of this program without human intervention.\n\
79 Turn off the display.\n\
85 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
99 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
107 click_allowed =
false;
113 usage(argv[0],
nullptr);
118 usage(argv[0], optarg_);
124 if ((c == 1) || (c == -1)) {
126 usage(argv[0],
nullptr);
127 std::cerr <<
"ERROR: " << std::endl;
128 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
143 std::string getOpenCVType(
int type)
145 std::string type_string =
"";
149 type_string =
"CV_8U";
153 type_string =
"CV_8S";
157 type_string =
"CV_16U";
161 type_string =
"CV_16S";
165 type_string =
"CV_32S";
169 type_string =
"CV_32F";
173 type_string =
"CV_64F";
177 type_string =
"Problem with type !";
184 template <
typename Type>
185 void run_test(
const std::string &env_ipath,
bool opt_click_allowed,
bool opt_display,
vpImage<Type> &Iinput,
196 #if defined(VISP_HAVE_X11)
198 #elif defined(VISP_HAVE_GTK)
200 #elif defined(VISP_HAVE_GDI)
202 #elif defined(HAVE_OPENCV_HIGHGUI)
207 display.init(I, 0, 0,
"KeyPoints detection.");
212 std::vector<std::string> descriptorNames;
213 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
214 (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
215 descriptorNames.push_back(
"SIFT");
217 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
218 descriptorNames.push_back(
"SURF");
220 descriptorNames.push_back(
"ORB");
221 #if (VISP_HAVE_OPENCV_VERSION >= 0x020403)
222 descriptorNames.push_back(
"BRISK");
224 #if defined(VISP_HAVE_OPENCV_XFEATURES2D) || (VISP_HAVE_OPENCV_VERSION < 0x030000)
225 descriptorNames.push_back(
"BRIEF");
226 #if (VISP_HAVE_OPENCV_VERSION >= 0x020402)
227 descriptorNames.push_back(
"FREAK");
230 #if defined(VISP_HAVE_OPENCV_XFEATURES2D)
231 descriptorNames.push_back(
"DAISY");
232 descriptorNames.push_back(
"LATCH");
234 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
235 descriptorNames.push_back(
"VGG");
236 descriptorNames.push_back(
"BoostDesc");
238 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
239 descriptorNames.push_back(
"KAZE");
240 descriptorNames.push_back(
"AKAZE");
243 std::string detectorName =
"FAST";
245 std::vector<cv::KeyPoint> kpts;
247 keyPoints.
detect(I, kpts);
248 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
250 std::stringstream ss;
251 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
255 for (std::vector<std::string>::const_iterator itd = descriptorNames.begin(); itd != descriptorNames.end(); ++itd) {
258 if (*itd ==
"KAZE") {
259 detectorName =
"KAZE";
261 keyPoints.
detect(I, kpts);
262 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
264 std::stringstream ss;
265 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
268 }
else if (*itd ==
"AKAZE") {
269 detectorName =
"AKAZE";
271 keyPoints.
detect(I, kpts);
272 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
274 std::stringstream ss;
275 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
278 }
else if (*itd ==
"BoostDesc") {
279 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
280 cv::Ptr<cv::Feature2D> boostDesc = keyPoints.
getExtractor(
"BoostDesc");
282 boostDesc = cv::xfeatures2d::BoostDesc::create(cv::xfeatures2d::BoostDesc::BINBOOST_256,
true, 5.0f);
288 keyPoints.
extract(I, kpts, descriptor);
291 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols
292 <<
" (rows x cols) ; type=" << getOpenCVType(descriptor.type()) <<
" for " << *itd <<
" method in " << t
293 <<
" ms." << std::endl;
294 if (descriptor.empty()) {
295 std::stringstream ss;
296 ss <<
"No descriptor extracted with " << *itd <<
" and image:" << filename <<
"." << std::endl;
303 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
305 imPt.
set_uv(it->pt.x, it->pt.y);
312 if (opt_click_allowed) {
320 std::map<vpKeyPoint::vpFeatureDescriptorType, std::string> mapOfDescriptorNames = keyPoints.
getExtractorNames();
326 detectorName =
"KAZE";
328 keyPoints.
detect(I, kpts);
329 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
331 std::stringstream ss;
332 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
336 detectorName =
"AKAZE";
338 keyPoints.
detect(I, kpts);
339 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
341 std::stringstream ss;
342 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
346 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
347 detectorName =
"FAST";
349 keyPoints.
detect(I, kpts);
350 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
352 std::stringstream ss;
353 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
357 cv::Ptr<cv::Feature2D> boostDesc = keyPoints.
getExtractor(
"BoostDesc");
359 boostDesc = cv::xfeatures2d::BoostDesc::create(cv::xfeatures2d::BoostDesc::BINBOOST_256,
true, 5.0f);
365 keyPoints.
extract(I, kpts, descriptor);
368 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols
369 <<
" (rows x cols) ; type=" << getOpenCVType(descriptor.type()) <<
" for "
372 if (descriptor.empty()) {
373 std::stringstream ss;
375 <<
" and image:" << filename <<
"." << std::endl;
382 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
384 imPt.
set_uv(it->pt.x, it->pt.y);
391 if (opt_click_allowed) {
403 int main(
int argc,
const char **argv)
406 std::string env_ipath;
407 bool opt_click_allowed =
true;
408 bool opt_display =
true;
411 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
419 if (env_ipath.empty()) {
420 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment "
429 std::cout <<
"-- Test on gray level images" << std::endl;
430 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
436 std::cout <<
"-- Test on color images" << std::endl;
437 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
441 std::cerr << e.
what() << std::endl;
445 std::cout <<
"testKeyPoint-6 is ok !" << std::endl;
453 std::cerr <<
"You need OpenCV library." << std::endl;
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...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
const char * what() const
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 ...
void set_uv(double u, double v)
Definition of the vpImage class member functions.
void quarterSizeImage(vpImage< Type > &res) const
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
void setExtractor(const vpFeatureDescriptorType &extractorType)
void extract(const vpImage< unsigned char > &I, std::vector< cv::KeyPoint > &keyPoints, cv::Mat &descriptors, std::vector< cv::Point3f > *trainPoints=nullptr)
void detect(const vpImage< unsigned char > &I, std::vector< cv::KeyPoint > &keyPoints, const vpRect &rectangle=vpRect())
@ DESCRIPTOR_TYPE_SIZE
Number of descriptors available.
std::map< vpFeatureDescriptorType, std::string > getExtractorNames() const
void setDetector(const vpFeatureDetectorType &detectorType)
cv::Ptr< cv::DescriptorExtractor > getExtractor(const vpFeatureDescriptorType &type) const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.
VISP_EXPORT double measureTimeMs()