43 #include <visp3/core/vpImage.h>
44 #include <visp3/core/vpIoTools.h>
45 #include <visp3/io/vpImageIo.h>
46 #include <visp3/io/vpParseArgv.h>
49 #define GETOPTARGS "cdi:h"
51 void usage(
const char *name,
const char *badparam, std::string ipath);
52 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\
74 -i <input image path> %s\n\
75 Set image input path.\n\
76 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
77 and \"ViSP-images/Klimt/Klimt.ppm\" images.\n\
78 Setting the VISP_INPUT_IMAGE_PATH environment\n\
79 variable produces the same behaviour than using\n\
87 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
98 bool getOptions(
int argc,
const char **argv, std::string &ipath)
105 case 'i': ipath = optarg_;
break;
106 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
113 usage(argv[0], optarg_, ipath);
return false;
break;
117 if ((c == 1) || (c == -1)) {
119 usage(argv[0], NULL, ipath);
120 std::cerr <<
"ERROR: " << std::endl;
121 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
128 int main(
int argc,
const char ** argv) {
130 std::string env_ipath;
131 std::string opt_ipath;
133 std::string filename;
134 std::string username;
140 if (! env_ipath.empty()) {
148 if (getOptions(argc, argv, opt_ipath) ==
false) {
153 if (!opt_ipath.empty()) {
159 if (!opt_ipath.empty() && !env_ipath.empty()) {
160 if (ipath != env_ipath) {
161 std::cout << std::endl
162 <<
"WARNING: " << std::endl;
163 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
164 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
165 <<
" we skip the environment variable." << std::endl;
170 if (opt_ipath.empty() && env_ipath.empty()) {
171 usage(argv[0], NULL, ipath);
172 std::cerr << std::endl
173 <<
"ERROR:" << std::endl;
174 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
176 <<
" environment variable to specify the location of the " << std::endl
177 <<
" image path where test images are located." << std::endl << std::endl;
192 std::cout <<
"\nI_Klimt1=" << I_Klimt1.
getWidth() <<
"x" << I_Klimt1.
getHeight() << std::endl;
193 std::cout <<
"I_Klimt2=" << I_Klimt2.
getWidth() <<
"x" << I_Klimt2.
getHeight() << std::endl;
195 std::cout <<
"\nThe two grayscale images are equal." << std::endl;
196 std::cout <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
197 std::cout <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
200 if ( !(I_Klimt1 == I_Klimt2) || (I_Klimt1 != I_Klimt2) ) {
201 std::stringstream ss;
202 ss <<
"\nProblem when comparing two grayscale images!\n";
203 ss <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
204 ss <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
210 if (I_Klimt1[I_Klimt1.getHeight()/2][I_Klimt1.getWidth()/2] < 255) {
211 I_Klimt1[I_Klimt1.getHeight()/2][I_Klimt1.getWidth()/2]++;
213 I_Klimt1[I_Klimt1.getHeight()/2][I_Klimt1.getWidth()/2]--;
216 std::cout <<
"\nThe two grayscale images are different." << std::endl;
217 std::cout <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
218 std::cout <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
221 if ( (I_Klimt1 == I_Klimt2) || !(I_Klimt1 != I_Klimt2) ) {
222 std::stringstream ss;
223 ss <<
"\nProblem when comparing two grayscale images!\n";
224 ss <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
225 ss <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
236 I_color_Klimt2 = I_color_Klimt1;
238 std::cout <<
"\nI_color_Klimt1=" << I_color_Klimt1.
getWidth() <<
"x" << I_color_Klimt1.
getHeight() << std::endl;
239 std::cout <<
"I_color_Klimt2=" << I_color_Klimt2.
getWidth() <<
"x" << I_color_Klimt2.
getHeight() << std::endl;
241 std::cout <<
"\nThe two color images are equal." << std::endl;
242 std::cout <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
243 std::cout <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
246 if ( !(I_color_Klimt1 == I_color_Klimt2) || (I_color_Klimt1 != I_color_Klimt2) ) {
247 std::stringstream ss;
248 ss <<
"\nProblem when comparing two color images!\n";
249 ss <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
250 ss <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
256 if (I_color_Klimt2[I_color_Klimt2.
getHeight()/2][I_color_Klimt2.
getWidth()/2].R < 255) {
262 std::cout <<
"\nThe two color images are different." << std::endl;
263 std::cout <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
264 std::cout <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
267 if ( (I_color_Klimt1 == I_color_Klimt2) || !(I_color_Klimt1 != I_color_Klimt2) ) {
268 std::stringstream ss;
269 ss <<
"\nProblem when comparing two color images!\n";
270 ss <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
271 ss <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
277 std::cerr <<
"\nCatch an exception: " << e << std::endl;
281 std::cout <<
"\nThe comparison of two images of the same type is OK!" << std::endl;
unsigned int getWidth() const
error that can be emited by ViSP classes.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void read(vpImage< unsigned char > &I, const std::string &filename)
unsigned int getHeight() const