51 #include <visp3/core/vpDebug.h> 52 #include <visp3/core/vpConfig.h> 53 #include <visp3/io/vpParseArgv.h> 54 #include <visp3/core/vpIoTools.h> 59 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) 61 #include <visp3/core/vpImage.h> 62 #include <visp3/io/vpImageIo.h> 64 #include <visp3/gui/vpDisplayGTK.h> 65 #include <visp3/gui/vpDisplayX.h> 66 #include <visp3/gui/vpDisplayGDI.h> 68 #include <visp3/core/vpTime.h> 81 #define GETOPTARGS "di:p:hf:n:s:w" 83 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
84 unsigned first,
unsigned nimages,
unsigned step);
85 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
86 unsigned &first,
unsigned &nimages,
unsigned &step,
bool &display,
bool &wait);
101 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
102 unsigned first,
unsigned nimages,
unsigned step)
105 Read an image sequence from the disk and display it.\n\ 106 The sequence is made of separate images. Each image corresponds\n\ 110 %s [-i <test image path>] [-p <personal image path>]\n\ 111 [-f <first image>] [-n <number of images>] [-s <step>] \n\ 117 -i <test image path> %s\n\ 118 Set image input path.\n\ 119 From this path read \"ViSP-images/cube/image.%%04d.pgm\"\n\ 120 images. These images come from ViSP-images-x.y.z.tar.gz\n\ 121 available on the ViSP website.\n\ 122 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 123 variable produces the same behaviour than using\n\ 126 -p <personal image path> %s\n\ 127 Specify a personal sequence containing images \n\ 129 By image sequence, we mean one file per image.\n\ 130 The following image file formats PNM (PGM P5, PPM P6)\n\ 131 are supported. The format is selected by analysing \n\ 132 the filename extension.\n\ 133 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\ 134 %%04d is for the image numbering.\n\ 136 -f <first image> %u\n\ 137 First image number of the sequence.\n\ 139 -n <number of images> %u\n\ 140 Number of images to load from the sequence.\n\ 143 Step between two images.\n\ 146 Disable the image display. This can be useful \n\ 147 for automatic tests using crontab under Unix or \n\ 148 using the task manager under Windows.\n\ 151 Wait for a mouse click between two images.\n\ 152 If the image display is disabled (using -d)\n\ 153 this option is without effect.\n\ 156 Print the help.\n\n",
157 ipath.c_str(),ppath.c_str(), first, nimages, step);
160 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
183 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
184 unsigned &first,
unsigned &nimages,
unsigned &step,
bool &display,
bool &wait)
191 case 'd': display =
false;
break;
192 case 'i': ipath = optarg_;
break;
193 case 'p': ppath = optarg_;
break;
194 case 'f': first = (unsigned) atoi(optarg_);
break;
195 case 'n': nimages = (unsigned) atoi(optarg_);
break;
196 case 's': step = (unsigned) atoi(optarg_);
break;
197 case 'w': wait =
true;
break;
198 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step);
202 usage(argv[0], optarg_, ipath, ppath, first, nimages, step);
207 if ((c == 1) || (c == -1)) {
209 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
210 std::cerr <<
"ERROR: " << std::endl;
211 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
219 main(
int argc,
const char ** argv)
222 std::string env_ipath;
223 std::string opt_ipath;
225 std::string opt_ppath;
227 std::string filename;
228 unsigned opt_first = 0;
229 unsigned opt_nimages = 80;
230 unsigned opt_step = 1;
231 bool opt_display =
true;
232 bool opt_wait =
false;
238 if (! env_ipath.empty())
242 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
243 opt_step, opt_display, opt_wait) ==
false) {
251 if (!opt_ipath.empty())
256 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
257 if (ipath != env_ipath) {
258 std::cout << std::endl
259 <<
"WARNING: " << std::endl;
260 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 261 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
262 <<
" we skip the environment variable." << std::endl;
267 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
268 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
269 std::cerr << std::endl
270 <<
"ERROR:" << std::endl;
271 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " 273 <<
" environment variable to specify the location of the " << std::endl
274 <<
" image path where test images are located." << std::endl
275 <<
" Use -p <personal image path> option if you want to "<<std::endl
276 <<
" use personal images." << std::endl
287 unsigned iter = opt_first;
288 std::ostringstream s;
289 char cfilename[FILENAME_MAX];
291 if (opt_ppath.empty()){
311 s.setf(std::ios::right, std::ios::adjustfield);
312 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
316 sprintf(cfilename,opt_ppath.c_str(), iter) ;
317 filename = cfilename;
334 std::cerr << std::endl
335 <<
"ERROR:" << std::endl;
336 std::cerr <<
" Cannot read " << filename << std::endl;
337 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
338 <<
" or your -p " << opt_ppath <<
" option " <<std::endl
339 <<
" or VISP_INPUT_IMAGE_PATH environment variable" 344 #if defined VISP_HAVE_GTK 346 #elif defined VISP_HAVE_X11 348 #elif defined VISP_HAVE_GDI 355 display.
init(I, 100, 100,
"Display...") ;
369 while (iter < opt_first + opt_nimages*opt_step) {
374 if (opt_ppath.empty()){
376 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
380 sprintf(cfilename, opt_ppath.c_str(), iter) ;
381 filename = cfilename;
384 std::cout <<
"read : " << filename << std::endl;
395 std::cout <<
"A click in the image to continue..." << std::endl;
413 std::cout <<
"Catch an exception: " << e << std::endl;
421 vpERROR_TRACE(
"You do not have X11 or GTK display functionalities...");
VISP_EXPORT int wait(double t0, double t)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void display(const vpImage< unsigned char > &I)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
static void read(vpImage< unsigned char > &I, const std::string &filename)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")