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"
52 void usage(
const char *name,
const char *badparam, std::string ipath);
53 bool getOptions(
int argc,
const char **argv, std::string &ipath);
62 void usage(
const char *name,
const char *badparam, std::string ipath)
65 Test 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);
99 bool getOptions(
int argc,
const char **argv, std::string &ipath)
110 usage(argv[0],
nullptr, ipath);
119 usage(argv[0], optarg_, ipath);
125 if ((c == 1) || (c == -1)) {
127 usage(argv[0],
nullptr, ipath);
128 std::cerr <<
"ERROR: " << std::endl;
129 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
136 int main(
int argc,
const char **argv)
139 std::string env_ipath;
140 std::string opt_ipath;
142 std::string filename;
143 std::string username;
150 if (!env_ipath.empty()) {
158 if (getOptions(argc, argv, opt_ipath) ==
false) {
163 if (!opt_ipath.empty()) {
169 if (!opt_ipath.empty() && !env_ipath.empty()) {
170 if (ipath != env_ipath) {
171 std::cout << std::endl <<
"WARNING: " << std::endl;
172 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
173 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
174 <<
" we skip the environment variable." << std::endl;
179 if (opt_ipath.empty() && env_ipath.empty()) {
180 usage(argv[0],
nullptr, ipath);
181 std::cerr << std::endl <<
"ERROR:" << std::endl;
182 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
183 <<
" environment variable to specify the location of the " << std::endl
184 <<
" image path where test images are located." << std::endl
200 std::cout <<
"\nI_Klimt1=" << I_Klimt1.
getWidth() <<
"x" << I_Klimt1.
getHeight() << std::endl;
201 std::cout <<
"I_Klimt2=" << I_Klimt2.
getWidth() <<
"x" << I_Klimt2.
getHeight() << std::endl;
203 std::cout <<
"\nThe two grayscale images are equal." << std::endl;
204 std::cout <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
205 std::cout <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
208 if (!(I_Klimt1 == I_Klimt2) || (I_Klimt1 != I_Klimt2)) {
209 std::stringstream ss;
210 ss <<
"\nProblem when comparing two grayscale images!\n";
211 ss <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
212 ss <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
218 if (I_Klimt1[I_Klimt1.getHeight() / 2][I_Klimt1.getWidth() / 2] < 255) {
219 I_Klimt1[I_Klimt1.getHeight() / 2][I_Klimt1.getWidth() / 2]++;
222 I_Klimt1[I_Klimt1.getHeight() / 2][I_Klimt1.getWidth() / 2]--;
225 std::cout <<
"\nThe two grayscale images are different." << std::endl;
226 std::cout <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
227 std::cout <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
230 if ((I_Klimt1 == I_Klimt2) || !(I_Klimt1 != I_Klimt2)) {
231 std::stringstream ss;
232 ss <<
"\nProblem when comparing two grayscale images!\n";
233 ss <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
234 ss <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
244 I_color_Klimt2 = I_color_Klimt1;
246 std::cout <<
"\nI_color_Klimt1=" << I_color_Klimt1.
getWidth() <<
"x" << I_color_Klimt1.
getHeight() << std::endl;
247 std::cout <<
"I_color_Klimt2=" << I_color_Klimt2.
getWidth() <<
"x" << I_color_Klimt2.
getHeight() << std::endl;
249 std::cout <<
"\nThe two color images are equal." << std::endl;
250 std::cout <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
251 std::cout <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
254 if (!(I_color_Klimt1 == I_color_Klimt2) || (I_color_Klimt1 != I_color_Klimt2)) {
255 std::stringstream ss;
256 ss <<
"\nProblem when comparing two color images!\n";
257 ss <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
258 ss <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
264 if (I_color_Klimt2[I_color_Klimt2.
getHeight() / 2][I_color_Klimt2.
getWidth() / 2].R < 255) {
265 I_color_Klimt2[I_color_Klimt2.
getHeight() / 2][I_color_Klimt2.
getWidth() / 2].R++;
268 I_color_Klimt2[I_color_Klimt2.
getHeight() / 2][I_color_Klimt2.
getWidth() / 2].R--;
271 std::cout <<
"\nThe two color images are different." << std::endl;
272 std::cout <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
273 std::cout <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
276 if ((I_color_Klimt1 == I_color_Klimt2) || !(I_color_Klimt1 != I_color_Klimt2)) {
277 std::stringstream ss;
278 ss <<
"\nProblem when comparing two color images!\n";
279 ss <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
280 ss <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
287 std::cerr <<
"\nCatch an exception: " << e << std::endl;
291 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)
unsigned int getWidth() const
unsigned int getHeight() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)