44 #include <visp3/core/vpImage.h> 45 #include <visp3/core/vpIoTools.h> 46 #include <visp3/io/vpImageIo.h> 47 #include <visp3/io/vpParseArgv.h> 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\ 74 -i <input image path> %s\n\ 75 Set image input path.\n\ 76 From this path read \"Klimt/Klimt.pgm\"\n\ 77 and \"Klimt/Klimt.ppm\" images.\n\ 78 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 79 variable produces the same behaviour than using\n\ 83 Print the help.\n\n", ipath.c_str());
86 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
97 bool getOptions(
int argc,
const char **argv, std::string &ipath)
108 usage(argv[0], NULL, ipath);
117 usage(argv[0], optarg_, ipath);
123 if ((c == 1) || (c == -1)) {
125 usage(argv[0], NULL, ipath);
126 std::cerr <<
"ERROR: " << std::endl;
127 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
134 int main(
int argc,
const char **argv)
137 std::string env_ipath;
138 std::string opt_ipath;
140 std::string filename;
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], NULL, 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]++;
219 I_Klimt1[I_Klimt1.getHeight() / 2][I_Klimt1.getWidth() / 2]--;
222 std::cout <<
"\nThe two grayscale images are different." << std::endl;
223 std::cout <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
224 std::cout <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
227 if ((I_Klimt1 == I_Klimt2) || !(I_Klimt1 != I_Klimt2)) {
228 std::stringstream ss;
229 ss <<
"\nProblem when comparing two grayscale images!\n";
230 ss <<
"(I_Klimt1 == I_Klimt2)=" << (I_Klimt1 == I_Klimt2) << std::endl;
231 ss <<
"(I_Klimt1 != I_Klimt2)=" << (I_Klimt1 != I_Klimt2) << std::endl;
241 I_color_Klimt2 = I_color_Klimt1;
243 std::cout <<
"\nI_color_Klimt1=" << I_color_Klimt1.
getWidth() <<
"x" << I_color_Klimt1.
getHeight() << std::endl;
244 std::cout <<
"I_color_Klimt2=" << I_color_Klimt2.
getWidth() <<
"x" << I_color_Klimt2.
getHeight() << std::endl;
246 std::cout <<
"\nThe two color images are equal." << std::endl;
247 std::cout <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
248 std::cout <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
251 if (!(I_color_Klimt1 == I_color_Klimt2) || (I_color_Klimt1 != I_color_Klimt2)) {
252 std::stringstream ss;
253 ss <<
"\nProblem when comparing two color images!\n";
254 ss <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
255 ss <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
261 if (I_color_Klimt2[I_color_Klimt2.
getHeight() / 2][I_color_Klimt2.
getWidth() / 2].R < 255) {
262 I_color_Klimt2[I_color_Klimt2.
getHeight() / 2][I_color_Klimt2.
getWidth() / 2].R++;
264 I_color_Klimt2[I_color_Klimt2.
getHeight() / 2][I_color_Klimt2.
getWidth() / 2].R--;
267 std::cout <<
"\nThe two color images are different." << std::endl;
268 std::cout <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
269 std::cout <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
272 if ((I_color_Klimt1 == I_color_Klimt2) || !(I_color_Klimt1 != I_color_Klimt2)) {
273 std::stringstream ss;
274 ss <<
"\nProblem when comparing two color images!\n";
275 ss <<
"(I_color_Klimt1 == I_color_Klimt2)=" << (I_color_Klimt1 == I_color_Klimt2) << std::endl;
276 ss <<
"(I_color_Klimt1 != I_color_Klimt2)=" << (I_color_Klimt1 != I_color_Klimt2) << std::endl;
282 std::cerr <<
"\nCatch an exception: " << e << std::endl;
286 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