44 #include <visp/vpConfig.h>
45 #include <visp/vpDebug.h>
54 #if defined (VISP_HAVE_DIRECTSHOW)
55 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
58 #include <visp/vpDirectShowGrabber.h>
59 #include <visp/vpImage.h>
60 #include <visp/vpImageIo.h>
61 #include <visp/vpDisplayGTK.h>
62 #include <visp/vpDisplayGDI.h>
63 #include <visp/vpParseArgv.h>
64 #include <visp/vpTime.h>
67 #define GETOPTARGS "dhn:o:"
79 void usage(
const char *name,
const char *badparam,
unsigned &nframes, std::string &opath)
82 Acquire images using DirectShow (under Windows only) and display\n\
83 it using GTK or the windows GDI if GTK is not available.\n\
86 %s [-d] [-n] [-o] [-h] \n", name);
91 Turn off the display.\n\
94 Number of frames to acquire. \n\
97 Filename for image saving. \n\
99 The %%d is for the image numbering.\n\
103 \n", nframes, opath.c_str());
105 fprintf(stderr,
"ERROR: \n" );
106 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
125 bool getOptions(
int argc,
const char **argv,
bool &display,
126 unsigned &nframes,
bool &save, std::string &opath)
133 case 'd': display =
false;
break;
135 nframes = atoi(optarg);
break;
138 opath = optarg;
break;
139 case 'h': usage(argv[0], NULL, nframes, opath);
return false;
break;
142 usage(argv[0], optarg, nframes, opath);
147 if ((c == 1) || (c == -1)) {
149 usage(argv[0], NULL, nframes, opath);
150 std::cerr <<
"ERROR: " << std::endl;
151 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
168 main(
int argc,
const char ** argv)
170 bool opt_display =
true;
171 unsigned nframes = 50;
185 std::string opath =
"C:/temp/I%04d.ppm";
188 std::string opath =
"C:/temp/I%04d.pgm";
192 if (getOptions(argc, argv, opt_display, nframes, save, opath) ==
false) {
203 vpCTRACE <<
"there is no camera detected on your computer." << std::endl ;
215 if (grabber !=NULL)
delete grabber;
216 vpCTRACE <<
"Cannot acquire an image... " << std::endl ;
220 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: "
224 #if defined VISP_HAVE_GTK
226 #elif defined VISP_HAVE_GDI
231 display.
init(I,100,100,
"DirectShow Framegrabber");
235 double tbegin=0, tend=0, tloop=0, ttotal=0;
240 for (
unsigned i = 0; i < nframes; i++) {
251 char buf[FILENAME_MAX];
252 sprintf(buf, opath.c_str(), i);
253 std::string filename(buf);
254 std::cout <<
"Write: " << filename << std::endl;
258 tloop = tend - tbegin;
260 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
263 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
264 std::cout <<
"Mean frequency: " << 1000./(ttotal / nframes) <<
" fps" << std::endl;
267 if (grabber !=NULL)
delete grabber;
272 vpCERROR <<
"Failure: exit" << std::endl;
273 if (grabber !=NULL)
delete grabber;
277 #else // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
282 vpTRACE(
"GDI or GTK is not available...") ;
284 #endif // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
285 #else // defined (VISP_HAVE_DIRECTSHOW)
289 vpTRACE(
"DirectShow is not available...") ;
291 #endif // defined (VISP_HAVE_DIRECTSHOW)
static void write(const vpImage< unsigned char > &I, const char *filename)
unsigned int getWidth() const
Display for windows using GDI (available on any windows 32 platform).
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)
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.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
unsigned int getDeviceNumber()
unsigned int getHeight() const