40 #include <visp3/core/vpImage.h>
41 #include <visp3/core/vpImageTools.h>
42 #include <visp3/core/vpIoTools.h>
43 #include <visp3/gui/vpDisplayGDI.h>
44 #include <visp3/gui/vpDisplayOpenCV.h>
45 #include <visp3/gui/vpDisplayX.h>
46 #include <visp3/io/vpParseArgv.h>
47 #include <visp3/io/vpVideoReader.h>
50 #define GETOPTARGS "cdi:h"
52 #ifdef ENABLE_VISP_NAMESPACE
58 void usage(
const char *name,
const char *badparam, std::string ipath)
61 Test vpImageTools::normalizedCorrelation().\n\
64 %s [-i <VISP_IMAGES directory>] \n\
71 -i <VISP_IMAGES directory> %s\n\
72 Set VISP_IMAGES input path.\n\
73 Setting the VISP_INPUT_IMAGE_PATH environment\n\
74 variable produces the same behaviour than using\n\
81 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
84 bool getOptions(
int argc,
const char **argv, std::string &ipath)
95 usage(argv[0],
nullptr, ipath);
104 usage(argv[0], optarg_, ipath);
110 if ((c == 1) || (c == -1)) {
112 usage(argv[0],
nullptr, ipath);
113 std::cerr <<
"ERROR: " << std::endl;
114 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
122 unsigned int step_u,
unsigned int step_v,
bool useOptimized)
130 for (
unsigned int i = 0; i < I.
getHeight() - height_tpl; i += step_v) {
131 for (
unsigned int j = 0; j < I.
getWidth() - width_tpl; j += step_u) {
141 int main(
int argc,
const char **argv)
144 std::string env_ipath;
145 std::string opt_ipath;
147 std::string filename;
149 #if VISP_HAVE_DATASET_VERSION >= 0x030600
150 std::string ext(
"png");
152 std::string ext(
"pgm");
160 if (!env_ipath.empty()) {
165 if (!getOptions(argc, argv, opt_ipath)) {
170 if (!opt_ipath.empty()) {
176 if (!opt_ipath.empty() && !env_ipath.empty()) {
177 if (ipath != env_ipath) {
178 std::cout << std::endl <<
"WARNING: " << std::endl;
179 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
180 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
181 <<
" we skip the environment variable." << std::endl;
186 if (opt_ipath.empty() && env_ipath.empty()) {
187 usage(argv[0],
nullptr, ipath);
188 std::cerr << std::endl <<
"ERROR:" << std::endl;
189 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
190 <<
" environment variable to specify the location of the " << std::endl
191 <<
" image path where test images are located." << std::endl
211 const unsigned int step_i = 5, step_j = 5;
213 templateMatching(I, I_template, I_score, step_i, step_j,
true);
217 templateMatching(I, I_template, I_score_gold, step_i, step_j,
false);
220 for (
unsigned int i = 0; i < I_score.
getHeight(); i++) {
221 for (
unsigned int j = 0; j < I_score.
getWidth(); j++) {
222 if (!
vpMath::equal(I_score[i][j], I_score_gold[i][j], 1e-9)) {
223 std::cerr <<
"Issue with normalizedCorrelation, gold: " << std::setprecision(17) << I_score_gold[i][j]
224 <<
" ; compute: " << I_score[i][j] << std::endl;
231 double max_correlation = -1.0, max_correlation_gold = -1.0;
232 I_score.
getMinMaxLoc(
nullptr, &max_loc,
nullptr, &max_correlation);
233 I_score_gold.
getMinMaxLoc(
nullptr, &max_loc_gold,
nullptr, &max_correlation_gold);
235 std::cout <<
"Compare regular and SSE version of vpImageTools::normalizedCorrelation()" << std::endl;
236 std::cout <<
"vpImageTools::normalizedCorrelation(): " << max_correlation <<
" ; " << t <<
" ms" << std::endl;
237 std::cout <<
"Gold normalizedCorrelation(): " << max_correlation_gold <<
" ; " << t_gold <<
" ms" << std::endl;
239 std::cerr <<
"\nTrue template position: " << template_roi.getTopLeft() << std::endl;
240 std::cerr <<
"Found template position: " << max_loc << std::endl;
242 std::cerr <<
"Issue with vpImageTools::normalizedCorrelation:" << std::endl;
248 std::cerr <<
"\nCatch an exception: " << e << std::endl;
error that can be emitted by ViSP classes.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
void getMinMaxLoc(vpImagePoint *minLoc, vpImagePoint *maxLoc, Type *minVal=nullptr, Type *maxVal=nullptr) const
Get the position of the minimum and/or the maximum pixel value within the bitmap and the correspondin...
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getHeight() const
static bool equal(double x, double y, double threshold=0.001)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Defines a rectangle in the plane.
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
VISP_EXPORT double measureTimeMs()