41 #include <visp3/core/vpConfig.h>
42 #include <visp3/core/vpDebug.h>
57 #if defined (VISP_HAVE_DIRECTSHOW)
58 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
60 #include <visp3/sensor/vpDirectShowGrabber.h>
61 #include <visp3/core/vpImage.h>
62 #include <visp3/io/vpImageIo.h>
63 #include <visp3/gui/vpDisplayGTK.h>
64 #include <visp3/gui/vpDisplayGDI.h>
65 #include <visp3/io/vpParseArgv.h>
66 #include <visp3/core/vpTime.h>
71 #define GETOPTARGS "c:df:hmn:io:st:?"
86 void usage(
const char *name,
const char *badparam,
unsigned int camera,
unsigned int &nframes,
90 fprintf(stderr,
"\nERREUR: Bad parameter [%s]\n", badparam);
93 Acquire images using DirectShow (under Windows only) and display\n\
94 it using GTK or the windows GDI if GTK is not available.\n\
95 For a given camera, mediatype (or video mode) as well as framerate\n\
97 If more than one camera is connected, this example allows also to \n\
98 acquire images from all the cameras.\n\
101 %s [-t <mediatype>] [-f <framerate>] \n\
102 [-c <camera id>] [-m] [-n <frames>] [-i] [-s] [-d] \n\
103 [-o <filename>] [-h]\n\
107 MediaType (or video mode) to set for the active \n\
108 camera. Use -s option so see which are the supported \n\
109 Mediatypes. You can select the active camera \n\
113 Framerate to set for the active camera.\n\
114 You can select the active camera using -c option.\n",
119 Active camera identifier.\n\
120 Zero is for the first camera found on the bus.\n\
123 Flag to active multi camera acquisition. \n\
124 You need at least two cameras connected on the bus.\n\
127 Number of frames to acquire.\n\
130 Flag to print camera information.\n\
133 Print camera settings capabilities such as MediaType \n\
134 and sizes available and exit.\n\
137 Flag to turn off image display.\n\
140 Filename for image saving. \n\
142 The first %%d is for the camera id, %%04d\n\
143 is for the image numbering.\n\
148 camera, nframes, opath.c_str());
178 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
179 unsigned int &nframes,
bool &verbose_info,
180 bool &verbose_settings,
181 bool &mediatype_is_set,
182 unsigned int &mediatypeID,
183 bool &framerate_is_set,
185 bool &display,
bool &save, std::string &opath)
196 camera = atoi(optarg);
break;
198 display =
false;
break;
200 framerate_is_set =
true;
201 framerate = atoi(optarg);
break;
203 verbose_info =
true;
break;
207 nframes = atoi(optarg);
break;
210 opath = optarg;
break;
212 verbose_settings =
true;
break;
214 mediatype_is_set =
true;
215 mediatypeID = atoi(optarg);
break;
217 usage(argv[0], NULL, camera, nframes, opath);
222 if ((c == 1) || (c == -1)) {
224 usage(argv[0], NULL, camera, nframes, opath);
225 std::cerr <<
"ERROR: " << std::endl;
226 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
240 main(
int argc,
const char ** argv)
243 unsigned int camera = 0;
245 bool verbose_info =
false;
246 bool verbose_settings =
false;
248 unsigned int nframes = 50;
249 bool mediatype_is_set =
false;
250 unsigned int mediatypeID;
251 bool framerate_is_set =
false;
257 std::string opath =
"C:/temp/I%d-%04d.ppm";
260 std::string opath =
"C:/temp/I%d-%04d.pgm";
262 #if defined VISP_HAVE_GDI
264 #elif defined VISP_HAVE_GTK
267 read_options(argc, argv, multi, camera, nframes,
268 verbose_info, verbose_settings,
269 mediatype_is_set, mediatypeID,
270 framerate_is_set, framerate,
271 display, save, opath);
281 std::cout <<
"You have only " << ncameras <<
" camera connected on the bus." << std::endl;
282 std::cout <<
"It is not possible to active multi-camera acquisition." << std::endl;
283 std::cout <<
"Disable -m command line option, or connect an other " << std::endl;
284 std::cout <<
"cameras on the bus." << std::endl;
289 if (camera >= ncameras) {
290 std::cout <<
"You have only " << ncameras;
291 std::cout <<
" camera connected on the bus." << std::endl;
292 std::cout <<
"It is not possible to select camera " << camera << std::endl;
293 std::cout <<
"Check your -c <camera> command line option." << std::endl;
302 for(
unsigned int i=0; i<ncameras ; i++)
332 if (mediatype_is_set) {
339 if (framerate_is_set) {
340 for(
unsigned int i=0; i<ncameras ; i++)
345 std::cout<<
"camera " << c <<std::endl;
346 if (!g[i].setFramerate(framerate))
347 std::cout <<
"Set Framerate failed !!" <<std::endl<< std::endl;
355 if (verbose_info || verbose_settings) {
357 std::cout <<
"----------------------------------------------------------" << std::endl;
358 std::cout <<
"---- Device List : " << std::endl;
359 std::cout <<
"----------------------------------------------------------" << std::endl;
361 for (
unsigned i=0; i < ncameras; i ++) {
367 g[i].
getFormat(width, height, framerate);
368 std::cout <<
"----------------------------------------------------------"
370 <<
"---- MediaType and framerate currently used by device " << std::endl
371 <<
"---- (or camera) " << c << std::endl
372 <<
"---- Current MediaType : " << g[i].
getMediaType() << std::endl
373 <<
"---- Current format : " << width <<
" x "<< height <<
" at "<< framerate <<
" fps" << std::endl
374 <<
"----------------------------------------------------------" << std::endl;
376 if (verbose_settings) {
377 std::cout <<
"----------------------------------------------------------"
379 <<
"---- MediaTypes supported by device (or camera) "
381 <<
"---- One of the MediaType below can be set using " << std::endl
382 <<
"---- option -t <mediatype>."
384 <<
"----------------------------------------------------------"
395 for (
unsigned int i=0; i < ncameras; i ++) {
402 std::cout <<
"Image size for camera " << c <<
" : width: "
408 sprintf(title,
"Images captured by camera %u", c );
409 d[i].
init(I[i], 100+i*50, 100+i*50, title) ;
414 std::cout <<
"Capture in process..." << std::endl;
416 double tbegin=0, tend=0, tloop=0, ttotal=0;
420 for (
unsigned i = 0; i < nframes; i++) {
421 for (
unsigned c = 0; c < ncameras; c++) {
430 char buf[FILENAME_MAX];
431 sprintf(buf, opath.c_str(), c, i);
432 std::string filename(buf);
433 std::cout <<
"Write: " << filename << std::endl;
438 tloop = tend - tbegin;
440 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
444 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
445 std::cout <<
"Mean frequency: " << 1000./(ttotal / nframes) <<
" fps" << std::endl;
458 std::cout <<
"Catch an exception: " << e << std::endl;
462 #else // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
467 vpTRACE(
"GDI or GTK is not available...") ;
469 #endif // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
470 #else // defined (VISP_HAVE_DIRECTSHOW)
474 vpTRACE(
"DirectShow is not available...") ;
476 #endif // defined (VISP_HAVE_DIRECTSHOW)
static void write(const vpImage< unsigned char > &I, const char *filename)
void getFormat(unsigned int &width, unsigned int &height, double &framerate)
unsigned int getWidth() const
Display for windows using GDI (available on any windows 32 platform).
bool setMediaType(int mediaTypeID)
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
class for windows direct show devices
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
bool setDevice(unsigned int id)
static void display(const vpImage< unsigned char > &I)
void acquire(vpImage< unsigned char > &I)
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
VISP_EXPORT double measureTimeMs()
bool getStreamCapabilities()
unsigned int getDeviceNumber()
unsigned int getHeight() const