36 #include <visp3/core/vpImageTools.h>
37 #include <visp3/core/vpIoTools.h>
38 #include <visp3/io/vpImageIo.h>
39 #include <visp3/io/vpParseArgv.h>
51 #define GETOPTARGS "cdi:o:h"
64 void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
65 const std::string &user)
68 Read an image from the disk (Klimt.pgm and klimp.ppm), crop a rectangular area\n\
69 and check the resultings images.\n\
72 %s [-i <input image path>] [-o <output image path>] [-h]\n",
77 -i <input image path> %s\n\
78 Set image input path.\n\
79 From this path read \"Klimt/Klimt.pgm\"\n\
81 Setting the VISP_INPUT_IMAGE_PATH environment\n\
82 variable produces the same behaviour than using\n\
85 -o <output image path> %s\n\
86 Set image output path.\n\
87 From this directory, creates the \"%s\"\n\
88 subdirectory depending on the username, where \n\
89 resulting images are written.\n\
93 ipath.c_str(), opath.c_str(), user.c_str());
96 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
111 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user)
125 usage(argv[0],
nullptr, ipath, opath, user);
134 usage(argv[0], optarg_, ipath, opath, user);
140 if ((c == 1) || (c == -1)) {
142 usage(argv[0],
nullptr, ipath, opath, user);
143 std::cerr <<
"ERROR: " << std::endl;
144 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
151 int main(
int argc,
const char **argv)
154 std::string env_ipath;
155 std::string opt_ipath;
156 std::string opt_opath;
159 std::string username;
166 if (!env_ipath.empty())
171 opt_opath =
"C:/temp";
180 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
185 if (!opt_ipath.empty())
187 if (!opt_opath.empty())
199 usage(argv[0],
nullptr, ipath, opt_opath, username);
200 std::cerr << std::endl <<
"ERROR:" << std::endl;
201 std::cerr <<
" Cannot create " << opath << std::endl;
202 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
209 if (opt_ipath.empty()) {
210 if (ipath != env_ipath) {
211 std::cout << std::endl <<
"WARNING: " << std::endl;
212 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
213 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
214 <<
" we skip the environment variable." << std::endl;
219 if (opt_ipath.empty() && env_ipath.empty()) {
220 usage(argv[0],
nullptr, ipath, opt_opath, username);
221 std::cerr << std::endl <<
"ERROR:" << std::endl;
222 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
223 <<
" environment variable to specify the location of the " << std::endl
224 <<
" image path where test images are located." << std::endl
234 std::cout <<
"Read image: " << filename << std::endl;
236 std::cout <<
"Image size: " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
238 std::vector<vpImage<unsigned char> > reference;
242 reference.push_back(crop);
244 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
248 reference.push_back(crop);
250 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
254 reference.push_back(crop);
256 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
259 vpRect roi(100, 100, 640, 640);
262 std::cout <<
" Cropped image saved in: " << filename << std::endl;
264 if (crop != reference[0]) {
265 std::cout <<
"Test 1 failed on uchar" << std::endl;
271 std::cout <<
" Cropped image saved in: " << filename << std::endl;
273 if (crop != reference[1]) {
274 std::cout <<
"Test 2 failed on uchar" << std::endl;
280 std::cout <<
" Cropped image saved in: " << filename << std::endl;
282 if (crop != reference[2]) {
283 std::cout <<
"Test 3 failed on uchar" << std::endl;
289 std::cout <<
" Cropped image saved in: " << filename << std::endl;
291 if (crop != reference[0]) {
292 std::cout <<
"Test 4 failed on uchar" << std::endl;
298 std::cout <<
" Cropped image saved in: " << filename << std::endl;
300 if (crop != reference[1]) {
301 std::cout <<
"Test 5 failed on uchar" << std::endl;
307 std::cout <<
" Cropped image saved in: " << filename << std::endl;
309 if (crop != reference[2]) {
310 std::cout <<
"Test 6 failed on uchar" << std::endl;
320 std::cout <<
"Read image: " << filename << std::endl;
322 std::cout <<
"Image size: " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
326 std::vector<vpImage<vpRGBa> > reference;
329 reference.push_back(crop);
331 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
335 reference.push_back(crop);
337 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
341 reference.push_back(crop);
343 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
346 vpRect roi(100, 100, 640, 640);
349 std::cout <<
" Cropped image saved in: " << filename << std::endl;
351 if (crop != reference[0]) {
352 std::cout <<
"Test 1 failed on uchar" << std::endl;
358 std::cout <<
" Cropped image saved in: " << filename << std::endl;
360 if (crop != reference[1]) {
361 std::cout <<
"Test 2 failed on uchar" << std::endl;
367 std::cout <<
" Cropped image saved in: " << filename << std::endl;
369 if (crop != reference[2]) {
370 std::cout <<
"Test 3 failed on uchar" << std::endl;
376 std::cout <<
" Cropped image saved in: " << filename << std::endl;
378 if (crop != reference[0]) {
379 std::cout <<
"Test 4 failed on uchar" << std::endl;
385 std::cout <<
" Cropped image saved in: " << filename << std::endl;
387 if (crop != reference[1]) {
388 std::cout <<
"Test 5 failed on uchar" << std::endl;
394 std::cout <<
" Cropped image saved in: " << filename << std::endl;
396 if (crop != reference[2]) {
397 std::cout <<
"Test 6 failed on uchar" << std::endl;
402 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.