40 #include <visp3/core/vpConfig.h>
41 #include <visp3/core/vpDebug.h>
52 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK))
54 #include <visp3/core/vpDisplay.h>
55 #include <visp3/gui/vpDisplayX.h>
56 #include <visp3/gui/vpDisplayGTK.h>
57 #include <visp3/core/vpImage.h>
58 #include <visp3/io/vpImageIo.h>
59 #include <visp3/core/vpTime.h>
60 #include <visp3/io/vpParseArgv.h>
61 #include <visp3/sensor/vpV4l2Grabber.h>
64 #define GETOPTARGS "df:i:hn:o:p:s:t:v:x"
87 void usage(
const char *name,
const char *badparam,
unsigned fps,
88 unsigned input,
unsigned scale,
long niter,
char *device,
90 const vpImage_type &image_type,
const std::string &opath)
93 Grab grey level images using the Video For Linux Two framegrabber. \n\
94 Display these images using X11 or GTK.\n\
97 %s [-v <video device>] [-f <fps=25|50>] \n\
98 [-i <input=0|1|2|3> [-s <scale=1|2|4>] [-p <pixel format>]\n\
99 [-n <niter>] [-t <image type>] [-o <filename>] [-x] [-d] [-h]\n", name);
103 -v <video device> %s\n\
104 Video device to access to the camera\n\
107 Framerate in term od number of images per second.\n\
108 Possible values are 25 (for 25Hz) or 50 (for %%) Hz)\n\
111 Framegrabber active input. Values can be 0, 1, 2, 4\n\
113 -p <pixel format> %d\n\
114 Camera pixel format. Values must be in [0-%d]:\n\
116 1 for RGB24 format\n\
117 2 for RGB32 format\n\
118 3 for BGR24 format\n\
121 -t <image type> %d\n\
122 Kind of images that are acquired/displayed by ViSP. \n\
123 Values must be in [0-1]:\n\
124 0 for grey images in unsigned char \n\
125 1 for color images in vpRGBa\n\
128 Framegrabber subsampling factor. \n\
129 If 1, full resolution image acquisition.\n\
130 If 2, half resolution image acquisition. The \n\
131 subsampling is achieved by the hardware.\n\
134 Number of images to acquire.\n\
137 Turn off the display.\n\
140 Activates the extra verbose mode.\n\
142 -o [%%s] : Filename for image saving. \n\
144 The %%d is for the image numbering. The format is set \n\
145 by the extension of the file (ex .png, .pgm, ...) \n\
148 Print the help.\n\n",
149 device, fps, input, pixelformat,
153 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
177 bool getOptions(
int argc,
const char **argv,
unsigned &fps,
unsigned &input,
178 unsigned &scale,
bool &display,
bool &verbose,
179 long &niter,
char *device,
181 vpImage_type &image_type,
bool &save, std::string &opath)
188 case 'd': display =
false;
break;
189 case 'f': fps = (unsigned) atoi(optarg_);
break;
190 case 'i': input = (unsigned) atoi(optarg_);
break;
191 case 'n': niter = atol(optarg_);
break;
194 opath = optarg_;
break;
196 case 's': scale = (unsigned) atoi(optarg_);
break;
197 case 't': image_type = (vpImage_type) atoi(optarg_);
break;
198 case 'v': sprintf(device,
"%s", optarg_);
break;
199 case 'x': verbose =
true;
break;
200 case 'h': usage(argv[0], NULL, fps, input, scale, niter,
201 device, pixelformat, image_type, opath);
205 usage(argv[0], optarg_, fps, input, scale, niter,
206 device, pixelformat, image_type, opath);
return false;
break;
210 if ((c == 1) || (c == -1)) {
212 usage(argv[0], NULL, fps, input, scale, niter,
213 device, pixelformat, image_type, opath);
214 std::cerr <<
"ERROR: " << std::endl;
215 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
232 main(
int argc,
const char ** argv)
235 unsigned int opt_fps = 25;
236 unsigned int opt_input = 0;
237 unsigned int opt_scale = 1;
240 bool opt_verbose =
false;
241 bool opt_display =
true;
243 bool opt_save =
false;
244 sprintf(opt_device,
"/dev/video0");
246 std::string opt_opath =
"/tmp/I%04d.ppm";
248 vpImage_type opt_image_type = color_image;
251 if (getOptions(argc, argv, opt_fps, opt_input, opt_scale, opt_display,
252 opt_verbose, opt_iter, opt_device,
253 opt_pixelformat, opt_image_type, opt_save, opt_opath) ==
false) {
277 if (opt_image_type == grey_image) {
282 std::cout <<
"Grey image size: width : " << Ig.
getWidth() <<
" height: "
290 std::cout <<
"Color image size: width : " << Ic.
getWidth() <<
" height: "
297 #if defined VISP_HAVE_X11
299 #elif defined VISP_HAVE_GTK
309 if (opt_image_type == grey_image) {
310 display.
init(Ig, 100, 100,
"V4L2 grey images framegrabbing") ;
315 display.
init(Ic, 100, 100,
"V4L2 color images framegrabbing") ;
322 while(cpt ++ < opt_iter)
327 if (opt_image_type == grey_image) {
347 char buf[FILENAME_MAX];
348 sprintf(buf, opt_opath.c_str(), cpt);
349 std::string filename(buf);
350 std::cout <<
"Write: " << filename << std::endl;
351 if (opt_image_type == grey_image) {
367 std::cout <<
"Catch an exception: " << e << std::endl;
375 vpTRACE(
"X11 or GTK display are not available") ;
382 vpTRACE(
"Video 4 Linux 2 frame grabber drivers are not available") ;
static void write(const vpImage< unsigned char > &I, const char *filename)
void acquire(vpImage< unsigned char > &I)
void open(vpImage< unsigned char > &I)
unsigned int getWidth() const
Define the X11 console to display images.
void setDevice(const std::string &devname)
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void setVerboseMode(bool verbose)
static void flush(const vpImage< unsigned char > &I)
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+ library version 1.2.
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
void setInput(unsigned input=vpV4l2Grabber::DEFAULT_INPUT)
VISP_EXPORT double measureTimeMs()
Class for the Video4Linux2 video device.
unsigned int getHeight() const
void setPixelFormat(vpV4l2PixelFormatType pixelformat)
void setFramerate(vpV4l2FramerateType framerate)