53 #include <visp/vpConfig.h>
54 #include <visp/vp1394CMUGrabber.h>
55 #include <visp/vpImage.h>
56 #include <visp/vpImageIo.h>
57 #include <visp/vpDisplayGDI.h>
58 #include <visp/vpDisplayOpenCV.h>
59 #include <visp/vpParseArgv.h>
60 #include <visp/vpTime.h>
65 #define GETOPTARGS "dhn:o:"
77 void usage(
const char *name,
const char *badparam,
unsigned &nframes, std::string &opath)
80 Acquire images using CMU 1394 Digital Camera SDK (available under Windows only) and display\n\
81 it using GDI or OpenCV if GDI is not available.\n\
84 %s [-d] [-n] [-o] [-h] \n", name);
89 Turn off the display.\n\
92 Number of frames to acquire. \n\
95 Filename for image saving. \n\
97 The %%d is for the image numbering.\n\
101 \n", nframes, opath.c_str());
103 fprintf(stderr,
"ERROR: \n" );
104 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
123 bool getOptions(
int argc,
const char **argv,
bool &display,
124 unsigned int &nframes,
bool &save, std::string &opath)
131 case 'd': display =
false;
break;
133 nframes = (
unsigned int)atoi(optarg);
break;
136 opath = optarg;
break;
137 case 'h': usage(argv[0], NULL, nframes, opath);
return false;
break;
140 usage(argv[0], optarg, nframes, opath);
145 if ((c == 1) || (c == -1)) {
147 usage(argv[0], NULL, nframes, opath);
148 std::cerr <<
"ERROR: " << std::endl;
149 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
163 #if defined(VISP_HAVE_CMU1394)
165 main(
int argc,
const char ** argv)
167 bool opt_display =
true;
168 unsigned nframes = 50;
182 std::string opath =
"C:/temp/I%04d.ppm";
185 std::string opath =
"C:/temp/I%04d.pgm";
189 if (getOptions(argc, argv, opt_display, nframes, save, opath) ==
false) {
199 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: "
202 #if (defined (VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
205 #if defined VISP_HAVE_OPENCV
207 #elif defined VISP_HAVE_GDI
211 display.
init(I,100,100,
"DirectShow Framegrabber");
216 double tbegin=0, tend=0, tloop=0, ttotal=0;
221 for (
unsigned i = 0; i < nframes; i++) {
225 #if (defined (VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
236 char buf[FILENAME_MAX];
237 sprintf(buf, opath.c_str(), i);
238 std::string filename(buf);
239 std::cout <<
"Write: " << filename << std::endl;
247 tloop = tend - tbegin;
249 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
252 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
253 std::cout <<
"Mean frequency: " << 1000./(ttotal / nframes) <<
" fps" << std::endl;
257 std::cout <<
"Failure: exit" << std::endl;
264 std::cout <<
"This example requires CMU 1394 Digital Camera SDK. " << std::endl;