37 #include <visp3/core/vpConfig.h>
39 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_FEATURES2D) && defined(HAVE_OPENCV_VIDEO)
41 #include <visp3/core/vpImage.h>
42 #include <visp3/core/vpIoTools.h>
43 #include <visp3/gui/vpDisplayGDI.h>
44 #include <visp3/gui/vpDisplayGTK.h>
45 #include <visp3/gui/vpDisplayOpenCV.h>
46 #include <visp3/gui/vpDisplayX.h>
47 #include <visp3/io/vpImageIo.h>
48 #include <visp3/io/vpParseArgv.h>
49 #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);
69 void usage(
const char *name,
const char *badparam)
72 Test keypoints detection.\n\
82 Disable the mouse click. Useful to automate the \n\
83 execution of this program without human intervention.\n\
86 Turn off the display.\n\
92 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
106 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
114 click_allowed =
false;
120 usage(argv[0],
nullptr);
125 usage(argv[0], optarg_);
131 if ((c == 1) || (c == -1)) {
133 usage(argv[0],
nullptr);
134 std::cerr <<
"ERROR: " << std::endl;
135 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
142 template <
typename Type>
143 void run_test(
const std::string &env_ipath,
bool opt_click_allowed,
bool opt_display,
vpImage<Type> &Iinput,
154 #if defined(VISP_HAVE_X11)
156 #elif defined(VISP_HAVE_GTK)
158 #elif defined(VISP_HAVE_GDI)
160 #elif defined(HAVE_OPENCV_HIGHGUI)
165 display.init(I, 0, 0,
"KeyPoints detection.");
170 std::cout <<
"INFORMATION: " << std::endl;
171 std::cout <<
"Here, we want to test feature detection on a pyramid of images even for features "
172 "that are scale invariant to detect potential problem in ViSP."
179 std::vector<std::string> detectorNames;
180 detectorNames.push_back(
"PyramidFAST");
181 detectorNames.push_back(
"FAST");
182 detectorNames.push_back(
"PyramidMSER");
183 detectorNames.push_back(
"MSER");
184 detectorNames.push_back(
"PyramidGFTT");
185 detectorNames.push_back(
"GFTT");
186 detectorNames.push_back(
"PyramidSimpleBlob");
187 detectorNames.push_back(
"SimpleBlob");
189 #if (VISP_HAVE_OPENCV_VERSION < 0x030000) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
190 detectorNames.push_back(
"PyramidSTAR");
191 detectorNames.push_back(
"STAR");
193 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
194 detectorNames.push_back(
"PyramidAGAST");
195 detectorNames.push_back(
"AGAST");
197 detectorNames.push_back(
"PyramidORB");
198 detectorNames.push_back(
"ORB");
199 #if (VISP_HAVE_OPENCV_VERSION >= 0x020403)
200 detectorNames.push_back(
"PyramidBRISK");
201 detectorNames.push_back(
"BRISK");
203 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
204 detectorNames.push_back(
"PyramidKAZE");
205 detectorNames.push_back(
"KAZE");
206 detectorNames.push_back(
"PyramidAKAZE");
207 detectorNames.push_back(
"AKAZE");
210 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
211 (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
212 #if (VISP_HAVE_OPENCV_VERSION != 0x040504) && (VISP_HAVE_OPENCV_VERSION != 0x040505) && \
213 (VISP_HAVE_OPENCV_VERSION != 0x040600) && (VISP_HAVE_OPENCV_VERSION != 0x040700) && \
214 (VISP_HAVE_OPENCV_VERSION != 0x040900) && \
215 (defined(__APPLE__) && defined(__MACH__))
219 detectorNames.push_back(
"PyramidSIFT");
220 detectorNames.push_back(
"SIFT");
223 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
224 detectorNames.push_back(
"PyramidSURF");
225 detectorNames.push_back(
"SURF");
228 for (std::vector<std::string>::const_iterator itd = detectorNames.begin(); itd != detectorNames.end(); ++itd) {
231 std::vector<cv::KeyPoint> kpts;
233 keyPoints.
detect(I, kpts);
234 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << *itd <<
" method." << std::endl;
236 std::stringstream ss;
237 ss <<
"No keypoints detected with " << *itd <<
" and image: " << filename <<
"." << std::endl;
244 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
246 imPt.
set_uv(it->pt.x, it->pt.y);
253 if (opt_click_allowed) {
261 std::map<vpKeyPoint::vpFeatureDetectorType, std::string> mapOfDetectorNames = keyPoints.
getDetectorNames();
263 #if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
264 (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
265 #if ((VISP_HAVE_OPENCV_VERSION == 0x040504) || (VISP_HAVE_OPENCV_VERSION == 0x040505) || \
266 (VISP_HAVE_OPENCV_VERSION == 0x040600) || (VISP_HAVE_OPENCV_VERSION == 0x040700) || \
267 (VISP_HAVE_OPENCV_VERSION == 0x040900)) && \
268 (defined(__APPLE__) && defined(__MACH__))
279 std::vector<cv::KeyPoint> kpts;
281 keyPoints.
detect(I, kpts);
282 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for "
285 std::stringstream ss;
287 <<
" method and image: " << filename <<
"." << std::endl;
294 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
296 imPt.
set_uv(it->pt.x, it->pt.y);
303 if (opt_click_allowed) {
316 int main(
int argc,
const char **argv)
319 std::string env_ipath;
320 bool opt_click_allowed =
true;
321 bool opt_display =
true;
324 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
332 if (env_ipath.empty()) {
333 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment "
342 std::cout <<
"-- Test on gray level images" << std::endl;
343 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
349 std::cout <<
"-- Test on color images" << std::endl;
350 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
355 std::cerr << e.
what() << std::endl;
359 std::cout <<
"testKeyPoint-5 is ok !" << std::endl;
367 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...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
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)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.