35#include <visp3/core/vpConfig.h>
36#include <visp3/core/vpDebug.h>
45#if defined(VISP_HAVE_DIRECTSHOW)
46#if defined(VISP_HAVE_DISPLAY)
48#include <visp3/core/vpImage.h>
49#include <visp3/core/vpTime.h>
50#include <visp3/gui/vpDisplayFactory.h>
51#include <visp3/io/vpImageIo.h>
52#include <visp3/io/vpParseArgv.h>
53#include <visp3/sensor/vpDirectShowGrabber.h>
56#define GETOPTARGS "dhn:o:"
58#ifdef ENABLE_VISP_NAMESPACE
72void usage(
const char *name,
const char *badparam,
unsigned &nframes, std::string &opath)
75Acquire images using DirectShow (under Windows only) and display\n\
76it using GTK or the windows GDI if GTK is not available.\n\
79 %s [-d] [-n] [-o] [-h] \n",
85 Turn off the display.\n\
88 Number of frames to acquire. \n\
91 Filename for image saving. \n\
93 The %%d is for the image numbering.\n\
98nframes, opath.c_str());
100 fprintf(stderr,
"ERROR: \n");
101 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
120bool getOptions(
int argc,
const char **argv,
bool &display,
unsigned &nframes,
bool &save, std::string &opath)
131 nframes = atoi(optarg);
138 usage(argv[0],
nullptr, nframes, opath);
142 usage(argv[0], optarg, nframes, opath);
147 if ((c == 1) || (c == -1)) {
149 usage(argv[0],
nullptr, nframes, opath);
150 std::cerr <<
"ERROR: " << std::endl;
151 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
166int main(
int argc,
const char **argv)
168#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
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 (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
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 snprintf(buf, FILENAME_MAX, opath.c_str(), i);
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;
258#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
259 if (display !=
nullptr) {
266 std::cout <<
"Catch an exception: " <<
e << std::endl;
267#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
268 if (display !=
nullptr) {
279 std::cout <<
"You do not have GDI (Graphical Device Interface), or GTK functionalities to display images..."
281 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
282 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
289 std::cout <<
"This example requires Direct Show SDK. " << std::endl;
290 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
291 std::cout <<
"- Install Direct Show, configure again ViSP using cmake and build again this example" << std::endl;
class for windows direct show devices
void acquire(vpImage< unsigned char > &I)
unsigned int getDeviceNumber()
Class that defines generic functionalities for display.
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()