37 #include <visp3/core/vpConfig.h>
38 #include <visp3/core/vpDebug.h>
47 #if defined(VISP_HAVE_DIRECTSHOW)
48 #if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
50 #include <visp3/core/vpImage.h>
51 #include <visp3/core/vpTime.h>
52 #include <visp3/gui/vpDisplayGDI.h>
53 #include <visp3/gui/vpDisplayGTK.h>
54 #include <visp3/io/vpImageIo.h>
55 #include <visp3/io/vpParseArgv.h>
56 #include <visp3/sensor/vpDirectShowGrabber.h>
59 #define GETOPTARGS "dhn:o:"
71 void usage(
const char *name,
const char *badparam,
unsigned &nframes, std::string &opath)
74 Acquire images using DirectShow (under Windows only) and display\n\
75 it using GTK or the windows GDI if GTK is not available.\n\
78 %s [-d] [-n] [-o] [-h] \n",
84 Turn off the display.\n\
87 Number of frames to acquire. \n\
90 Filename for image saving. \n\
92 The %%d is for the image numbering.\n\
97 nframes, opath.c_str());
99 fprintf(stderr,
"ERROR: \n");
100 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
119 bool getOptions(
int argc,
const char **argv,
bool &display,
unsigned &nframes,
bool &save, std::string &opath)
130 nframes = atoi(optarg);
137 usage(argv[0],
nullptr, nframes, opath);
142 usage(argv[0], optarg, nframes, opath);
148 if ((c == 1) || (c == -1)) {
150 usage(argv[0],
nullptr, nframes, opath);
151 std::cerr <<
"ERROR: " << std::endl;
152 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
167 int 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) {
200 vpCTRACE <<
"there is no camera detected on your computer." << std::endl;
210 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: " << I.
getHeight() << std::endl;
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 snprintf(buf, FILENAME_MAX, 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;
258 std::cout <<
"Catch an exception: " << e << std::endl;
266 std::cout <<
"You do not have GDI (Graphical Device Interface), or GTK functionalities to display images..."
268 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
269 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
276 std::cout <<
"This example requires Direct Show SDK. " << std::endl;
277 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
278 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()
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
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)
unsigned int getWidth() const
unsigned int getHeight() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.
VISP_EXPORT double measureTimeMs()