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:"
61 #ifdef ENABLE_VISP_NAMESPACE
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",
88 Turn off the display.\n\
91 Number of frames to acquire. \n\
94 Filename for image saving. \n\
96 The %%d is for the image numbering.\n\
101 nframes, opath.c_str());
103 fprintf(stderr,
"ERROR: \n");
104 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
123 bool getOptions(
int argc,
const char **argv,
bool &display,
unsigned &nframes,
bool &save, std::string &opath)
134 nframes = atoi(optarg);
141 usage(argv[0],
nullptr, nframes, opath);
146 usage(argv[0], optarg, nframes, opath);
152 if ((c == 1) || (c == -1)) {
154 usage(argv[0],
nullptr, nframes, opath);
155 std::cerr <<
"ERROR: " << std::endl;
156 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
171 int main(
int argc,
const char **argv)
174 bool opt_display =
true;
175 unsigned nframes = 50;
189 std::string opath =
"C:/temp/I%04d.ppm";
192 std::string opath =
"C:/temp/I%04d.pgm";
196 if (getOptions(argc, argv, opt_display, nframes, save, opath) ==
false) {
204 vpCTRACE <<
"there is no camera detected on your computer." << std::endl;
214 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: " << I.
getHeight() << std::endl;
217 #if defined(VISP_HAVE_GTK)
219 #elif defined(VISP_HAVE_GDI)
224 display.init(I, 100, 100,
"DirectShow Framegrabber");
227 double tbegin = 0, ttotal = 0;
232 for (
unsigned i = 0; i < nframes; i++) {
243 char buf[FILENAME_MAX];
244 snprintf(buf, FILENAME_MAX, opath.c_str(), i);
245 std::string filename(buf);
246 std::cout <<
"Write: " << filename << std::endl;
250 double 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;
271 std::cout <<
"You do not have GDI (Graphical Device Interface), or GTK functionalities to display images..."
273 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
274 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
281 std::cout <<
"This example requires Direct Show SDK. " << std::endl;
282 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
283 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)
VISP_EXPORT double measureTimeMs()