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
58void 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);
84bool getOptions(
int argc,
const char **argv, std::string &ipath)
95 usage(argv[0],
nullptr, ipath);
103 usage(argv[0], optarg_, ipath);
108 if ((c == 1) || (c == -1)) {
110 usage(argv[0],
nullptr, ipath);
111 std::cerr <<
"ERROR: " << std::endl;
112 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
120 unsigned int step_u,
unsigned int step_v,
bool useOptimized)
126 I_score.
resize(I.getHeight() - height_tpl, I.getWidth() - width_tpl, 0.0);
128 for (
unsigned int i = 0;
i < I.getHeight() - height_tpl;
i += step_v) {
129 for (
unsigned int j = 0;
j < I.getWidth() - width_tpl;
j += step_u) {
139int main(
int argc,
const char **argv)
142 std::string env_ipath;
143 std::string opt_ipath;
147#if defined(VISP_HAVE_DATASET)
148#if VISP_HAVE_DATASET_VERSION >= 0x030600
149 std::string ext(
"png");
151 std::string ext(
"pgm");
155 std::string ext(
"png");
163 if (!env_ipath.empty()) {
168 if (!getOptions(argc, argv, opt_ipath)) {
173 if (!opt_ipath.empty()) {
179 if (!opt_ipath.empty() && !env_ipath.empty()) {
180 if (ipath != env_ipath) {
181 std::cout << std::endl <<
"WARNING: " << std::endl;
182 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
183 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
184 <<
" we skip the environment variable." << std::endl;
189 if (opt_ipath.empty() && env_ipath.empty()) {
190 usage(argv[0],
nullptr, ipath);
191 std::cerr << std::endl <<
"ERROR:" << std::endl;
192 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
193 <<
" environment variable to specify the location of the " << std::endl
194 <<
" image path where test images are located." << std::endl
214 const unsigned int step_i = 5, step_j = 5;
216 templateMatching(I, I_template, I_score, step_i, step_j,
true);
220 templateMatching(I, I_template, I_score_gold, step_i, step_j,
false);
223 for (
unsigned int i = 0;
i < I_score.
getHeight();
i++) {
224 for (
unsigned int j = 0;
j < I_score.
getWidth();
j++) {
225 if (!
vpMath::equal(I_score[i][j], I_score_gold[i][j], 1e-9)) {
226 std::cerr <<
"Issue with normalizedCorrelation, gold: " << std::setprecision(17) << I_score_gold[
i][
j]
227 <<
" ; compute: " << I_score[
i][
j] << std::endl;
234 double max_correlation = -1.0, max_correlation_gold = -1.0;
235 I_score.
getMinMaxLoc(
nullptr, &max_loc,
nullptr, &max_correlation);
236 I_score_gold.
getMinMaxLoc(
nullptr, &max_loc_gold,
nullptr, &max_correlation_gold);
238 std::cout <<
"Compare regular and SSE version of vpImageTools::normalizedCorrelation()" << std::endl;
239 std::cout <<
"vpImageTools::normalizedCorrelation(): " << max_correlation <<
" ; " <<
t <<
" ms" << std::endl;
240 std::cout <<
"Gold normalizedCorrelation(): " << max_correlation_gold <<
" ; " << t_gold <<
" ms" << std::endl;
242 std::cerr <<
"\nTrue template position: " << template_roi.getTopLeft() << std::endl;
243 std::cerr <<
"Found template position: " << max_loc << std::endl;
245 std::cerr <<
"Issue with vpImageTools::normalizedCorrelation:" << std::endl;
251 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)
Definition of the vpImage class member functions.
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) VP_OVERRIDE
void setFileName(const std::string &filename)
VISP_EXPORT double measureTimeMs()