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:?"
78 void usage(
const char *name,
const char *badparam,
unsigned int camera,
unsigned int &nframes, std::string &opath)
81 fprintf(stderr,
"\nERREUR: Bad parameter [%s]\n", badparam);
84 Acquire images using DirectShow (under Windows only) and display\n\
85 it using GTK or the windows GDI if GTK is not available.\n\
86 For a given camera, mediatype (or video mode) as well as framerate\n\
88 If more than one camera is connected, this example allows also to \n\
89 acquire images from all the cameras.\n\
92 %s [-t <mediatype>] [-f <framerate>] \n\
93 [-c <camera id>] [-m] [-n <frames>] [-i] [-s] [-d] \n\
94 [-o <filename>] [-h]\n\
98 MediaType (or video mode) to set for the active \n\
99 camera. Use -s option so see which are the supported \n\
100 Mediatypes. You can select the active camera \n\
104 Framerate to set for the active camera.\n\
105 You can select the active camera using -c option.\n",
110 Active camera identifier.\n\
111 Zero is for the first camera found on the bus.\n\
114 Flag to active multi camera acquisition. \n\
115 You need at least two cameras connected on the bus.\n\
118 Number of frames to acquire.\n\
121 Flag to print camera information.\n\
124 Print camera settings capabilities such as MediaType \n\
125 and sizes available and exit.\n\
128 Flag to turn off image display.\n\
131 Filename for image saving. \n\
133 The first %%d is for the camera id, %%04d\n\
134 is for the image numbering.\n\
139 camera, nframes, opath.c_str());
169 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
unsigned int &nframes,
170 bool &verbose_info,
bool &verbose_settings,
bool &mediatype_is_set,
unsigned int &mediatypeID,
171 bool &framerate_is_set,
double &framerate,
bool &display,
bool &save, std::string &opath)
182 camera = atoi(optarg);
188 framerate_is_set =
true;
189 framerate = atoi(optarg);
198 nframes = atoi(optarg);
205 verbose_settings =
true;
208 mediatype_is_set =
true;
209 mediatypeID = atoi(optarg);
212 usage(argv[0],
nullptr, camera, nframes, opath);
217 if ((c == 1) || (c == -1)) {
219 usage(argv[0],
nullptr, camera, nframes, opath);
220 std::cerr <<
"ERROR: " << std::endl;
221 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
233 int main(
int argc,
const char **argv)
236 unsigned int camera = 0;
238 bool verbose_info =
false;
239 bool verbose_settings =
false;
241 unsigned int nframes = 50;
242 bool mediatype_is_set =
false;
243 unsigned int mediatypeID;
244 bool framerate_is_set =
false;
250 std::string opath =
"C:/temp/I%d-%04d.ppm";
253 std::string opath =
"C:/temp/I%d-%04d.pgm";
255 #if defined(VISP_HAVE_GDI)
258 #elif defined(VISP_HAVE_GTK)
261 read_options(argc, argv, multi, camera, nframes, verbose_info, verbose_settings, mediatype_is_set, mediatypeID,
262 framerate_is_set, framerate, display, save, opath);
272 std::cout <<
"You have only " << ncameras <<
" camera connected on the bus." << std::endl;
273 std::cout <<
"It is not possible to active multi-camera acquisition." << std::endl;
274 std::cout <<
"Disable -m command line option, or connect an other " << std::endl;
275 std::cout <<
"cameras on the bus." << std::endl;
281 if (camera >= ncameras) {
282 std::cout <<
"You have only " << ncameras;
283 std::cout <<
" camera connected on the bus." << std::endl;
284 std::cout <<
"It is not possible to select camera " << camera << std::endl;
285 std::cout <<
"Check your -c <camera> command line option." << std::endl;
296 for (
unsigned int i = 0; i < ncameras; i++) {
323 if (mediatype_is_set) {
327 if (framerate_is_set) {
328 for (
unsigned int i = 0; i < ncameras; i++) {
334 std::cout <<
"camera " << c << std::endl;
335 if (!g[i].setFramerate(framerate))
336 std::cout <<
"Set Framerate failed !!" << std::endl << std::endl;
341 if (verbose_info || verbose_settings) {
343 std::cout <<
"----------------------------------------------------------" << std::endl;
344 std::cout <<
"---- Device List : " << std::endl;
345 std::cout <<
"----------------------------------------------------------" << std::endl;
347 for (
unsigned i = 0; i < ncameras; i++) {
355 unsigned int width, height;
356 g[i].
getFormat(width, height, framerate);
357 std::cout <<
"----------------------------------------------------------" << std::endl
358 <<
"---- MediaType and framerate currently used by device " << std::endl
359 <<
"---- (or camera) " << c << std::endl
360 <<
"---- Current MediaType : " << g[i].
getMediaType() << std::endl
361 <<
"---- Current format : " << width <<
" x " << height <<
" at " << framerate <<
" fps"
363 <<
"----------------------------------------------------------" << std::endl;
365 if (verbose_settings) {
366 std::cout <<
"----------------------------------------------------------" << std::endl
367 <<
"---- MediaTypes supported by device (or camera) " << c << std::endl
368 <<
"---- One of the MediaType below can be set using " << std::endl
369 <<
"---- option -t <mediatype>." << std::endl
370 <<
"----------------------------------------------------------" << std::endl;
383 for (
unsigned int i = 0; i < ncameras; i++) {
392 std::cout <<
"Image size for camera " << c <<
" : width: " << I[i].
getWidth() <<
" height: " << I[i].
getHeight()
397 std::stringstream title;
398 title <<
"Images captured by camera ";
400 d[i].
init(I[i], 100 + i * 50, 100 + i * 50, title.c_str());
405 std::cout <<
"Capture in process..." << std::endl;
407 double tbegin = 0, ttotal = 0;
411 for (
unsigned i = 0; i < nframes; i++) {
412 for (
unsigned c = 0; c < ncameras; c++) {
421 char buf[FILENAME_MAX];
422 snprintf(buf, FILENAME_MAX, opath.c_str(), c, i);
423 std::string filename(buf);
424 std::cout <<
"Write: " << filename << std::endl;
429 double tloop = tend - tbegin;
431 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
435 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
436 std::cout <<
"Mean frequency: " << 1000. / (ttotal / nframes) <<
" fps" << std::endl;
448 std::cout <<
"Catch an exception: " << e << std::endl;
455 std::cout <<
"You do not have GDI (Graphical Device Interface), or GTK functionalities to display images..."
457 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
458 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
465 std::cout <<
"This example requires Direct Show SDK. " << std::endl;
466 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
467 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 win_x=-1, int win_y=-1, const std::string &win_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)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.
VISP_EXPORT double measureTimeMs()