41 #include <visp3/core/vpImage.h> 42 #include <visp3/core/vpIoTools.h> 43 #include <visp3/core/vpImageTools.h> 44 #include <visp3/io/vpVideoReader.h> 45 #include <visp3/io/vpParseArgv.h> 46 #include <visp3/gui/vpDisplayX.h> 47 #include <visp3/gui/vpDisplayGDI.h> 48 #include <visp3/gui/vpDisplayOpenCV.h> 51 #define GETOPTARGS "cdi:h" 55 void usage(
const char *name,
const char *badparam, std::string ipath)
58 Test vpImageTools::normalizedCorrelation().\n\ 61 %s [-i <VISP_IMAGES directory>] \n\ 67 -i <VISP_IMAGES directory> %s\n\ 68 Set VISP_IMAGES input path.\n\ 69 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 70 variable produces the same behaviour than using\n\ 73 Print the help.\n\n", ipath.c_str());
76 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
79 bool getOptions(
int argc,
const char **argv, std::string &ipath)
90 usage(argv[0], NULL, ipath);
99 usage(argv[0], optarg_, ipath);
105 if ((c == 1) || (c == -1)) {
107 usage(argv[0], NULL, ipath);
108 std::cerr <<
"ERROR: " << std::endl;
109 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
118 const unsigned int step_v,
const bool useOptimized)
126 for (
unsigned int i = 0; i < I.
getHeight()-height_tpl; i += step_v) {
127 for (
unsigned int j = 0; j < I.
getWidth()-width_tpl; j += step_u) {
137 int main(
int argc,
const char **argv)
140 std::string env_ipath;
141 std::string opt_ipath;
143 std::string filename;
150 if (!env_ipath.empty()) {
155 if (!getOptions(argc, argv, opt_ipath)) {
160 if (!opt_ipath.empty()) {
166 if (!opt_ipath.empty() && !env_ipath.empty()) {
167 if (ipath != env_ipath) {
168 std::cout << std::endl <<
"WARNING: " << std::endl;
169 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 170 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
171 <<
" we skip the environment variable." << std::endl;
176 if (opt_ipath.empty() && env_ipath.empty()) {
177 usage(argv[0], NULL, ipath);
178 std::cerr << std::endl <<
"ERROR:" << std::endl;
179 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
180 <<
" environment variable to specify the location of the " << std::endl
181 <<
" image path where test images are located." << std::endl
201 const unsigned int step_i = 5, step_j = 5;
203 templateMatching(I, I_template, I_score, step_i, step_j,
true);
207 templateMatching(I, I_template, I_score_gold, step_i, step_j,
false);
210 for (
unsigned int i = 0; i < I_score.
getHeight(); i++) {
211 for (
unsigned int j = 0; j < I_score.
getWidth(); j++) {
212 if ( !
vpMath::equal(I_score[i][j], I_score_gold[i][j], 1e-9) ) {
213 std::cerr <<
"Issue with normalizedCorrelation, gold: " << std::setprecision(17)
214 << I_score_gold[i][j] <<
" ; compute: " << I_score[i][j] << std::endl;
221 double max_correlation = -1.0, max_correlation_gold = -1.0;
222 I_score.
getMinMaxLoc(NULL, &max_loc, NULL, &max_correlation);
223 I_score_gold.
getMinMaxLoc(NULL, &max_loc_gold, NULL, &max_correlation_gold);
225 std::cout <<
"Compare regular and SSE version of vpImageTools::normalizedCorrelation()" << std::endl;
226 std::cout <<
"vpImageTools::normalizedCorrelation(): " << max_correlation <<
" ; " << t <<
" ms" << std::endl;
227 std::cout <<
"Gold normalizedCorrelation(): " << max_correlation_gold <<
" ; " << t_gold <<
" ms" << std::endl;
229 std::cerr <<
"\nTrue template position: " << template_roi.getTopLeft() << std::endl;
230 std::cerr <<
"Found template position: " << max_loc << std::endl;
232 std::cerr <<
"Issue with vpImageTools::normalizedCorrelation:" << std::endl;
237 std::cerr <<
"\nCatch an exception: " << e << std::endl;
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static bool equal(double x, double y, double s=0.001)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
error that can be emited by ViSP classes.
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void open(vpImage< vpRGBa > &I)
void resize(const unsigned int h, const unsigned int w)
resize the image : Image initialization
void setFileName(const char *filename)
unsigned int getHeight() const
Defines a rectangle in the plane.
void getMinMaxLoc(vpImagePoint *minLoc, vpImagePoint *maxLoc, Type *minVal=NULL, Type *maxVal=NULL) const
Get the position of the minimum and/or the maximum pixel value within the bitmap and the correspondin...
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)