41 #include <visp3/core/vpConfig.h> 42 #include <visp3/core/vpDebug.h> 52 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK)) 54 #include <visp3/core/vpDisplay.h> 55 #include <visp3/core/vpImage.h> 56 #include <visp3/core/vpTime.h> 57 #include <visp3/gui/vpDisplayGTK.h> 58 #include <visp3/gui/vpDisplayX.h> 59 #include <visp3/io/vpImageIo.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,
unsigned input,
unsigned scale,
long niter,
89 const std::string &opath)
92 Grab grey level images using the Video For Linux Two framegrabber. \n\ 93 Display these images using X11 or GTK.\n\ 96 %s [-v <video device>] [-f <fps=25|50>] \n\ 97 [-i <input=0|1|2|3> [-s <scale=1|2|4>] [-p <pixel format>]\n\ 98 [-n <niter>] [-t <image type>] [-o <filename>] [-x] [-d] [-h]\n", name);
102 -v <video device> %s\n\ 103 Video device to access to the camera\n\ 106 Framerate in term od number of images per second.\n\ 107 Possible values are 25 (for 25Hz) or 50 (for %%) Hz)\n\ 110 Framegrabber active input. Values can be 0, 1, 2, 4\n\ 112 -p <pixel format> %d\n\ 113 Camera pixel format. Values must be in [0-%d]:\n\ 115 1 for RGB24 format\n\ 116 2 for RGB32 format\n\ 117 3 for BGR24 format\n\ 120 -t <image type> %d\n\ 121 Kind of images that are acquired/displayed by ViSP. \n\ 122 Values must be in [0-1]:\n\ 123 0 for grey images in unsigned char \n\ 124 1 for color images in vpRGBa\n\ 127 Framegrabber subsampling factor. \n\ 128 If 1, full resolution image acquisition.\n\ 129 If 2, half resolution image acquisition. The \n\ 130 subsampling is achieved by the hardware.\n\ 133 Number of images to acquire.\n\ 136 Turn off the display.\n\ 139 Activates the extra verbose mode.\n\ 141 -o [%%s] : Filename for image saving. \n\ 143 The %%d is for the image numbering. The format is set \n\ 144 by the extension of the file (ex .png, .pgm, ...) \n\ 151 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
175 bool getOptions(
int argc,
const char **argv,
unsigned &fps,
unsigned &input,
unsigned &scale,
bool &display,
177 vpImage_type &image_type,
bool &save, std::string &opath)
188 fps = (unsigned)atoi(optarg_);
191 input = (unsigned)atoi(optarg_);
194 niter = atol(optarg_);
204 scale = (unsigned)atoi(optarg_);
207 image_type = (vpImage_type)atoi(optarg_);
210 sprintf(device,
"%s", optarg_);
216 usage(argv[0], NULL, fps, input, scale, niter, device, pixelformat, image_type, opath);
221 usage(argv[0], optarg_, fps, input, scale, niter, device, pixelformat, image_type, opath);
227 if ((c == 1) || (c == -1)) {
229 usage(argv[0], NULL, fps, input, scale, niter, device, pixelformat, image_type, opath);
230 std::cerr <<
"ERROR: " << std::endl;
231 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
247 int main(
int argc,
const char **argv)
250 unsigned int opt_fps = 25;
251 unsigned int opt_input = 0;
252 unsigned int opt_scale = 1;
255 bool opt_verbose =
false;
256 bool opt_display =
true;
258 bool opt_save =
false;
259 sprintf(opt_device,
"/dev/video0");
261 std::string opt_opath =
"/tmp/I%04d.ppm";
263 vpImage_type opt_image_type = color_image;
266 if (getOptions(argc, argv, opt_fps, opt_input, opt_scale, opt_display, opt_verbose, opt_iter, opt_device,
267 opt_pixelformat, opt_image_type, opt_save, opt_opath) ==
false) {
291 if (opt_image_type == grey_image) {
296 std::cout <<
"Grey image size: width : " << Ig.
getWidth() <<
" height: " << Ig.
getHeight() << std::endl;
302 std::cout <<
"Color image size: width : " << Ic.
getWidth() <<
" height: " << Ic.
getHeight() << std::endl;
307 #if defined VISP_HAVE_X11 309 #elif defined VISP_HAVE_GTK 319 if (opt_image_type == grey_image) {
320 display.
init(Ig, 100, 100,
"V4L2 grey images framegrabbing");
324 display.
init(Ic, 100, 100,
"V4L2 color images framegrabbing");
331 while (cpt++ < opt_iter) {
335 if (opt_image_type == grey_image) {
354 char buf[FILENAME_MAX];
355 sprintf(buf, opt_opath.c_str(), cpt);
356 std::string filename(buf);
357 std::cout <<
"Write: " << filename << std::endl;
358 if (opt_image_type == grey_image) {
372 std::cout <<
"Catch an exception: " << e << std::endl;
379 std::cout <<
"You do not have X11, or GTK functionalities to display images..." << std::endl;
380 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
381 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
382 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
383 std::cout <<
"- Install GTK, configure again ViSP using cmake and build again this example" << std::endl;
390 std::cout <<
"You do not have Video 4 Linux 2 functionality enabled" << std::endl;
391 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
392 std::cout <<
"- Install libv4l2, configure again ViSP using cmake and build again this example" << std::endl;
void acquire(vpImage< unsigned char > &I)
void open(vpImage< unsigned char > &I)
unsigned int getWidth() const
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void setDevice(const std::string &devname)
error that can be emited by ViSP classes.
void setVerboseMode(bool verbose)
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 write(const vpImage< unsigned char > &I, const std::string &filename)
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...
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
void setInput(unsigned input=vpV4l2Grabber::DEFAULT_INPUT)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
unsigned int getHeight() const
void setPixelFormat(vpV4l2PixelFormatType pixelformat)
void setFramerate(vpV4l2FramerateType framerate)