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(
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 !";
188 template<
typename Type>
189 void run_test(
const std::string &env_ipath,
bool opt_click_allowed,
bool opt_display,
200 #if defined VISP_HAVE_X11 202 #elif defined VISP_HAVE_GTK 204 #elif defined VISP_HAVE_GDI 211 display.
init(I, 0, 0,
"KeyPoints detection.");
216 std::vector<std::string> descriptorNames;
217 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \ 218 (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400) 219 descriptorNames.push_back(
"SIFT");
221 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) 222 descriptorNames.push_back(
"SURF");
224 descriptorNames.push_back(
"ORB");
225 #if (VISP_HAVE_OPENCV_VERSION >= 0x020403) 226 descriptorNames.push_back(
"BRISK");
228 #if defined(VISP_HAVE_OPENCV_XFEATURES2D) || (VISP_HAVE_OPENCV_VERSION < 0x030000) 229 descriptorNames.push_back(
"BRIEF");
230 #if (VISP_HAVE_OPENCV_VERSION >= 0x020402) 231 descriptorNames.push_back(
"FREAK");
234 #if defined(VISP_HAVE_OPENCV_XFEATURES2D) 235 descriptorNames.push_back(
"DAISY");
236 descriptorNames.push_back(
"LATCH");
238 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D) 239 descriptorNames.push_back(
"VGG");
240 descriptorNames.push_back(
"BoostDesc");
242 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) 243 descriptorNames.push_back(
"KAZE");
244 descriptorNames.push_back(
"AKAZE");
247 std::string detectorName =
"FAST";
249 std::vector<cv::KeyPoint> kpts;
251 keyPoints.
detect(I, kpts);
252 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
254 std::stringstream ss;
255 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
259 for (std::vector<std::string>::const_iterator itd = descriptorNames.begin(); itd != descriptorNames.end(); ++itd) {
262 if (*itd ==
"KAZE") {
263 detectorName =
"KAZE";
265 keyPoints.
detect(I, kpts);
266 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
268 std::stringstream ss;
269 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
272 }
else if (*itd ==
"AKAZE") {
273 detectorName =
"AKAZE";
275 keyPoints.
detect(I, kpts);
276 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
278 std::stringstream ss;
279 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
282 }
else if (*itd ==
"BoostDesc") {
283 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D) 284 cv::Ptr<cv::Feature2D> boostDesc = keyPoints.
getExtractor(
"BoostDesc");
286 boostDesc = cv::xfeatures2d::BoostDesc::create(cv::xfeatures2d::BoostDesc::BINBOOST_256,
true, 5.0f);
292 keyPoints.
extract(I, kpts, descriptor);
295 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols
296 <<
" (rows x cols) ; type=" << getOpenCVType(descriptor.type()) <<
" for " << *itd <<
" method in " << t
297 <<
" ms." << std::endl;
298 if (descriptor.empty()) {
299 std::stringstream ss;
300 ss <<
"No descriptor extracted with " << *itd <<
" and image:" << filename <<
"." << std::endl;
307 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
309 imPt.
set_uv(it->pt.x, it->pt.y);
316 if (opt_click_allowed) {
324 std::map<vpKeyPoint::vpFeatureDescriptorType, std::string> mapOfDescriptorNames = keyPoints.
getExtractorNames();
330 detectorName =
"KAZE";
332 keyPoints.
detect(I, kpts);
333 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
335 std::stringstream ss;
336 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
340 detectorName =
"AKAZE";
342 keyPoints.
detect(I, kpts);
343 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
345 std::stringstream ss;
346 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
350 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D) 351 detectorName =
"FAST";
353 keyPoints.
detect(I, kpts);
354 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
356 std::stringstream ss;
357 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
361 cv::Ptr<cv::Feature2D> boostDesc = keyPoints.
getExtractor(
"BoostDesc");
363 boostDesc = cv::xfeatures2d::BoostDesc::create(cv::xfeatures2d::BoostDesc::BINBOOST_256,
true, 5.0f);
369 keyPoints.
extract(I, kpts, descriptor);
372 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols
373 <<
" (rows x cols) ; type=" << getOpenCVType(descriptor.type()) <<
" for " 376 if (descriptor.empty()) {
377 std::stringstream ss;
379 <<
" and image:" << filename <<
"." << std::endl;
386 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
388 imPt.
set_uv(it->pt.x, it->pt.y);
395 if (opt_click_allowed) {
407 int main(
int argc,
const char **argv)
410 std::string env_ipath;
411 bool opt_click_allowed =
true;
412 bool opt_display =
true;
415 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
423 if (env_ipath.empty()) {
424 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment " 433 std::cout <<
"-- Test on gray level images" << std::endl;
434 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
440 std::cout <<
"-- Test on color images" << std::endl;
441 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
445 std::cerr << e.
what() << std::endl;
449 std::cout <<
"testKeyPoint-6 is ok !" << std::endl;
457 std::cerr <<
"You need OpenCV library." << std::endl;
void quarterSizeImage(vpImage< Type > &res) const
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
void set_uv(double u, double v)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
cv::Ptr< cv::DescriptorExtractor > getExtractor(const vpFeatureDescriptorType &type) const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
const char * what() const
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void setDetector(const vpFeatureDetectorType &detectorType)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
std::map< vpFeatureDescriptorType, std::string > getExtractorNames() const
static void read(vpImage< unsigned char > &I, const std::string &filename)
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void setExtractor(const vpFeatureDescriptorType &extractorType)
Definition of the vpImage class member functions.
void detect(const vpImage< unsigned char > &I, std::vector< cv::KeyPoint > &keyPoints, const vpRect &rectangle=vpRect())
void extract(const vpImage< unsigned char > &I, std::vector< cv::KeyPoint > &keyPoints, cv::Mat &descriptors, std::vector< cv::Point3f > *trainPoints=NULL)