42 #include <visp3/core/vpConfig.h>
44 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_FEATURES2D) && defined(HAVE_OPENCV_VIDEO)
46 #include <visp3/core/vpImage.h>
47 #include <visp3/core/vpIoTools.h>
48 #include <visp3/gui/vpDisplayGDI.h>
49 #include <visp3/gui/vpDisplayGTK.h>
50 #include <visp3/gui/vpDisplayOpenCV.h>
51 #include <visp3/gui/vpDisplayX.h>
52 #include <visp3/io/vpImageIo.h>
53 #include <visp3/io/vpParseArgv.h>
54 #include <visp3/vision/vpKeyPoint.h>
57 #define GETOPTARGS "cdh"
59 #ifdef ENABLE_VISP_NAMESPACE
63 void usage(
const char *name,
const char *badparam);
64 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
72 void usage(
const char *name,
const char *badparam)
75 Test keypoint descriptor extraction.\n\
85 Disable the mouse click. Useful to automate the \n\
86 execution of this program without human intervention.\n\
89 Turn off the display.\n\
95 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
109 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
117 click_allowed =
false;
123 usage(argv[0],
nullptr);
128 usage(argv[0], optarg_);
134 if ((c == 1) || (c == -1)) {
136 usage(argv[0],
nullptr);
137 std::cerr <<
"ERROR: " << std::endl;
138 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
153 std::string getOpenCVType(
int type)
155 std::string type_string =
"";
159 type_string =
"CV_8U";
163 type_string =
"CV_8S";
167 type_string =
"CV_16U";
171 type_string =
"CV_16S";
175 type_string =
"CV_32S";
179 type_string =
"CV_32F";
183 type_string =
"CV_64F";
187 type_string =
"Problem with type !";
194 template <
typename Type>
195 void run_test(
const std::string &env_ipath,
bool opt_click_allowed,
bool opt_display,
vpImage<Type> &Iinput,
206 #if defined(VISP_HAVE_X11)
208 #elif defined(VISP_HAVE_GTK)
210 #elif defined(VISP_HAVE_GDI)
212 #elif defined(HAVE_OPENCV_HIGHGUI)
217 display.init(I, 0, 0,
"KeyPoints detection.");
222 std::vector<std::string> descriptorNames;
223 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
224 (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
225 descriptorNames.push_back(
"SIFT");
227 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
228 descriptorNames.push_back(
"SURF");
230 descriptorNames.push_back(
"ORB");
231 #if (VISP_HAVE_OPENCV_VERSION >= 0x020403)
232 descriptorNames.push_back(
"BRISK");
234 #if defined(VISP_HAVE_OPENCV_XFEATURES2D) || (VISP_HAVE_OPENCV_VERSION < 0x030000)
235 descriptorNames.push_back(
"BRIEF");
236 #if (VISP_HAVE_OPENCV_VERSION >= 0x020402)
237 descriptorNames.push_back(
"FREAK");
240 #if defined(VISP_HAVE_OPENCV_XFEATURES2D)
241 descriptorNames.push_back(
"DAISY");
242 descriptorNames.push_back(
"LATCH");
244 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
245 descriptorNames.push_back(
"VGG");
246 descriptorNames.push_back(
"BoostDesc");
248 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
249 descriptorNames.push_back(
"KAZE");
250 descriptorNames.push_back(
"AKAZE");
253 std::string detectorName =
"FAST";
255 std::vector<cv::KeyPoint> kpts;
257 keyPoints.
detect(I, kpts);
258 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
260 std::stringstream ss;
261 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
265 for (std::vector<std::string>::const_iterator itd = descriptorNames.begin(); itd != descriptorNames.end(); ++itd) {
268 if (*itd ==
"KAZE") {
269 detectorName =
"KAZE";
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;
279 else if (*itd ==
"AKAZE") {
280 detectorName =
"AKAZE";
282 keyPoints.
detect(I, kpts);
283 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
285 std::stringstream ss;
286 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
290 else if (*itd ==
"BoostDesc") {
291 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
292 cv::Ptr<cv::Feature2D> boostDesc = keyPoints.
getExtractor(
"BoostDesc");
294 boostDesc = cv::xfeatures2d::BoostDesc::create(cv::xfeatures2d::BoostDesc::BINBOOST_256,
true, 5.0f);
300 keyPoints.
extract(I, kpts, descriptor);
303 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols
304 <<
" (rows x cols) ; type=" << getOpenCVType(descriptor.type()) <<
" for " << *itd <<
" method in " << t
305 <<
" ms." << std::endl;
306 if (descriptor.empty()) {
307 std::stringstream ss;
308 ss <<
"No descriptor extracted with " << *itd <<
" and image:" << filename <<
"." << std::endl;
315 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
317 imPt.
set_uv(it->pt.x, it->pt.y);
324 if (opt_click_allowed) {
332 std::map<vpKeyPoint::vpFeatureDescriptorType, std::string> mapOfDescriptorNames = keyPoints.
getExtractorNames();
338 detectorName =
"KAZE";
340 keyPoints.
detect(I, kpts);
341 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
343 std::stringstream ss;
344 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
349 detectorName =
"AKAZE";
351 keyPoints.
detect(I, kpts);
352 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
354 std::stringstream ss;
355 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
360 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
361 detectorName =
"FAST";
363 keyPoints.
detect(I, kpts);
364 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
366 std::stringstream ss;
367 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
371 cv::Ptr<cv::Feature2D> boostDesc = keyPoints.
getExtractor(
"BoostDesc");
373 boostDesc = cv::xfeatures2d::BoostDesc::create(cv::xfeatures2d::BoostDesc::BINBOOST_256,
true, 5.0f);
379 keyPoints.
extract(I, kpts, descriptor);
382 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols
383 <<
" (rows x cols) ; type=" << getOpenCVType(descriptor.type()) <<
" for "
386 if (descriptor.empty()) {
387 std::stringstream ss;
389 <<
" and image:" << filename <<
"." << std::endl;
396 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
398 imPt.
set_uv(it->pt.x, it->pt.y);
405 if (opt_click_allowed) {
412 int main(
int argc,
const char **argv)
415 std::string env_ipath;
416 bool opt_click_allowed =
true;
417 bool opt_display =
true;
420 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
428 if (env_ipath.empty()) {
429 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment "
438 std::cout <<
"-- Test on gray level images" << std::endl;
439 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
445 std::cout <<
"-- Test on color images" << std::endl;
446 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
451 std::cerr << e.
what() << std::endl;
455 std::cout <<
"testKeyPoint-6 is ok !" << std::endl;
463 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...
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)
VISP_EXPORT double measureTimeMs()