44 #include <visp3/core/vpConfig.h>
46 #if defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) && \
47 ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_CALIB3D) && defined(HAVE_OPENCV_FEATURES2D)) || \
48 ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_3D) && defined(HAVE_OPENCV_FEATURES))
50 #include <visp3/core/vpImage.h>
51 #include <visp3/core/vpIoTools.h>
52 #include <visp3/gui/vpDisplayFactory.h>
53 #include <visp3/io/vpImageIo.h>
54 #include <visp3/io/vpParseArgv.h>
55 #include <visp3/vision/vpKeyPoint.h>
58 #define GETOPTARGS "cdh"
60 #ifdef ENABLE_VISP_NAMESPACE
64 void usage(
const char *name,
const char *badparam);
65 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
75 void usage(
const char *name,
const char *badparam)
78 Test keypoints detection.\n\
88 Disable the mouse click. Useful to automate the \n\
89 execution of this program without human intervention.\n\
92 Turn off the display.\n\
98 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
112 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
120 click_allowed =
false;
126 usage(argv[0],
nullptr);
131 usage(argv[0], optarg_);
137 if ((c == 1) || (c == -1)) {
139 usage(argv[0],
nullptr);
140 std::cerr <<
"ERROR: " << std::endl;
141 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
148 template <
typename Type>
149 void run_test(
const std::string &env_ipath,
bool opt_click_allowed,
bool opt_display,
vpImage<Type> &Iinput,
163 #ifdef VISP_HAVE_DISPLAY
166 std::cout <<
"No image viewer is available..." << std::endl;
172 std::cout <<
"INFORMATION: " << std::endl;
173 std::cout <<
"Here, we want to test feature detection on a pyramid of images even for features "
174 <<
"that are scale invariant to detect potential problem in ViSP." << std::endl
180 std::vector<std::string> detectorNames;
181 #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES))
182 detectorNames.push_back(
"PyramidFAST");
183 detectorNames.push_back(
"FAST");
185 #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES))
186 detectorNames.push_back(
"PyramidMSER");
187 detectorNames.push_back(
"MSER");
188 detectorNames.push_back(
"PyramidGFTT");
189 detectorNames.push_back(
"GFTT");
190 detectorNames.push_back(
"PyramidSimpleBlob");
191 detectorNames.push_back(
"SimpleBlob");
195 #if defined(HAVE_OPENCV_XFEATURES2D)
196 detectorNames.push_back(
"PyramidSTAR");
197 detectorNames.push_back(
"STAR");
199 #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES))
200 detectorNames.push_back(
"PyramidORB");
201 detectorNames.push_back(
"ORB");
203 #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_XFEATURES2D))
204 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
205 detectorNames.push_back(
"PyramidAGAST");
206 detectorNames.push_back(
"AGAST");
208 detectorNames.push_back(
"PyramidBRISK");
209 detectorNames.push_back(
"BRISK");
210 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
211 detectorNames.push_back(
"PyramidKAZE");
212 detectorNames.push_back(
"KAZE");
213 detectorNames.push_back(
"PyramidAKAZE");
214 detectorNames.push_back(
"AKAZE");
218 #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_XFEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES))
219 #if (VISP_HAVE_OPENCV_VERSION != 0x040504) && (VISP_HAVE_OPENCV_VERSION != 0x040505) && \
220 (VISP_HAVE_OPENCV_VERSION != 0x040600) && (VISP_HAVE_OPENCV_VERSION != 0x040700) && \
221 (VISP_HAVE_OPENCV_VERSION != 0x040900) && (VISP_HAVE_OPENCV_VERSION != 0x040A00) && \
222 (defined(__APPLE__) && defined(__MACH__))
226 std::cout <<
"-- Add SIFT detector" << std::endl;
227 detectorNames.push_back(
"PyramidSIFT");
228 detectorNames.push_back(
"SIFT");
231 #if defined(OPENCV_ENABLE_NONFREE) && defined(HAVE_OPENCV_XFEATURES2D)
232 detectorNames.push_back(
"PyramidSURF");
233 detectorNames.push_back(
"SURF");
236 for (std::vector<std::string>::const_iterator itd = detectorNames.begin(); itd != detectorNames.end(); ++itd) {
239 std::vector<cv::KeyPoint> kpts;
241 keyPoints.
detect(I, kpts);
242 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << *itd <<
" method." << std::endl;
244 std::stringstream ss;
245 ss <<
"No keypoints detected with " << *itd <<
" and image: " << filename <<
"." << std::endl;
252 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
254 imPt.
set_uv(it->pt.x, it->pt.y);
261 if (opt_click_allowed) {
269 std::map<vpKeyPoint::vpFeatureDetectorType, std::string> mapOfDetectorNames = keyPoints.
getDetectorNames();
271 #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_XFEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES))
272 #if ((VISP_HAVE_OPENCV_VERSION == 0x040504) || (VISP_HAVE_OPENCV_VERSION == 0x040505) || \
273 (VISP_HAVE_OPENCV_VERSION == 0x040600) || (VISP_HAVE_OPENCV_VERSION == 0x040700) || \
274 (VISP_HAVE_OPENCV_VERSION == 0x040900) || (VISP_HAVE_OPENCV_VERSION == 0x040A00)) && \
275 (defined(__APPLE__) && defined(__MACH__))
280 std::cout <<
"-- Skip SIFT detector" << std::endl;
287 std::vector<cv::KeyPoint> kpts;
289 keyPoints.
detect(I, kpts);
290 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for "
293 std::stringstream ss;
295 <<
" method and image: " << filename <<
"." << std::endl;
302 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
304 imPt.
set_uv(it->pt.x, it->pt.y);
311 if (opt_click_allowed) {
322 int main(
int argc,
const char **argv)
325 std::string env_ipath;
326 bool opt_click_allowed =
true;
327 bool opt_display =
true;
330 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
338 if (env_ipath.empty()) {
339 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment "
348 std::cout <<
"-- Test on gray level images" << std::endl;
349 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
355 std::cout <<
"-- Test on color images" << std::endl;
356 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
361 std::cerr << e.
what() << std::endl;
365 std::cout <<
"testKeyPoint-5 is ok !" << std::endl;
373 std::cerr <<
"You need OpenCV library." << std::endl;
Class that defines generic functionalities for display.
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 halfSizeImage(vpImage< Type > &res) const
Class that allows keypoints 2D features detection (and descriptors extraction) and matching thanks to...
@ DETECTOR_TYPE_SIZE
Number of detectors available.
@ DETECTOR_SIFT
SIFT detector.
std::map< vpFeatureDetectorType, std::string > getDetectorNames() const
void detect(const vpImage< unsigned char > &I, std::vector< cv::KeyPoint > &keyPoints, const vpRect &rectangle=vpRect())
void setDetector(const vpFeatureDetectorType &detectorType)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.