44 #include <visp3/core/vpConfig.h>
46 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_FEATURES2D) && defined(HAVE_OPENCV_VIDEO)
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpIoTools.h>
50 #include <visp3/gui/vpDisplayGDI.h>
51 #include <visp3/gui/vpDisplayGTK.h>
52 #include <visp3/gui/vpDisplayOpenCV.h>
53 #include <visp3/gui/vpDisplayX.h>
54 #include <visp3/io/vpImageIo.h>
55 #include <visp3/io/vpParseArgv.h>
56 #include <visp3/vision/vpKeyPoint.h>
59 #define GETOPTARGS "cdh"
61 #ifdef ENABLE_VISP_NAMESPACE
65 void usage(
const char *name,
const char *badparam);
66 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
76 void usage(
const char *name,
const char *badparam)
79 Test keypoints detection.\n\
89 Disable the mouse click. Useful to automate the \n\
90 execution of this program without human intervention.\n\
93 Turn off the display.\n\
99 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
113 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
121 click_allowed =
false;
127 usage(argv[0],
nullptr);
132 usage(argv[0], optarg_);
138 if ((c == 1) || (c == -1)) {
140 usage(argv[0],
nullptr);
141 std::cerr <<
"ERROR: " << std::endl;
142 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
149 template <
typename Type>
150 void run_test(
const std::string &env_ipath,
bool opt_click_allowed,
bool opt_display,
vpImage<Type> &Iinput,
161 #if defined(VISP_HAVE_X11)
163 #elif defined(VISP_HAVE_GTK)
165 #elif defined(VISP_HAVE_GDI)
167 #elif defined(HAVE_OPENCV_HIGHGUI)
172 display.init(I, 0, 0,
"KeyPoints detection.");
177 std::cout <<
"INFORMATION: " << std::endl;
178 std::cout <<
"Here, we want to test feature detection on a pyramid of images even for features "
179 "that are scale invariant to detect potential problem in ViSP."
186 std::vector<std::string> detectorNames;
187 detectorNames.push_back(
"PyramidFAST");
188 detectorNames.push_back(
"FAST");
189 detectorNames.push_back(
"PyramidMSER");
190 detectorNames.push_back(
"MSER");
191 detectorNames.push_back(
"PyramidGFTT");
192 detectorNames.push_back(
"GFTT");
193 detectorNames.push_back(
"PyramidSimpleBlob");
194 detectorNames.push_back(
"SimpleBlob");
196 #if (VISP_HAVE_OPENCV_VERSION < 0x030000) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
197 detectorNames.push_back(
"PyramidSTAR");
198 detectorNames.push_back(
"STAR");
200 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
201 detectorNames.push_back(
"PyramidAGAST");
202 detectorNames.push_back(
"AGAST");
204 detectorNames.push_back(
"PyramidORB");
205 detectorNames.push_back(
"ORB");
206 #if (VISP_HAVE_OPENCV_VERSION >= 0x020403)
207 detectorNames.push_back(
"PyramidBRISK");
208 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");
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 #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(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_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 defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
272 (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
273 #if ((VISP_HAVE_OPENCV_VERSION == 0x040504) || (VISP_HAVE_OPENCV_VERSION == 0x040505) || \
274 (VISP_HAVE_OPENCV_VERSION == 0x040600) || (VISP_HAVE_OPENCV_VERSION == 0x040700) || \
275 (VISP_HAVE_OPENCV_VERSION == 0x040900) || (VISP_HAVE_OPENCV_VERSION == 0x040A00)) && \
276 (defined(__APPLE__) && defined(__MACH__))
281 std::cout <<
"-- Skip SIFT detector" << std::endl;
288 std::vector<cv::KeyPoint> kpts;
290 keyPoints.
detect(I, kpts);
291 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for "
294 std::stringstream ss;
296 <<
" method 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 int main(
int argc,
const char **argv)
322 std::string env_ipath;
323 bool opt_click_allowed =
true;
324 bool opt_display =
true;
327 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
335 if (env_ipath.empty()) {
336 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment "
345 std::cout <<
"-- Test on gray level images" << std::endl;
346 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
352 std::cout <<
"-- Test on color images" << std::endl;
353 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
358 std::cerr << e.
what() << std::endl;
362 std::cout <<
"testKeyPoint-5 is ok !" << std::endl;
370 std::cerr <<
"You need OpenCV library." << std::endl;
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
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 detection (and descriptors extraction) and matching thanks to OpenCV libr...
@ 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)