40#include <visp3/core/vpImage.h>
41#include <visp3/core/vpIoTools.h>
42#include <visp3/io/vpImageIo.h>
43#include <visp3/io/vpParseArgv.h>
45#ifdef ENABLE_VISP_NAMESPACE
50#define GETOPTARGS "cdi:h"
52void usage(
const char *name,
const char *badparam, std::string ipath);
53bool getOptions(
int argc,
const char **argv, std::string &ipath);
62void usage(
const char *name,
const char *badparam, std::string ipath)
65Test the comparison of two vpImage objects of the same type.\n\
68 %s [-i <input image path>]\n\
75 -i <input image path> %s\n\
76 Set image input path.\n\
77 From this path read \"Klimt/Klimt.pgm\"\n\
78 and \"Klimt/Klimt.ppm\" images.\n\
79 Setting the VISP_INPUT_IMAGE_PATH environment\n\
80 variable produces the same behaviour than using\n\
88 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
99bool getOptions(
int argc,
const char **argv, std::string &ipath)
110 usage(argv[0],
nullptr, ipath);
118 usage(argv[0], optarg_, ipath);
123 if ((c == 1) || (c == -1)) {
125 usage(argv[0],
nullptr, ipath);
126 std::cerr <<
"ERROR: " << std::endl;
127 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
134int main(
int argc,
const char **argv)
137 std::string env_ipath;
138 std::string opt_ipath;
141 std::string username;
148 if (!env_ipath.empty()) {
156 if (getOptions(argc, argv, opt_ipath) ==
false) {
161 if (!opt_ipath.empty()) {
167 if (!opt_ipath.empty() && !env_ipath.empty()) {
168 if (ipath != env_ipath) {
169 std::cout << std::endl <<
"WARNING: " << std::endl;
170 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
171 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
172 <<
" we skip the environment variable." << std::endl;
177 if (opt_ipath.empty() && env_ipath.empty()) {
178 usage(argv[0],
nullptr, ipath);
179 std::cerr << std::endl <<
"ERROR:" << std::endl;
180 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
181 <<
" environment variable to specify the location of the " << std::endl
182 <<
" image path where test images are located." << std::endl
198 std::cout <<
"\nI_Klimt1=" << I_Klimt1.
getWidth() <<
"x" << I_Klimt1.
getHeight() << std::endl;
199 std::cout <<
"I_Klimt2=" << I_Klimt2.
getWidth() <<
"x" << I_Klimt2.
getHeight() << std::endl;
201 std::cout <<
"\nThe two grayscale images are equal." << std::endl;
202 std::cout <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
203 std::cout <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
206 if (!(I_Klimt1 == I_Klimt2) || (I_Klimt1 != I_Klimt2)) {
207 std::stringstream ss;
208 ss <<
"\nProblem when comparing two grayscale images!\n";
209 ss <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
210 ss <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
216 if (I_Klimt1[I_Klimt1.getHeight() / 2][I_Klimt1.getWidth() / 2] < 255) {
217 I_Klimt1[I_Klimt1.getHeight() / 2][I_Klimt1.getWidth() / 2]++;
220 I_Klimt1[I_Klimt1.getHeight() / 2][I_Klimt1.getWidth() / 2]--;
223 std::cout <<
"\nThe two grayscale images are different." << std::endl;
224 std::cout <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
225 std::cout <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
228 if ((I_Klimt1 == I_Klimt2) || !(I_Klimt1 != I_Klimt2)) {
229 std::stringstream ss;
230 ss <<
"\nProblem when comparing two grayscale images!\n";
231 ss <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
232 ss <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
242 I_color_Klimt2 = I_color_Klimt1;
244 std::cout <<
"\nI_color_Klimt1=" << I_color_Klimt1.
getWidth() <<
"x" << I_color_Klimt1.
getHeight() << std::endl;
245 std::cout <<
"I_color_Klimt2=" << I_color_Klimt2.
getWidth() <<
"x" << I_color_Klimt2.
getHeight() << std::endl;
247 std::cout <<
"\nThe two color images are equal." << std::endl;
248 std::cout <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
249 std::cout <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
252 if (!(I_color_Klimt1 == I_color_Klimt2) || (I_color_Klimt1 != I_color_Klimt2)) {
253 std::stringstream ss;
254 ss <<
"\nProblem when comparing two color images!\n";
255 ss <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
256 ss <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
262 if (I_color_Klimt2[I_color_Klimt2.
getHeight() / 2][I_color_Klimt2.
getWidth() / 2].R < 255) {
263 I_color_Klimt2[I_color_Klimt2.
getHeight() / 2][I_color_Klimt2.
getWidth() / 2].R++;
266 I_color_Klimt2[I_color_Klimt2.
getHeight() / 2][I_color_Klimt2.
getWidth() / 2].R--;
269 std::cout <<
"\nThe two color images are different." << std::endl;
270 std::cout <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
271 std::cout <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
274 if ((I_color_Klimt1 == I_color_Klimt2) || !(I_color_Klimt1 != I_color_Klimt2)) {
275 std::stringstream ss;
276 ss <<
"\nProblem when comparing two color images!\n";
277 ss <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
278 ss <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
285 std::cerr <<
"\nCatch an exception: " <<
e << std::endl;
289 std::cout <<
"\nThe comparison of two images of the same type is OK!" << std::endl;
error that can be emitted by ViSP classes.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
unsigned int getWidth() const
unsigned int getHeight() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)