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 descriptorNames.push_back(
"SIFT");
219 descriptorNames.push_back(
"SURF");
221 descriptorNames.push_back(
"ORB");
222 #if (VISP_HAVE_OPENCV_VERSION >= 0x020403) 223 descriptorNames.push_back(
"BRISK");
225 #if defined(VISP_HAVE_OPENCV_XFEATURES2D) || (VISP_HAVE_OPENCV_VERSION < 0x030000) 226 descriptorNames.push_back(
"BRIEF");
227 #if (VISP_HAVE_OPENCV_VERSION >= 0x020402) 228 descriptorNames.push_back(
"FREAK");
231 #if defined(VISP_HAVE_OPENCV_XFEATURES2D) 232 descriptorNames.push_back(
"DAISY");
233 descriptorNames.push_back(
"LATCH");
235 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D) 236 descriptorNames.push_back(
"VGG");
237 descriptorNames.push_back(
"BoostDesc");
239 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) 240 descriptorNames.push_back(
"KAZE");
241 descriptorNames.push_back(
"AKAZE");
244 std::string detectorName =
"FAST";
246 std::vector<cv::KeyPoint> kpts;
248 keyPoints.
detect(I, kpts);
249 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
251 std::stringstream ss;
252 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
256 for (std::vector<std::string>::const_iterator itd = descriptorNames.begin(); itd != descriptorNames.end(); ++itd) {
259 if (*itd ==
"KAZE") {
260 detectorName =
"KAZE";
262 keyPoints.
detect(I, kpts);
263 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
265 std::stringstream ss;
266 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
269 }
else if (*itd ==
"AKAZE") {
270 detectorName =
"AKAZE";
272 keyPoints.
detect(I, kpts);
273 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
275 std::stringstream ss;
276 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
279 }
else if (*itd ==
"BoostDesc") {
280 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D) 281 cv::Ptr<cv::Feature2D> boostDesc = keyPoints.
getExtractor(
"BoostDesc");
283 boostDesc = cv::xfeatures2d::BoostDesc::create(cv::xfeatures2d::BoostDesc::BINBOOST_256,
true, 5.0f);
289 keyPoints.
extract(I, kpts, descriptor);
292 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols
293 <<
" (rows x cols) ; type=" << getOpenCVType(descriptor.type()) <<
" for " << *itd <<
" method in " << t
294 <<
" ms." << std::endl;
295 if (descriptor.empty()) {
296 std::stringstream ss;
297 ss <<
"No descriptor extracted with " << *itd <<
" and image:" << filename <<
"." << std::endl;
304 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
306 imPt.
set_uv(it->pt.x, it->pt.y);
313 if (opt_click_allowed) {
321 std::map<vpKeyPoint::vpFeatureDescriptorType, std::string> mapOfDescriptorNames = keyPoints.
getExtractorNames();
327 detectorName =
"KAZE";
329 keyPoints.
detect(I, kpts);
330 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
332 std::stringstream ss;
333 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
337 detectorName =
"AKAZE";
339 keyPoints.
detect(I, kpts);
340 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
342 std::stringstream ss;
343 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
347 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D) 348 detectorName =
"FAST";
350 keyPoints.
detect(I, kpts);
351 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
353 std::stringstream ss;
354 ss <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
358 cv::Ptr<cv::Feature2D> boostDesc = keyPoints.
getExtractor(
"BoostDesc");
360 boostDesc = cv::xfeatures2d::BoostDesc::create(cv::xfeatures2d::BoostDesc::BINBOOST_256,
true, 5.0f);
366 keyPoints.
extract(I, kpts, descriptor);
369 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols
370 <<
" (rows x cols) ; type=" << getOpenCVType(descriptor.type()) <<
" for " 373 if (descriptor.empty()) {
374 std::stringstream ss;
376 <<
" and image:" << filename <<
"." << std::endl;
383 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
385 imPt.
set_uv(it->pt.x, it->pt.y);
392 if (opt_click_allowed) {
404 int main(
int argc,
const char **argv)
407 std::string env_ipath;
408 bool opt_click_allowed =
true;
409 bool opt_display =
true;
412 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
420 if (env_ipath.empty()) {
421 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment " 430 std::cout <<
"-- Test on gray level images" << std::endl;
431 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
437 std::cout <<
"-- Test on color images" << std::endl;
438 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
442 std::cerr << e.
what() << std::endl;
446 std::cout <<
"testKeyPoint-6 is ok !" << std::endl;
454 std::cerr <<
"You need OpenCV library." << std::endl;
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()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
std::map< vpFeatureDescriptorType, std::string > getExtractorNames() 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...
const char * what() const
void quarterSizeImage(vpImage< Type > &res) const
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
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...
cv::Ptr< cv::DescriptorExtractor > getExtractor(const vpFeatureDescriptorType &type) const
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)