44 #include <visp/vpDebug.h>
45 #include <visp/vpConfig.h>
47 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK))
49 #include <visp/vpDiskGrabber.h>
50 #include <visp/vpImage.h>
51 #include <visp/vpDisplay.h>
52 #include <visp/vpDisplayX.h>
53 #include <visp/vpDisplayGTK.h>
54 #include <visp/vpTime.h>
55 #include <visp/vpParseArgv.h>
67 #define GETOPTARGS "b:de:f:i:hn:s:z:"
84 void usage(
const char *name,
const char *badparam, std::string ipath, std::string basename,
85 std::string ext,
int first,
unsigned int nimages,
int step,
89 Read an image sequence from the disk. Display it using X11 or GTK.\n\
90 The sequence is made of separate images. Each image corresponds\n\
94 %s [-i <input image path>] [-b <base name>] [-e <extension>] \n\
95 [-f <first frame>] [-n <number of images> [-s <step>] \n\
96 [-z <number of zero>] [-d] [-h]\n", name);
100 -i <input image path> %s\n\
101 Set image input path.\n\
102 From this path read \"ViSP-images/cube/image.%%04d.pgm\"\n\
104 Setting the VISP_INPUT_IMAGE_PATH environment\n\
105 variable produces the same behaviour than using\n\
109 Specify the base name of the files of the sequence\n\
110 containing the images to process. \n\
111 By image sequence, we mean one file per image.\n\
112 The following image file formats PNM (PGM P5, PPM P6)\n\
113 are supported. The format is selected by analysing \n\
114 the filename extension.\n\
117 Specify the extension of the files.\n\
118 Not taken into account for the moment. Will be a\n\
121 -f <first frame> %u\n\
122 First frame number of the sequence\n\
124 -n <number of images> %u\n\
125 Number of images to load from the sequence.\n\
128 Step between two images.\n\
130 -z <number of zero> %u\n\
131 Number of digits to encode the image number.\n\
134 Turn off the display.\n\
137 Print the help.\n\n",
138 ipath.c_str(), basename.c_str(), ext.c_str(), first,
139 nimages, step, nzero);
142 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
162 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &basename,
163 std::string &ext,
int &first,
unsigned int &nimages,
164 int &step,
unsigned int &nzero,
bool &display)
171 case 'b': basename = optarg;
break;
172 case 'd': display =
false;
break;
173 case 'e': ext = optarg;
break;
174 case 'f': first = atoi(optarg);
break;
175 case 'i': ipath = optarg;
break;
176 case 'n': nimages = (unsigned) atoi(optarg);
break;
177 case 's': step = atoi(optarg);
break;
178 case 'z': nzero = (unsigned) atoi(optarg);
break;
179 case 'h': usage(argv[0], NULL, ipath, basename, ext, first, nimages,
180 step, nzero);
return false;
break;
183 usage(argv[0], optarg, ipath, basename, ext, first, nimages,
189 if ((c == 1) || (c == -1)) {
191 usage(argv[0], NULL, ipath, basename, ext, first, nimages, step, nzero);
192 std::cerr <<
"ERROR: " << std::endl;
193 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
211 main(
int argc,
const char ** argv)
213 std::string env_ipath;
214 std::string opt_ipath;
216 std::string opt_basename =
"ViSP-images/cube/image.";
217 std::string opt_ext =
"pgm";
218 bool opt_display =
true;
221 unsigned int opt_nimages = 70;
223 unsigned int opt_nzero = 4;
226 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
231 if (! env_ipath.empty())
235 if (getOptions(argc, argv, opt_ipath, opt_basename, opt_ext, opt_first,
236 opt_nimages, opt_step, opt_nzero, opt_display) ==
false) {
241 if (!opt_ipath.empty())
246 if (!opt_ipath.empty() && !env_ipath.empty()) {
247 if (ipath != env_ipath) {
248 std::cout << std::endl
249 <<
"WARNING: " << std::endl;
250 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
251 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
252 <<
" we skip the environment variable." << std::endl;
257 if (opt_ipath.empty() && env_ipath.empty()){
258 usage(argv[0], NULL, ipath, opt_basename, opt_ext, opt_first,
259 opt_nimages, opt_step, opt_nzero);
260 std::cerr << std::endl
261 <<
"ERROR:" << std::endl;
262 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
264 <<
" environment variable to specify the location of the " << std::endl
265 <<
" image path where test images are located." << std::endl << std::endl;
299 vpERROR_TRACE(
"Cannot open the first image of the sequence... ") ;
303 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: "
308 #if defined VISP_HAVE_X11
310 #elif defined VISP_HAVE_GTK
316 display.
init(I,100,100,
"Disk Framegrabber");
336 while(cpt ++ < opt_nimages)
362 vpERROR_TRACE(
"You do not have X11 or GTK display functionalities...");
unsigned int getWidth() const
void setBaseName(const char *name)
Define the X11 console to display images.
void setDirectory(const char *dir)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
static double measureTimeMs()
static int wait(double t0, double t)
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void setNumberOfZero(unsigned int noz)
static void display(const vpImage< unsigned char > &I)
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void setImageNumber(long number)
void open(vpImage< unsigned char > &I)
Class to grab (ie. read) images from the disk.
void setExtension(const char *ext)
unsigned int getHeight() const
void acquire(vpImage< unsigned char > &I)