35#include <visp3/core/vpConfig.h>
36#include <visp3/core/vpDebug.h>
49#if defined(VISP_HAVE_DIRECTSHOW)
50#if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
52#include <visp3/core/vpImage.h>
53#include <visp3/core/vpTime.h>
54#include <visp3/gui/vpDisplayGDI.h>
55#include <visp3/gui/vpDisplayGTK.h>
56#include <visp3/io/vpImageIo.h>
57#include <visp3/io/vpParseArgv.h>
58#include <visp3/sensor/vpDirectShowGrabber.h>
61#define GETOPTARGS "c:df:hmn:io:st:?"
65#ifdef ENABLE_VISP_NAMESPACE
80void usage(
const char *name,
const char *badparam,
unsigned int camera,
unsigned int &nframes, std::string &opath)
83 fprintf(stderr,
"\nERREUR: Bad parameter [%s]\n", badparam);
86Acquire images using DirectShow (under Windows only) and display\n\
87it using GTK or the windows GDI if GTK is not available.\n\
88For a given camera, mediatype (or video mode) as well as framerate\n\
90If more than one camera is connected, this example allows also to \n\
91acquire images from all the cameras.\n\
94%s [-t <mediatype>] [-f <framerate>] \n\
95 [-c <camera id>] [-m] [-n <frames>] [-i] [-s] [-d] \n\
96 [-o <filename>] [-h]\n\
100 MediaType (or video mode) to set for the active \n\
101 camera. Use -s option so see which are the supported \n\
102 Mediatypes. You can select the active camera \n\
106 Framerate to set for the active camera.\n\
107 You can select the active camera using -c option.\n",
112 Active camera identifier.\n\
113 Zero is for the first camera found on the bus.\n\
116 Flag to active multi camera acquisition. \n\
117 You need at least two cameras connected on the bus.\n\
120 Number of frames to acquire.\n\
123 Flag to print camera information.\n\
126 Print camera settings capabilities such as MediaType \n\
127 and sizes available and exit.\n\
130 Flag to turn off image display.\n\
133 Filename for image saving. \n\
135 The first %%d is for the camera id, %%04d\n\
136 is for the image numbering.\n\
141camera, nframes, opath.c_str());
171void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
unsigned int &nframes,
172 bool &verbose_info,
bool &verbose_settings,
bool &mediatype_is_set,
unsigned int &mediatypeID,
173 bool &framerate_is_set,
double &framerate,
bool &display,
bool &save, std::string &opath)
184 camera = atoi(optarg);
190 framerate_is_set =
true;
191 framerate = atoi(optarg);
200 nframes = atoi(optarg);
207 verbose_settings =
true;
210 mediatype_is_set =
true;
211 mediatypeID = atoi(optarg);
214 usage(argv[0],
nullptr, camera, nframes, opath);
219 if ((c == 1) || (c == -1)) {
221 usage(argv[0],
nullptr, camera, nframes, opath);
222 std::cerr <<
"ERROR: " << std::endl;
223 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
235int main(
int argc,
const char **argv)
238 unsigned int camera = 0;
240 bool verbose_info =
false;
241 bool verbose_settings =
false;
243 unsigned int nframes = 50;
244 bool mediatype_is_set =
false;
245 unsigned int mediatypeID;
246 bool framerate_is_set =
false;
252 std::string opath =
"C:/temp/I%d-%04d.ppm";
255 std::string opath =
"C:/temp/I%d-%04d.pgm";
257#if defined(VISP_HAVE_GDI)
260#elif defined(VISP_HAVE_GTK)
263 read_options(argc, argv, multi, camera, nframes, verbose_info, verbose_settings, mediatype_is_set, mediatypeID,
264 framerate_is_set, framerate, display, save, opath);
274 std::cout <<
"You have only " << ncameras <<
" camera connected on the bus." << std::endl;
275 std::cout <<
"It is not possible to active multi-camera acquisition." << std::endl;
276 std::cout <<
"Disable -m command line option, or connect an other " << std::endl;
277 std::cout <<
"cameras on the bus." << std::endl;
283 if (camera >= ncameras) {
284 std::cout <<
"You have only " << ncameras;
285 std::cout <<
" camera connected on the bus." << std::endl;
286 std::cout <<
"It is not possible to select camera " << camera << std::endl;
287 std::cout <<
"Check your -c <camera> command line option." << std::endl;
298 for (
unsigned int i = 0;
i < ncameras;
i++) {
326 if (mediatype_is_set) {
330 if (framerate_is_set) {
331 for (
unsigned int i = 0;
i < ncameras;
i++) {
337 std::cout <<
"camera " << c << std::endl;
338 if (!g[i].setFramerate(framerate))
339 std::cout <<
"Set Framerate failed !!" << std::endl << std::endl;
344 if (verbose_info || verbose_settings) {
346 std::cout <<
"----------------------------------------------------------" << std::endl;
347 std::cout <<
"---- Device List : " << std::endl;
348 std::cout <<
"----------------------------------------------------------" << std::endl;
350 for (
unsigned i = 0;
i < ncameras;
i++) {
360 std::cout <<
"----------------------------------------------------------" << std::endl
361 <<
"---- MediaType and framerate currently used by device " << std::endl
362 <<
"---- (or camera) " << c << std::endl
363 <<
"---- Current MediaType : " << g[
i].
getMediaType() << std::endl
364 <<
"---- Current format : " <<
width <<
" x " <<
height <<
" at " << framerate <<
" fps"
366 <<
"----------------------------------------------------------" << std::endl;
368 if (verbose_settings) {
369 std::cout <<
"----------------------------------------------------------" << std::endl
370 <<
"---- MediaTypes supported by device (or camera) " << c << std::endl
371 <<
"---- One of the MediaType below can be set using " << std::endl
372 <<
"---- option -t <mediatype>." << std::endl
373 <<
"----------------------------------------------------------" << std::endl;
386 for (
unsigned int i = 0;
i < ncameras;
i++) {
395 std::cout <<
"Image size for camera " << c <<
" : width: " << I[
i].getWidth() <<
" height: " << I[
i].getHeight()
400 std::stringstream title;
401 title <<
"Images captured by camera ";
403 d[
i].init(I[i], 100 + i * 50, 100 + i * 50, title.c_str());
408 std::cout <<
"Capture in process..." << std::endl;
410 double tbegin = 0, ttotal = 0;
414 for (
unsigned i = 0;
i < nframes;
i++) {
415 for (
unsigned c = 0; c < ncameras; c++) {
424 char buf[FILENAME_MAX];
425 snprintf(buf, FILENAME_MAX, opath.c_str(), c, i);
427 std::cout <<
"Write: " <<
filename << std::endl;
432 double tloop = tend - tbegin;
434 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
438 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
439 std::cout <<
"Mean frequency: " << 1000. / (ttotal / nframes) <<
" fps" << std::endl;
452 std::cout <<
"Catch an exception: " <<
e << std::endl;
459 std::cout <<
"You do not have GDI (Graphical Device Interface), or GTK functionalities to display images..."
461 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
462 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
469 std::cout <<
"This example requires Direct Show SDK. " << std::endl;
470 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
471 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)
void getFormat(unsigned int &width, unsigned int &height, double &framerate)
bool setDevice(unsigned int id)
unsigned int getDeviceNumber()
bool getStreamCapabilities()
bool setMediaType(int mediaTypeID)
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)
Definition of the vpImage class member functions.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
VISP_EXPORT double measureTimeMs()