42 #include <visp3/core/vpConfig.h> 43 #include <visp3/core/vpDebug.h> 57 #if defined(VISP_HAVE_DIRECTSHOW) 58 #if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 60 #include <visp3/core/vpImage.h> 61 #include <visp3/core/vpTime.h> 62 #include <visp3/gui/vpDisplayGDI.h> 63 #include <visp3/gui/vpDisplayGTK.h> 64 #include <visp3/io/vpImageIo.h> 65 #include <visp3/io/vpParseArgv.h> 66 #include <visp3/sensor/vpDirectShowGrabber.h> 70 #define GETOPTARGS "c:df:hmn:io:st:?" 85 void usage(
const char *name,
const char *badparam,
unsigned int camera,
unsigned int &nframes, std::string &opath)
88 fprintf(stderr,
"\nERREUR: Bad parameter [%s]\n", badparam);
91 Acquire images using DirectShow (under Windows only) and display\n\ 92 it using GTK or the windows GDI if GTK is not available.\n\ 93 For a given camera, mediatype (or video mode) as well as framerate\n\ 95 If more than one camera is connected, this example allows also to \n\ 96 acquire images from all the cameras.\n\ 99 %s [-t <mediatype>] [-f <framerate>] \n\ 100 [-c <camera id>] [-m] [-n <frames>] [-i] [-s] [-d] \n\ 101 [-o <filename>] [-h]\n\ 105 MediaType (or video mode) to set for the active \n\ 106 camera. Use -s option so see which are the supported \n\ 107 Mediatypes. You can select the active camera \n\ 111 Framerate to set for the active camera.\n\ 112 You can select the active camera using -c option.\n", name);
116 Active camera identifier.\n\ 117 Zero is for the first camera found on the bus.\n\ 120 Flag to active multi camera acquisition. \n\ 121 You need at least two cameras connected on the bus.\n\ 124 Number of frames to acquire.\n\ 127 Flag to print camera information.\n\ 130 Print camera settings capabilities such as MediaType \n\ 131 and sizes available and exit.\n\ 134 Flag to turn off image display.\n\ 137 Filename for image saving. \n\ 139 The first %%d is for the camera id, %%04d\n\ 140 is for the image numbering.\n\ 144 \n", camera, nframes, opath.c_str());
174 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
unsigned int &nframes,
175 bool &verbose_info,
bool &verbose_settings,
bool &mediatype_is_set,
unsigned int &mediatypeID,
176 bool &framerate_is_set,
double &framerate,
bool &display,
bool &save, std::string &opath)
187 camera = atoi(optarg);
193 framerate_is_set =
true;
194 framerate = atoi(optarg);
203 nframes = atoi(optarg);
210 verbose_settings =
true;
213 mediatype_is_set =
true;
214 mediatypeID = atoi(optarg);
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;
238 int main(
int argc,
const char **argv)
241 unsigned int camera = 0;
243 bool verbose_info =
false;
244 bool verbose_settings =
false;
246 unsigned int nframes = 50;
247 bool mediatype_is_set =
false;
248 unsigned int mediatypeID;
249 bool framerate_is_set =
false;
255 std::string opath =
"C:/temp/I%d-%04d.ppm";
258 std::string opath =
"C:/temp/I%d-%04d.pgm";
260 #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++) {
327 if (mediatype_is_set) {
331 if (framerate_is_set) {
332 for (
unsigned int i = 0; i < ncameras; i++) {
338 std::cout <<
"camera " << c << std::endl;
339 if (!g[i].setFramerate(framerate))
340 std::cout <<
"Set Framerate failed !!" << std::endl << std::endl;
345 if (verbose_info || verbose_settings) {
347 std::cout <<
"----------------------------------------------------------" << std::endl;
348 std::cout <<
"---- Device List : " << std::endl;
349 std::cout <<
"----------------------------------------------------------" << std::endl;
351 for (
unsigned i = 0; i < ncameras; i++) {
359 unsigned int width, height;
360 g[i].
getFormat(width, height, framerate);
361 std::cout <<
"----------------------------------------------------------" << std::endl
362 <<
"---- MediaType and framerate currently used by device " << std::endl
363 <<
"---- (or camera) " << c << std::endl
364 <<
"---- Current MediaType : " << g[i].
getMediaType() << std::endl
365 <<
"---- Current format : " << width <<
" x " << height <<
" at " << framerate <<
" fps" 367 <<
"----------------------------------------------------------" << std::endl;
369 if (verbose_settings) {
370 std::cout <<
"----------------------------------------------------------" << std::endl
371 <<
"---- MediaTypes supported by device (or camera) " << c << std::endl
372 <<
"---- One of the MediaType below can be set using " << std::endl
373 <<
"---- option -t <mediatype>." << std::endl
374 <<
"----------------------------------------------------------" << std::endl;
387 for (
unsigned int i = 0; i < ncameras; i++) {
396 std::cout <<
"Image size for camera " << c <<
" : width: " << I[i].
getWidth() <<
" height: " << I[i].
getHeight()
402 sprintf(title,
"Images captured by camera %u", c);
403 d[i].
init(I[i], 100 + i * 50, 100 + i * 50, title);
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 sprintf(buf, opath.c_str(), c, i);
426 std::string filename(buf);
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;
451 std::cout <<
"Catch an exception: " << e << std::endl;
455 #else // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 458 std::cout <<
"You do not have GDI (Graphical Device Interface), or GTK functionalities to display images..." << std::endl;
459 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
460 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
463 #endif // (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) 464 #else // defined (VISP_HAVE_DIRECTSHOW) 467 std::cout <<
"This example requires Direct Show SDK. " << std::endl;
468 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
469 std::cout <<
"- Install Direct Show, configure again ViSP using cmake and build again this example" << std::endl;
472 #endif // defined (VISP_HAVE_DIRECTSHOW) void getFormat(unsigned int &width, unsigned int &height, double &framerate)
unsigned int getWidth() const
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="")
bool getStreamCapabilities()
unsigned int getDeviceNumber()
unsigned int getHeight() const