37 #include <visp3/core/vpConfig.h>
38 #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 "c:df:hmn:io:st:?"
67 #ifdef ENABLE_VISP_NAMESPACE
82 void usage(
const char *name,
const char *badparam,
unsigned int camera,
unsigned int &nframes, std::string &opath)
85 fprintf(stderr,
"\nERREUR: Bad parameter [%s]\n", badparam);
88 Acquire images using DirectShow (under Windows only) and display\n\
89 it using GTK or the windows GDI if GTK is not available.\n\
90 For a given camera, mediatype (or video mode) as well as framerate\n\
92 If more than one camera is connected, this example allows also to \n\
93 acquire images from all the cameras.\n\
96 %s [-t <mediatype>] [-f <framerate>] \n\
97 [-c <camera id>] [-m] [-n <frames>] [-i] [-s] [-d] \n\
98 [-o <filename>] [-h]\n\
102 MediaType (or video mode) to set for the active \n\
103 camera. Use -s option so see which are the supported \n\
104 Mediatypes. You can select the active camera \n\
108 Framerate to set for the active camera.\n\
109 You can select the active camera using -c option.\n",
114 Active camera identifier.\n\
115 Zero is for the first camera found on the bus.\n\
118 Flag to active multi camera acquisition. \n\
119 You need at least two cameras connected on the bus.\n\
122 Number of frames to acquire.\n\
125 Flag to print camera information.\n\
128 Print camera settings capabilities such as MediaType \n\
129 and sizes available and exit.\n\
132 Flag to turn off image display.\n\
135 Filename for image saving. \n\
137 The first %%d is for the camera id, %%04d\n\
138 is for the image numbering.\n\
143 camera, nframes, opath.c_str());
173 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
unsigned int &nframes,
174 bool &verbose_info,
bool &verbose_settings,
bool &mediatype_is_set,
unsigned int &mediatypeID,
175 bool &framerate_is_set,
double &framerate,
bool &display,
bool &save, std::string &opath)
186 camera = atoi(optarg);
192 framerate_is_set =
true;
193 framerate = atoi(optarg);
202 nframes = atoi(optarg);
209 verbose_settings =
true;
212 mediatype_is_set =
true;
213 mediatypeID = atoi(optarg);
216 usage(argv[0],
nullptr, camera, nframes, opath);
221 if ((c == 1) || (c == -1)) {
223 usage(argv[0],
nullptr, camera, nframes, opath);
224 std::cerr <<
"ERROR: " << std::endl;
225 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
237 int main(
int argc,
const char **argv)
240 unsigned int camera = 0;
242 bool verbose_info =
false;
243 bool verbose_settings =
false;
245 unsigned int nframes = 50;
246 bool mediatype_is_set =
false;
247 unsigned int mediatypeID;
248 bool framerate_is_set =
false;
254 std::string opath =
"C:/temp/I%d-%04d.ppm";
257 std::string opath =
"C:/temp/I%d-%04d.pgm";
259 #if defined(VISP_HAVE_GDI)
262 #elif defined(VISP_HAVE_GTK)
265 read_options(argc, argv, multi, camera, nframes, verbose_info, verbose_settings, mediatype_is_set, mediatypeID,
266 framerate_is_set, framerate, display, save, opath);
276 std::cout <<
"You have only " << ncameras <<
" camera connected on the bus." << std::endl;
277 std::cout <<
"It is not possible to active multi-camera acquisition." << std::endl;
278 std::cout <<
"Disable -m command line option, or connect an other " << std::endl;
279 std::cout <<
"cameras on the bus." << std::endl;
285 if (camera >= ncameras) {
286 std::cout <<
"You have only " << ncameras;
287 std::cout <<
" camera connected on the bus." << std::endl;
288 std::cout <<
"It is not possible to select camera " << camera << std::endl;
289 std::cout <<
"Check your -c <camera> command line option." << std::endl;
300 for (
unsigned int i = 0; i < ncameras; i++) {
328 if (mediatype_is_set) {
332 if (framerate_is_set) {
333 for (
unsigned int i = 0; i < ncameras; i++) {
339 std::cout <<
"camera " << c << std::endl;
340 if (!g[i].setFramerate(framerate))
341 std::cout <<
"Set Framerate failed !!" << std::endl << std::endl;
346 if (verbose_info || verbose_settings) {
348 std::cout <<
"----------------------------------------------------------" << std::endl;
349 std::cout <<
"---- Device List : " << std::endl;
350 std::cout <<
"----------------------------------------------------------" << std::endl;
352 for (
unsigned i = 0; i < ncameras; i++) {
360 unsigned int width, height;
361 g[i].
getFormat(width, height, framerate);
362 std::cout <<
"----------------------------------------------------------" << std::endl
363 <<
"---- MediaType and framerate currently used by device " << std::endl
364 <<
"---- (or camera) " << c << std::endl
365 <<
"---- Current MediaType : " << g[i].
getMediaType() << std::endl
366 <<
"---- Current format : " << width <<
" x " << height <<
" at " << framerate <<
" fps"
368 <<
"----------------------------------------------------------" << std::endl;
370 if (verbose_settings) {
371 std::cout <<
"----------------------------------------------------------" << std::endl
372 <<
"---- MediaTypes supported by device (or camera) " << c << std::endl
373 <<
"---- One of the MediaType below can be set using " << std::endl
374 <<
"---- option -t <mediatype>." << std::endl
375 <<
"----------------------------------------------------------" << std::endl;
388 for (
unsigned int i = 0; i < ncameras; i++) {
397 std::cout <<
"Image size for camera " << c <<
" : width: " << I[i].
getWidth() <<
" height: " << I[i].
getHeight()
402 std::stringstream title;
403 title <<
"Images captured by camera ";
405 d[i].
init(I[i], 100 + i * 50, 100 + i * 50, title.c_str());
410 std::cout <<
"Capture in process..." << std::endl;
412 double tbegin = 0, ttotal = 0;
416 for (
unsigned i = 0; i < nframes; i++) {
417 for (
unsigned c = 0; c < ncameras; c++) {
426 char buf[FILENAME_MAX];
427 snprintf(buf, FILENAME_MAX, opath.c_str(), c, i);
428 std::string filename(buf);
429 std::cout <<
"Write: " << filename << std::endl;
434 double tloop = tend - tbegin;
436 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
440 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
441 std::cout <<
"Mean frequency: " << 1000. / (ttotal / nframes) <<
" fps" << std::endl;
454 std::cout <<
"Catch an exception: " << e << std::endl;
461 std::cout <<
"You do not have GDI (Graphical Device Interface), or GTK functionalities to display images..."
463 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
464 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
471 std::cout <<
"This example requires Direct Show SDK. " << std::endl;
472 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
473 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...
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="") VP_OVERRIDE
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()