41 #include <visp3/core/vpConfig.h> 42 #include <visp3/core/vpDebug.h> 51 #if defined(VISP_HAVE_DIRECTSHOW) 52 #if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 54 #include <visp3/core/vpImage.h> 55 #include <visp3/core/vpTime.h> 56 #include <visp3/gui/vpDisplayGDI.h> 57 #include <visp3/gui/vpDisplayGTK.h> 58 #include <visp3/io/vpImageIo.h> 59 #include <visp3/io/vpParseArgv.h> 60 #include <visp3/sensor/vpDirectShowGrabber.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,
unsigned &nframes,
bool &save, std::string &opath)
132 nframes = atoi(optarg);
139 usage(argv[0], NULL, nframes, opath);
144 usage(argv[0], optarg, nframes, opath);
150 if ((c == 1) || (c == -1)) {
152 usage(argv[0], NULL, nframes, opath);
153 std::cerr <<
"ERROR: " << std::endl;
154 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
169 int main(
int argc,
const char **argv)
172 bool opt_display =
true;
173 unsigned nframes = 50;
187 std::string opath =
"C:/temp/I%04d.ppm";
190 std::string opath =
"C:/temp/I%04d.pgm";
194 if (getOptions(argc, argv, opt_display, nframes, save, opath) ==
false) {
202 vpCTRACE <<
"there is no camera detected on your computer." << std::endl;
212 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: " << I.
getHeight() << std::endl;
215 #if defined VISP_HAVE_GTK 217 #elif defined VISP_HAVE_GDI 222 display.
init(I, 100, 100,
"DirectShow Framegrabber");
225 double tbegin = 0, ttotal = 0;
230 for (
unsigned i = 0; i < nframes; i++) {
241 char buf[FILENAME_MAX];
242 sprintf(buf, opath.c_str(), i);
243 std::string filename(buf);
244 std::cout <<
"Write: " << filename << std::endl;
248 double tloop = tend - tbegin;
250 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
253 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
254 std::cout <<
"Mean frequency: " << 1000. / (ttotal / nframes) <<
" fps" << std::endl;
260 std::cout <<
"Catch an exception: " << e << std::endl;
264 #else // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 266 int main() {
vpTRACE(
"GDI or GTK is not available..."); }
267 #endif // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 268 #else // defined (VISP_HAVE_DIRECTSHOW) 269 int main() {
vpTRACE(
"DirectShow is not available..."); }
270 #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