43 #include <visp3/core/vpImageTools.h>
44 #include <visp3/core/vpIoTools.h>
45 #include <visp3/io/vpImageIo.h>
46 #include <visp3/io/vpParseArgv.h>
48 #ifdef ENABLE_VISP_NAMESPACE
53 #define GETOPTARGS "cdi:o:h"
66 void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
67 const std::string &user)
70 Read an image from the disk (Klimt.pgm and klimp.ppm), crop a rectangular area\n\
71 and check the resultings images.\n\
74 %s [-i <input image path>] [-o <output image path>] [-h]\n",
79 -i <input image path> %s\n\
80 Set image input path.\n\
81 From this path read \"Klimt/Klimt.pgm\"\n\
83 Setting the VISP_INPUT_IMAGE_PATH environment\n\
84 variable produces the same behaviour than using\n\
87 -o <output image path> %s\n\
88 Set image output path.\n\
89 From this directory, creates the \"%s\"\n\
90 subdirectory depending on the username, where \n\
91 resulting images are written.\n\
95 ipath.c_str(), opath.c_str(), user.c_str());
98 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
113 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user)
127 usage(argv[0],
nullptr, ipath, opath, user);
136 usage(argv[0], optarg_, ipath, opath, user);
142 if ((c == 1) || (c == -1)) {
144 usage(argv[0],
nullptr, ipath, opath, user);
145 std::cerr <<
"ERROR: " << std::endl;
146 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
153 int main(
int argc,
const char **argv)
156 std::string env_ipath;
157 std::string opt_ipath;
158 std::string opt_opath;
161 std::string username;
168 if (!env_ipath.empty())
173 opt_opath =
"C:/temp";
182 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
187 if (!opt_ipath.empty())
189 if (!opt_opath.empty())
202 usage(argv[0],
nullptr, ipath, opt_opath, username);
203 std::cerr << std::endl <<
"ERROR:" << std::endl;
204 std::cerr <<
" Cannot create " << opath << std::endl;
205 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
212 if (opt_ipath.empty()) {
213 if (ipath != env_ipath) {
214 std::cout << std::endl <<
"WARNING: " << std::endl;
215 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
216 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
217 <<
" we skip the environment variable." << std::endl;
222 if (opt_ipath.empty() && env_ipath.empty()) {
223 usage(argv[0],
nullptr, ipath, opt_opath, username);
224 std::cerr << std::endl <<
"ERROR:" << std::endl;
225 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
226 <<
" environment variable to specify the location of the " << std::endl
227 <<
" image path where test images are located." << std::endl
237 std::cout <<
"Read image: " << filename << std::endl;
239 std::cout <<
"Image size: " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
241 std::vector<vpImage<unsigned char> > reference;
245 reference.push_back(crop);
247 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
251 reference.push_back(crop);
253 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
257 reference.push_back(crop);
259 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
262 vpRect roi(100, 100, 640, 640);
265 std::cout <<
" Cropped image saved in: " << filename << std::endl;
267 if (crop != reference[0]) {
268 std::cout <<
"Test 1 failed on uchar" << std::endl;
274 std::cout <<
" Cropped image saved in: " << filename << std::endl;
276 if (crop != reference[1]) {
277 std::cout <<
"Test 2 failed on uchar" << std::endl;
283 std::cout <<
" Cropped image saved in: " << filename << std::endl;
285 if (crop != reference[2]) {
286 std::cout <<
"Test 3 failed on uchar" << std::endl;
292 std::cout <<
" Cropped image saved in: " << filename << std::endl;
294 if (crop != reference[0]) {
295 std::cout <<
"Test 4 failed on uchar" << std::endl;
301 std::cout <<
" Cropped image saved in: " << filename << std::endl;
303 if (crop != reference[1]) {
304 std::cout <<
"Test 5 failed on uchar" << std::endl;
310 std::cout <<
" Cropped image saved in: " << filename << std::endl;
312 if (crop != reference[2]) {
313 std::cout <<
"Test 6 failed on uchar" << std::endl;
323 std::cout <<
"Read image: " << filename << std::endl;
325 std::cout <<
"Image size: " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
329 std::vector<vpImage<vpRGBa> > reference;
332 reference.push_back(crop);
334 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
338 reference.push_back(crop);
340 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
344 reference.push_back(crop);
346 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
349 vpRect roi(100, 100, 640, 640);
352 std::cout <<
" Cropped image saved in: " << filename << std::endl;
354 if (crop != reference[0]) {
355 std::cout <<
"Test 1 failed on uchar" << std::endl;
361 std::cout <<
" Cropped image saved in: " << filename << std::endl;
363 if (crop != reference[1]) {
364 std::cout <<
"Test 2 failed on uchar" << std::endl;
370 std::cout <<
" Cropped image saved in: " << filename << std::endl;
372 if (crop != reference[2]) {
373 std::cout <<
"Test 3 failed on uchar" << std::endl;
379 std::cout <<
" Cropped image saved in: " << filename << std::endl;
381 if (crop != reference[0]) {
382 std::cout <<
"Test 4 failed on uchar" << std::endl;
388 std::cout <<
" Cropped image saved in: " << filename << std::endl;
390 if (crop != reference[1]) {
391 std::cout <<
"Test 5 failed on uchar" << std::endl;
397 std::cout <<
" Cropped image saved in: " << filename << std::endl;
399 if (crop != reference[2]) {
400 std::cout <<
"Test 6 failed on uchar" << std::endl;
405 std::cout <<
"Test succeed" << std::endl;
error that can be emitted by ViSP classes.
const std::string & getStringMessage() const
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
unsigned int getWidth() const
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Defines a rectangle in the plane.