44#include <visp3/core/vpConfig.h>
46#if defined(VISP_HAVE_OPENCV) && 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
64void usage(
const char *name,
const char *badparam);
65bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
75void usage(
const char *name,
const char *badparam)
78Test 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);
112bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
120 click_allowed =
false;
126 usage(argv[0],
nullptr);
130 usage(argv[0], optarg_);
135 if ((c == 1) || (c == -1)) {
137 usage(argv[0],
nullptr);
138 std::cerr <<
"ERROR: " << std::endl;
139 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
146template <
typename Type>
147void run_test(
const std::string &env_ipath,
bool opt_click_allowed,
bool opt_display,
vpImage<Type> &Iinput,
161#ifdef VISP_HAVE_DISPLAY
164 std::cout <<
"No image viewer is available..." << std::endl;
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." << std::endl
178 std::vector<std::string> detectorNames;
179#if defined(VISP_HAVE_OPENCV) && \
180 (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || \
181 ((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 defined(VISP_HAVE_OPENCV) && \
200 (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || \
201 ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES)))
202 detectorNames.push_back(
"PyramidORB");
203 detectorNames.push_back(
"ORB");
205#if defined(VISP_HAVE_OPENCV) && \
206 (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || \
207 ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_XFEATURES2D)))
208#if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
209 detectorNames.push_back(
"PyramidAGAST");
210 detectorNames.push_back(
"AGAST");
212 detectorNames.push_back(
"PyramidBRISK");
213 detectorNames.push_back(
"BRISK");
214#if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
215 detectorNames.push_back(
"PyramidKAZE");
216 detectorNames.push_back(
"KAZE");
217 detectorNames.push_back(
"PyramidAKAZE");
218 detectorNames.push_back(
"AKAZE");
222#if defined(VISP_HAVE_OPENCV) && \
223 (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_XFEATURES2D)) || \
224 ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES)))
225#if (VISP_HAVE_OPENCV_VERSION != 0x040504) && (VISP_HAVE_OPENCV_VERSION != 0x040505) && \
226 (VISP_HAVE_OPENCV_VERSION != 0x040600) && (VISP_HAVE_OPENCV_VERSION != 0x040700) && \
227 (VISP_HAVE_OPENCV_VERSION != 0x040900) && (VISP_HAVE_OPENCV_VERSION != 0x040A00) && \
228 (defined(__APPLE__) && defined(__MACH__))
232 std::cout <<
"-- Add SIFT detector" << std::endl;
233 detectorNames.push_back(
"PyramidSIFT");
234 detectorNames.push_back(
"SIFT");
237#if defined(OPENCV_ENABLE_NONFREE) && defined(HAVE_OPENCV_XFEATURES2D)
238 detectorNames.push_back(
"PyramidSURF");
239 detectorNames.push_back(
"SURF");
242 for (std::vector<std::string>::const_iterator itd = detectorNames.begin(); itd != detectorNames.end(); ++itd) {
245 std::vector<cv::KeyPoint> kpts;
247 keyPoints.
detect(I, kpts);
248 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for " << *itd <<
" method." << std::endl;
250 std::stringstream ss;
251 ss <<
"No keypoints detected with " << *itd <<
" and image: " <<
filename <<
"." << std::endl;
258 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
260 imPt.
set_uv(it->pt.x, it->pt.y);
267 if (opt_click_allowed) {
275 std::map<vpKeyPoint::vpFeatureDetectorType, std::string> mapOfDetectorNames = keyPoints.
getDetectorNames();
277#if defined(VISP_HAVE_OPENCV) && \
278 (((VISP_HAVE_OPENCV_VERSION < 0x050000) && ((VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || \
279 (VISP_HAVE_OPENCV_VERSION >= 0x040400)) && defined(HAVE_OPENCV_FEATURES2D))) || \
280 ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES))
281#if ((VISP_HAVE_OPENCV_VERSION == 0x040504) || (VISP_HAVE_OPENCV_VERSION == 0x040505) || \
282 (VISP_HAVE_OPENCV_VERSION == 0x040600) || (VISP_HAVE_OPENCV_VERSION == 0x040700) || \
283 (VISP_HAVE_OPENCV_VERSION == 0x040900) || (VISP_HAVE_OPENCV_VERSION == 0x040A00)) && \
284 (defined(__APPLE__) && defined(__MACH__))
288 if (i == vpKeyPoint::DETECTOR_SIFT) {
289 std::cout <<
"-- Skip SIFT detector" << std::endl;
296 std::vector<cv::KeyPoint> kpts;
298 keyPoints.
detect(I, kpts);
299 std::cout <<
"Nb keypoints detected: " << kpts.size() <<
" for "
302 std::stringstream ss;
304 <<
" method and image: " << filename <<
"." << std::endl;
311 for (std::vector<cv::KeyPoint>::const_iterator it = kpts.begin(); it != kpts.end(); ++it) {
313 imPt.
set_uv(it->pt.x, it->pt.y);
320 if (opt_click_allowed) {
331int main(
int argc,
const char **argv)
334 std::string env_ipath;
335 bool opt_click_allowed =
true;
336 bool opt_display =
true;
339 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
347 if (env_ipath.empty()) {
348 std::cerr <<
"Please set the VISP_INPUT_IMAGE_PATH environment "
357 std::cout <<
"-- Test on gray level images" << std::endl;
358 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
364 std::cout <<
"-- Test on color images" << std::endl;
365 run_test(env_ipath, opt_click_allowed, opt_display, Iinput, I);
370 std::cerr <<
e.what() << std::endl;
374 std::cout <<
"testKeyPoint-5 is ok !" << std::endl;
382 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.
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.
void detect(const vpImage< unsigned char > &I, std::vector< cv::KeyPoint > &keyPoints, const vpRect &rectangle=vpRect())
std::map< vpFeatureDetectorType, std::string > getDetectorNames() const
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.