41 #include <visp3/core/vpConfig.h> 42 #include <visp3/core/vpDebug.h> 57 #if defined (VISP_HAVE_DIRECTSHOW) 58 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 60 #include <visp3/sensor/vpDirectShowGrabber.h> 61 #include <visp3/core/vpImage.h> 62 #include <visp3/io/vpImageIo.h> 63 #include <visp3/gui/vpDisplayGTK.h> 64 #include <visp3/gui/vpDisplayGDI.h> 65 #include <visp3/io/vpParseArgv.h> 66 #include <visp3/core/vpTime.h> 71 #define GETOPTARGS "c:df:hmn:io:st:?" 86 void usage(
const char *name,
const char *badparam,
unsigned int camera,
unsigned int &nframes,
90 fprintf(stderr,
"\nERREUR: Bad parameter [%s]\n", badparam);
93 Acquire images using DirectShow (under Windows only) and display\n\ 94 it using GTK or the windows GDI if GTK is not available.\n\ 95 For a given camera, mediatype (or video mode) as well as framerate\n\ 97 If more than one camera is connected, this example allows also to \n\ 98 acquire images from all the cameras.\n\ 101 %s [-t <mediatype>] [-f <framerate>] \n\ 102 [-c <camera id>] [-m] [-n <frames>] [-i] [-s] [-d] \n\ 103 [-o <filename>] [-h]\n\ 107 MediaType (or video mode) to set for the active \n\ 108 camera. Use -s option so see which are the supported \n\ 109 Mediatypes. You can select the active camera \n\ 113 Framerate to set for the active camera.\n\ 114 You can select the active camera using -c option.\n",
119 Active camera identifier.\n\ 120 Zero is for the first camera found on the bus.\n\ 123 Flag to active multi camera acquisition. \n\ 124 You need at least two cameras connected on the bus.\n\ 127 Number of frames to acquire.\n\ 130 Flag to print camera information.\n\ 133 Print camera settings capabilities such as MediaType \n\ 134 and sizes available and exit.\n\ 137 Flag to turn off image display.\n\ 140 Filename for image saving. \n\ 142 The first %%d is for the camera id, %%04d\n\ 143 is for the image numbering.\n\ 148 camera, nframes, opath.c_str());
178 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
179 unsigned int &nframes,
bool &verbose_info,
180 bool &verbose_settings,
181 bool &mediatype_is_set,
182 unsigned int &mediatypeID,
183 bool &framerate_is_set,
185 bool &display,
bool &save, std::string &opath)
196 camera = atoi(optarg);
break;
198 display =
false;
break;
200 framerate_is_set =
true;
201 framerate = atoi(optarg);
break;
203 verbose_info =
true;
break;
207 nframes = atoi(optarg);
break;
210 opath = optarg;
break;
212 verbose_settings =
true;
break;
214 mediatype_is_set =
true;
215 mediatypeID = atoi(optarg);
break;
217 usage(argv[0], NULL, camera, nframes, opath);
222 if ((c == 1) || (c == -1)) {
224 usage(argv[0], NULL, camera, nframes, opath);
225 std::cerr <<
"ERROR: " << std::endl;
226 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
240 main(
int argc,
const char ** argv)
243 unsigned int camera = 0;
245 bool verbose_info =
false;
246 bool verbose_settings =
false;
248 unsigned int nframes = 50;
249 bool mediatype_is_set =
false;
250 unsigned int mediatypeID;
251 bool framerate_is_set =
false;
257 std::string opath =
"C:/temp/I%d-%04d.ppm";
260 std::string opath =
"C:/temp/I%d-%04d.pgm";
262 #if defined VISP_HAVE_GDI 264 #elif defined VISP_HAVE_GTK 267 read_options(argc, argv, multi, camera, nframes,
268 verbose_info, verbose_settings,
269 mediatype_is_set, mediatypeID,
270 framerate_is_set, framerate,
271 display, save, opath);
281 std::cout <<
"You have only " << ncameras <<
" camera connected on the bus." << std::endl;
282 std::cout <<
"It is not possible to active multi-camera acquisition." << std::endl;
283 std::cout <<
"Disable -m command line option, or connect an other " << std::endl;
284 std::cout <<
"cameras on the bus." << std::endl;
290 if (camera >= ncameras) {
291 std::cout <<
"You have only " << ncameras;
292 std::cout <<
" camera connected on the bus." << std::endl;
293 std::cout <<
"It is not possible to select camera " << camera << std::endl;
294 std::cout <<
"Check your -c <camera> command line option." << std::endl;
304 for(
unsigned int i=0; i<ncameras ; i++)
334 if (mediatype_is_set) {
338 if (framerate_is_set) {
339 for(
unsigned int i=0; i<ncameras ; i++)
344 std::cout<<
"camera " << c <<std::endl;
345 if (!g[i].setFramerate(framerate))
346 std::cout <<
"Set Framerate failed !!" <<std::endl<< std::endl;
351 if (verbose_info || verbose_settings) {
353 std::cout <<
"----------------------------------------------------------" << std::endl;
354 std::cout <<
"---- Device List : " << std::endl;
355 std::cout <<
"----------------------------------------------------------" << std::endl;
357 for (
unsigned i=0; i < ncameras; i ++) {
363 unsigned int width, height;
364 g[i].
getFormat(width, height, framerate);
365 std::cout <<
"----------------------------------------------------------" 367 <<
"---- MediaType and framerate currently used by device " << std::endl
368 <<
"---- (or camera) " << c << std::endl
369 <<
"---- Current MediaType : " << g[i].
getMediaType() << std::endl
370 <<
"---- Current format : " << width <<
" x "<< height <<
" at "<< framerate <<
" fps" << std::endl
371 <<
"----------------------------------------------------------" << std::endl;
373 if (verbose_settings) {
374 std::cout <<
"----------------------------------------------------------" 376 <<
"---- MediaTypes supported by device (or camera) " 378 <<
"---- One of the MediaType below can be set using " << std::endl
379 <<
"---- option -t <mediatype>." 381 <<
"----------------------------------------------------------" 397 for (
unsigned int i=0; i < ncameras; i ++) {
404 std::cout <<
"Image size for camera " << c <<
" : width: " 410 sprintf(title,
"Images captured by camera %u", c );
411 d[i].
init(I[i], 100+i*50, 100+i*50, title) ;
416 std::cout <<
"Capture in process..." << std::endl;
418 double tbegin=0, ttotal=0;
422 for (
unsigned i = 0; i < nframes; i++) {
423 for (
unsigned c = 0; c < ncameras; c++) {
432 char buf[FILENAME_MAX];
433 sprintf(buf, opath.c_str(), c, i);
434 std::string filename(buf);
435 std::cout <<
"Write: " << filename << std::endl;
440 double tloop = tend - tbegin;
442 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
446 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
447 std::cout <<
"Mean frequency: " << 1000./(ttotal / nframes) <<
" fps" << std::endl;
460 std::cout <<
"Catch an exception: " << e << std::endl;
464 #else // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 469 vpTRACE(
"GDI or GTK is not available...") ;
471 #endif // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 472 #else // defined (VISP_HAVE_DIRECTSHOW) 476 vpTRACE(
"DirectShow is not available...") ;
478 #endif // defined (VISP_HAVE_DIRECTSHOW) void getFormat(unsigned int &width, unsigned int &height, double &framerate)
Display for windows using GDI (available on any windows 32 platform).
bool setMediaType(int mediaTypeID)
error that can be emited by ViSP classes.
class for windows direct show devices
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
bool setDevice(unsigned int id)
static void write(const vpImage< unsigned char > &I, const std::string &filename)
static void display(const vpImage< unsigned char > &I)
void acquire(vpImage< unsigned char > &I)
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="")
unsigned int getHeight() const
bool getStreamCapabilities()
unsigned int getDeviceNumber()
unsigned int getWidth() const