40 #include <visp3/core/vpConfig.h> 41 #include <visp3/core/vpDebug.h> 50 #if defined (VISP_HAVE_DIRECTSHOW) 51 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 54 #include <visp3/sensor/vpDirectShowGrabber.h> 55 #include <visp3/core/vpImage.h> 56 #include <visp3/io/vpImageIo.h> 57 #include <visp3/gui/vpDisplayGTK.h> 58 #include <visp3/gui/vpDisplayGDI.h> 59 #include <visp3/io/vpParseArgv.h> 60 #include <visp3/core/vpTime.h> 63 #define GETOPTARGS "dhn:o:" 75 void usage(
const char *name,
const char *badparam,
unsigned &nframes, std::string &opath)
78 Acquire images using DirectShow (under Windows only) and display\n\ 79 it using GTK or the windows GDI if GTK is not available.\n\ 82 %s [-d] [-n] [-o] [-h] \n", name);
87 Turn off the display.\n\ 90 Number of frames to acquire. \n\ 93 Filename for image saving. \n\ 95 The %%d is for the image numbering.\n\ 99 \n", nframes, opath.c_str());
101 fprintf(stderr,
"ERROR: \n" );
102 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
121 bool getOptions(
int argc,
const char **argv,
bool &display,
122 unsigned &nframes,
bool &save, std::string &opath)
129 case 'd': display =
false;
break;
131 nframes = atoi(optarg);
break;
134 opath = optarg;
break;
135 case 'h': usage(argv[0], NULL, nframes, opath);
return false;
break;
138 usage(argv[0], optarg, nframes, opath);
143 if ((c == 1) || (c == -1)) {
145 usage(argv[0], NULL, nframes, opath);
146 std::cerr <<
"ERROR: " << std::endl;
147 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
164 main(
int argc,
const char ** argv)
167 bool opt_display =
true;
168 unsigned nframes = 50;
182 std::string opath =
"C:/temp/I%04d.ppm";
185 std::string opath =
"C:/temp/I%04d.pgm";
189 if (getOptions(argc, argv, opt_display, nframes, save, opath) ==
false) {
198 vpCTRACE <<
"there is no camera detected on your computer." << std::endl ;
209 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: " 213 #if defined VISP_HAVE_GTK 215 #elif defined VISP_HAVE_GDI 220 display.
init(I,100,100,
"DirectShow Framegrabber");
223 double tbegin=0, ttotal=0;
228 for (
unsigned i = 0; i < nframes; i++) {
239 char buf[FILENAME_MAX];
240 sprintf(buf, opath.c_str(), i);
241 std::string filename(buf);
242 std::cout <<
"Write: " << filename << std::endl;
246 double tloop = tend - tbegin;
248 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
251 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
252 std::cout <<
"Mean frequency: " << 1000./(ttotal / nframes) <<
" fps" << std::endl;
259 std::cout <<
"Catch an exception: " << e << std::endl;
263 #else // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 268 vpTRACE(
"GDI or GTK is not available...") ;
270 #endif // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 271 #else // defined (VISP_HAVE_DIRECTSHOW) 275 vpTRACE(
"DirectShow is not available...") ;
277 #endif // defined (VISP_HAVE_DIRECTSHOW) Display for windows using GDI (available on any windows 32 platform).
error that can be emited by ViSP classes.
class for windows direct show devices
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)
void acquire(vpImage< unsigned char > &I)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
unsigned int getHeight() const
unsigned int getDeviceNumber()
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
unsigned int getWidth() const