44 #include <visp/vpConfig.h>
45 #include <visp/vpDebug.h>
60 #if defined (VISP_HAVE_DIRECTSHOW)
61 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
63 #include <visp/vpDirectShowGrabber.h>
64 #include <visp/vpImage.h>
65 #include <visp/vpImageIo.h>
66 #include <visp/vpDisplayGTK.h>
67 #include <visp/vpDisplayGDI.h>
68 #include <visp/vpParseArgv.h>
69 #include <visp/vpTime.h>
74 #define GETOPTARGS "c:df:hmn:io:st:?"
89 void usage(
const char *name,
const char *badparam,
unsigned int camera,
unsigned int &nframes,
93 fprintf(stderr,
"\nERREUR: Bad parameter [%s]\n", badparam);
96 Acquire images using DirectShow (under Windows only) and display\n\
97 it using GTK or the windows GDI if GTK is not available.\n\
98 For a given camera, mediatype (or video mode) as well as framerate\n\
100 If more than one camera is connected, this example allows also to \n\
101 acquire images from all the cameras.\n\
104 %s [-t <mediatype>] [-f <framerate>] \n\
105 [-c <camera id>] [-m] [-n <frames>] [-i] [-s] [-d] \n\
106 [-o <filename>] [-h]\n\
110 MediaType (or video mode) to set for the active \n\
111 camera. Use -s option so see which are the supported \n\
112 Mediatypes. You can select the active camera \n\
116 Framerate to set for the active camera.\n\
117 You can select the active camera using -c option.\n",
122 Active camera identifier.\n\
123 Zero is for the first camera found on the bus.\n\
126 Flag to active multi camera acquisition. \n\
127 You need at least two cameras connected on the bus.\n\
130 Number of frames to acquire.\n\
133 Flag to print camera information.\n\
136 Print camera settings capabilities such as MediaType \n\
137 and sizes available and exit.\n\
140 Flag to turn off image display.\n\
143 Filename for image saving. \n\
145 The first %%d is for the camera id, %%04d\n\
146 is for the image numbering.\n\
151 camera, nframes, opath.c_str());
181 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
182 unsigned int &nframes,
bool &verbose_info,
183 bool &verbose_settings,
184 bool &mediatype_is_set,
185 unsigned int &mediatypeID,
186 bool &framerate_is_set,
188 bool &display,
bool &save, std::string &opath)
199 camera = atoi(optarg);
break;
201 display =
false;
break;
203 framerate_is_set =
true;
204 framerate = atoi(optarg);
break;
206 verbose_info =
true;
break;
210 nframes = atoi(optarg);
break;
213 opath = optarg;
break;
215 verbose_settings =
true;
break;
217 mediatype_is_set =
true;
218 mediatypeID = atoi(optarg);
break;
220 usage(argv[0], NULL, camera, nframes, opath);
225 if ((c == 1) || (c == -1)) {
227 usage(argv[0], NULL, camera, nframes, opath);
228 std::cerr <<
"ERROR: " << std::endl;
229 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
243 main(
int argc,
const char ** argv)
246 unsigned int camera = 0;
248 bool verbose_info =
false;
249 bool verbose_settings =
false;
251 unsigned int nframes = 50;
252 bool mediatype_is_set =
false;
253 unsigned int mediatypeID;
254 bool framerate_is_set =
false;
260 std::string opath =
"C:/temp/I%d-%04d.ppm";
263 std::string opath =
"C:/temp/I%d-%04d.pgm";
265 #if defined VISP_HAVE_GDI
267 #elif defined VISP_HAVE_GTK
270 read_options(argc, argv, multi, camera, nframes,
271 verbose_info, verbose_settings,
272 mediatype_is_set, mediatypeID,
273 framerate_is_set, framerate,
274 display, save, opath);
284 std::cout <<
"You have only " << ncameras <<
" camera connected on the bus." << std::endl;
285 std::cout <<
"It is not possible to active multi-camera acquisition." << std::endl;
286 std::cout <<
"Disable -m command line option, or connect an other " << std::endl;
287 std::cout <<
"cameras on the bus." << std::endl;
292 if (camera >= ncameras) {
293 std::cout <<
"You have only " << ncameras;
294 std::cout <<
" camera connected on the bus." << std::endl;
295 std::cout <<
"It is not possible to select camera " << camera << std::endl;
296 std::cout <<
"Check your -c <camera> command line option." << std::endl;
305 for(
unsigned int i=0; i<ncameras ; i++)
335 if (mediatype_is_set) {
342 if (framerate_is_set) {
343 for(
unsigned int i=0; i<ncameras ; i++)
348 std::cout<<
"camera " << c <<std::endl;
349 if (!g[i].setFramerate(framerate))
350 std::cout <<
"Set Framerate failed !!" <<std::endl<< std::endl;
358 if (verbose_info || verbose_settings) {
360 std::cout <<
"----------------------------------------------------------" << std::endl;
361 std::cout <<
"---- Device List : " << std::endl;
362 std::cout <<
"----------------------------------------------------------" << std::endl;
364 for (
unsigned i=0; i < ncameras; i ++) {
370 g[i].
getFormat(width, height, framerate);
371 std::cout <<
"----------------------------------------------------------"
373 <<
"---- MediaType and framerate currently used by device " << std::endl
374 <<
"---- (or camera) " << c << std::endl
375 <<
"---- Current MediaType : " << g[i].
getMediaType() << std::endl
376 <<
"---- Current format : " << width <<
" x "<< height <<
" at "<< framerate <<
" fps" << std::endl
377 <<
"----------------------------------------------------------" << std::endl;
379 if (verbose_settings) {
380 std::cout <<
"----------------------------------------------------------"
382 <<
"---- MediaTypes supported by device (or camera) "
384 <<
"---- One of the MediaType below can be set using " << std::endl
385 <<
"---- option -t <mediatype>."
387 <<
"----------------------------------------------------------"
398 for (
unsigned int i=0; i < ncameras; i ++) {
405 std::cout <<
"Image size for camera " << c <<
" : width: "
411 sprintf(title,
"Images captured by camera %u", c );
412 d[i].
init(I[i], 100+i*50, 100+i*50, title) ;
417 std::cout <<
"Capture in process..." << std::endl;
419 double tbegin=0, tend=0, tloop=0, ttotal=0;
423 for (
unsigned i = 0; i < nframes; i++) {
424 for (
unsigned c = 0; c < ncameras; c++) {
433 char buf[FILENAME_MAX];
434 sprintf(buf, opath.c_str(), c, i);
435 std::string filename(buf);
436 std::cout <<
"Write: " << filename << std::endl;
441 tloop = tend - tbegin;
443 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
447 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
448 std::cout <<
"Mean frequency: " << 1000./(ttotal / nframes) <<
" fps" << std::endl;
460 vpCERROR <<
"Failure: exit" << std::endl;
463 std::cout <<
" the end" << std::endl;
465 #else // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
470 vpTRACE(
"GDI or GTK is not available...") ;
472 #endif // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
473 #else // defined (VISP_HAVE_DIRECTSHOW)
477 vpTRACE(
"DirectShow is not available...") ;
479 #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)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
static double measureTimeMs()
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.
bool getStreamCapabilities()
unsigned int getDeviceNumber()
unsigned int getHeight() const