40 #include <visp3/core/vpConfig.h>
42 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020301)
44 #include <visp3/core/vpImage.h>
45 #include <visp3/io/vpImageIo.h>
46 #include <visp3/gui/vpDisplayX.h>
47 #include <visp3/gui/vpDisplayGTK.h>
48 #include <visp3/gui/vpDisplayGDI.h>
49 #include <visp3/gui/vpDisplayOpenCV.h>
50 #include <visp3/core/vpIoTools.h>
51 #include <visp3/io/vpParseArgv.h>
52 #include <visp3/vision/vpKeyPoint.h>
55 #define GETOPTARGS "cdh"
57 void usage(
const char *name,
const char *badparam);
58 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
66 void usage(
const char *name,
const char *badparam)
69 Test keypoint descriptor extraction.\n\
72 %s [-c] [-d] [-h]\n", name);
78 Disable the mouse click. Useful to automaze the \n\
79 execution of this program without humain intervention.\n\
82 Turn off the display.\n\
88 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
102 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
109 case 'c': click_allowed =
false;
break;
110 case 'd': display =
false;
break;
111 case 'h': usage(argv[0], NULL);
return false;
break;
114 usage(argv[0], optarg_);
119 if ((c == 1) || (c == -1)) {
121 usage(argv[0], NULL);
122 std::cerr <<
"ERROR: " << std::endl;
123 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
138 std::string getOpenCVType(
const int type) {
139 std::string type_string =
"";
143 type_string =
"CV_8U";
147 type_string =
"CV_8S";
151 type_string =
"CV_16U";
155 type_string =
"CV_16S";
159 type_string =
"CV_32S";
163 type_string =
"CV_32F";
167 type_string =
"CV_64F";
171 type_string =
"Problem with type !";
183 int main(
int argc,
const char ** argv) {
185 std::string env_ipath;
186 bool opt_click_allowed =
true;
187 bool opt_display =
true;
190 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
197 if(env_ipath.empty()) {
198 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment variable value." << std::endl;
211 #if defined VISP_HAVE_X11
213 #elif defined VISP_HAVE_GTK
215 #elif defined VISP_HAVE_GDI
222 display.
init(I, 0, 0,
"KeyPoints detection.");
227 std::vector<std::string> descriptorNames;
228 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
229 descriptorNames.push_back(
"SIFT");
230 descriptorNames.push_back(
"SURF");
232 descriptorNames.push_back(
"ORB");
233 #if (VISP_HAVE_OPENCV_VERSION >= 0x020403)
234 descriptorNames.push_back(
"BRISK");
236 #if defined(VISP_HAVE_OPENCV_XFEATURES2D) || (VISP_HAVE_OPENCV_VERSION < 0x030000)
237 descriptorNames.push_back(
"BRIEF");
238 #if (VISP_HAVE_OPENCV_VERSION >= 0x020402)
239 descriptorNames.push_back(
"FREAK");
242 #if defined(VISP_HAVE_OPENCV_XFEATURES2D)
243 descriptorNames.push_back(
"DAISY");
244 descriptorNames.push_back(
"LATCH");
246 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
247 descriptorNames.push_back(
"VGG");
248 descriptorNames.push_back(
"BoostDesc");
250 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
251 descriptorNames.push_back(
"KAZE");
252 descriptorNames.push_back(
"AKAZE");
255 std::string detectorName =
"FAST";
257 std::vector<cv::KeyPoint> kpts;
259 keyPoints.
detect(I, kpts);
260 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
262 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
266 for(std::vector<std::string>::const_iterator itd = descriptorNames.begin(); itd != descriptorNames.end(); ++itd) {
269 if (*itd ==
"KAZE") {
270 detectorName =
"KAZE";
272 keyPoints.
detect(I, kpts);
273 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
275 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
278 }
else if (*itd ==
"AKAZE") {
279 detectorName =
"AKAZE";
281 keyPoints.
detect(I, kpts);
282 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
284 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
287 }
else if (*itd ==
"BoostDesc") {
288 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
289 cv::Ptr<cv::Feature2D> boostDesc = keyPoints.
getExtractor(
"BoostDesc");
291 boostDesc = cv::xfeatures2d::BoostDesc::create(cv::xfeatures2d::BoostDesc::BINBOOST_256,
true, 5.0f);
297 keyPoints.
extract(I, kpts, descriptor);
300 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols <<
" (rows x cols) ; type="
301 << getOpenCVType(descriptor.type()) <<
" for " << *itd <<
" method in " << t <<
" ms." << std::endl;
302 if(descriptor.empty()) {
303 std::cerr <<
"No descriptor extracted with " << *itd <<
" and image:" << filename <<
"." << std::endl;
310 for(std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
312 imPt.
set_uv(it->pt.x, it->pt.y);
319 if(opt_click_allowed) {
327 std::map<vpKeyPoint::vpFeatureDescriptorType, std::string> mapOfDescriptorNames = keyPoints.
getExtractorNames();
333 detectorName =
"KAZE";
335 keyPoints.
detect(I, kpts);
336 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
338 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
342 detectorName =
"AKAZE";
344 keyPoints.
detect(I, kpts);
345 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
347 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
351 #if (VISP_HAVE_OPENCV_VERSION >= 0x030200) && defined(VISP_HAVE_OPENCV_XFEATURES2D)
352 detectorName =
"FAST";
354 keyPoints.
detect(I, kpts);
355 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
357 std::cerr <<
"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 <<
" (rows x cols) ; type="
374 << " method in " << t << " ms." << std::endl;
375 if(descriptor.empty()) {
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) {
399 std::cerr << e.
what() << std::endl;
403 std::cout <<
"testKeyPoint-6 is ok !" << std::endl;
410 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).
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...
void set_uv(const double u, const double v)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void setExtractor(const vpFeatureDescriptorType &extractorType)
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)