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);
68 void usage(
const char *name,
const char *badparam)
71 Test keypoint descriptor extraction.\n\ 74 %s [-c] [-d] [-h]\n", name);
80 Disable the mouse click. Useful to automaze the \n\ 81 execution of this program without humain intervention.\n\ 84 Turn off the display.\n\ 90 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
104 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
111 case 'c': click_allowed =
false;
break;
112 case 'd': display =
false;
break;
113 case 'h': usage(argv[0], NULL);
return false;
break;
116 usage(argv[0], optarg_);
121 if ((c == 1) || (c == -1)) {
123 usage(argv[0], NULL);
124 std::cerr <<
"ERROR: " << std::endl;
125 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
140 std::string getOpenCVType(
const int type) {
141 std::string type_string =
"";
145 type_string =
"CV_8U";
149 type_string =
"CV_8S";
153 type_string =
"CV_16U";
157 type_string =
"CV_16S";
161 type_string =
"CV_32S";
165 type_string =
"CV_32F";
169 type_string =
"CV_64F";
173 type_string =
"Problem with type !";
185 int main(
int argc,
const char ** argv) {
187 std::string env_ipath;
188 bool opt_click_allowed =
true;
189 bool opt_display =
true;
192 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
199 if(env_ipath.empty()) {
200 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment variable value." << std::endl;
213 #if defined VISP_HAVE_X11 215 #elif defined VISP_HAVE_GTK 217 #elif defined VISP_HAVE_GDI 224 display.
init(I, 0, 0,
"KeyPoints detection.");
229 std::vector<std::string> descriptorNames;
230 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) 231 descriptorNames.push_back(
"SIFT");
232 descriptorNames.push_back(
"SURF");
234 descriptorNames.push_back(
"ORB");
235 #if (VISP_HAVE_OPENCV_VERSION >= 0x020403) 236 descriptorNames.push_back(
"BRISK");
238 #if defined(VISP_HAVE_OPENCV_XFEATURES2D) || (VISP_HAVE_OPENCV_VERSION < 0x030000) 239 descriptorNames.push_back(
"BRIEF");
240 #if (VISP_HAVE_OPENCV_VERSION >= 0x020402) 241 descriptorNames.push_back(
"FREAK");
244 #if defined(VISP_HAVE_OPENCV_XFEATURES2D) 245 descriptorNames.push_back(
"DAISY");
246 descriptorNames.push_back(
"LATCH");
249 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) 250 descriptorNames.push_back(
"KAZE");
251 descriptorNames.push_back(
"AKAZE");
254 std::string detectorName =
"FAST";
256 std::vector<cv::KeyPoint> kpts;
258 keyPoints.
detect(I, kpts, elapsedTime);
259 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
261 std::cerr <<
"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) {
267 detectorName =
"KAZE";
269 keyPoints.
detect(I, kpts, elapsedTime);
270 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
272 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
275 }
else if(*itd ==
"AKAZE") {
276 detectorName =
"AKAZE";
278 keyPoints.
detect(I, kpts, elapsedTime);
279 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << detectorName <<
" method." << std::endl;
281 std::cerr <<
"No keypoints detected with " << detectorName <<
" and image:" << filename <<
"." << std::endl;
290 keyPoints.
extract(I, kpts, descriptor, elapsedTime);
293 std::cout <<
"Descriptor: " << descriptor.rows <<
"x" << descriptor.cols <<
" (rows x cols) ; type=" <<
294 getOpenCVType(descriptor.type()) <<
" for " << *itd <<
" method in " << t <<
" ms." << std::endl;
295 if(descriptor.empty()) {
296 std::cerr <<
"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) {
319 std::cerr << e.
what() << std::endl;
323 std::cout <<
"testKeyPoint-6 is ok !" << std::endl;
328 std::cerr <<
"You need OpenCV library." << std::endl;
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void detect(const vpImage< unsigned char > &I, std::vector< cv::KeyPoint > &keyPoints, double &elapsedTime, const vpRect &rectangle=vpRect())
void setExtractor(const std::string &extractorName)
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
error that can be emited by ViSP classes.
static void flush(const vpImage< unsigned char > &I)
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.
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
VISP_EXPORT double measureTimeMs()
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
void extract(const vpImage< unsigned char > &I, std::vector< cv::KeyPoint > &keyPoints, cv::Mat &descriptors, double &elapsedTime, std::vector< cv::Point3f > *trainPoints=NULL)
void set_uv(const double u, const double v)
void setDetector(const std::string &detectorName)
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static void read(vpImage< unsigned char > &I, const char *filename)