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)
171 bool opt_display =
true;
172 unsigned nframes = 50;
186 std::string opath =
"C:/temp/I%04d.ppm";
189 std::string opath =
"C:/temp/I%04d.pgm";
193 if (getOptions(argc, argv, opt_display, nframes, save, opath) ==
false) {
202 vpCTRACE <<
"there is no camera detected on your computer." << std::endl ;
213 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: "
217 #if defined VISP_HAVE_GTK
219 #elif defined VISP_HAVE_GDI
224 display.
init(I,100,100,
"DirectShow Framegrabber");
227 double tbegin=0, tend=0, tloop=0, ttotal=0;
232 for (
unsigned i = 0; i < nframes; i++) {
243 char buf[FILENAME_MAX];
244 sprintf(buf, opath.c_str(), i);
245 std::string filename(buf);
246 std::cout <<
"Write: " << filename << std::endl;
250 tloop = tend - tbegin;
252 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
255 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
256 std::cout <<
"Mean frequency: " << 1000./(ttotal / nframes) <<
" fps" << std::endl;
263 std::cout <<
"Catch an exception: " << e << std::endl;
267 #else // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
272 vpTRACE(
"GDI or GTK is not available...") ;
274 #endif // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
275 #else // defined (VISP_HAVE_DIRECTSHOW)
279 vpTRACE(
"DirectShow is not available...") ;
281 #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).
error that can be emited by ViSP classes.
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