43 #include <visp/vpConfig.h>
44 #include <visp/vpDebug.h>
53 #if defined (VISP_HAVE_OPENCV)
56 #include <visp/vpOpenCVGrabber.h>
57 #include <visp/vpImage.h>
58 #include <visp/vpImageIo.h>
59 #include <visp/vpDisplayOpenCV.h>
60 #include <visp/vpParseArgv.h>
61 #include <visp/vpTime.h>
64 #define GETOPTARGS "dhn:o:D:"
76 void usage(
const char *name,
const char *badparam,
unsigned int &nframes, std::string &opath)
79 Acquire and display images using OpenCV library.\n\
82 %s [-d] [-n] [-o] [-h] \n", name);
87 Turn off the display.\n\
90 Type of device to detect. 1394\n\
91 It can be ANY, MIL, USB, 1394. \n\
94 Number of frames to acquire. \n\
97 Filename for image saving. \n\
99 The %%d is for the image numbering.\n\
103 \n", nframes, opath.c_str());
105 fprintf(stderr,
"ERROR: \n" );
106 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
126 bool getOptions(
int argc,
const char **argv,
bool &display,
127 unsigned int &nframes,
bool &save, std::string &opath,
int &deviceType)
134 case 'd': display =
false;
break;
136 if (strcmp( optarg ,
"ANY") == 0 ) {deviceType = 0;}
137 else if ( strcmp( optarg ,
"MIL") == 0) {deviceType = 100;}
138 else if ( strcmp( optarg ,
"USB") == 0) {deviceType = 200;}
139 else if ( strcmp( optarg ,
"1394") == 0) {deviceType = 300;}
140 else {std::cout <<
"Unknown type of device" << std::endl;
144 nframes = (
unsigned int)atoi(optarg);
break;
147 opath = optarg;
break;
148 case 'h': usage(argv[0], NULL, nframes, opath);
return false;
break;
151 usage(argv[0], optarg, nframes, opath);
156 if ((c == 1) || (c == -1)) {
158 usage(argv[0], NULL, nframes, opath);
159 std::cerr <<
"ERROR: " << std::endl;
160 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
176 main(
int argc,
const char ** argv)
178 bool opt_display =
true;
179 unsigned nframes = 50;
181 int deviceType = CV_CAP_DC1394;
195 std::string opath =
"/tmp/I%04d.ppm";
196 # elif defined(WIN32)
197 std::string opath =
"C:/temp/I%04d.ppm";
202 std::string opath =
"/tmp/I%04d.pgm";
203 # elif defined(WIN32)
204 std::string opath =
"C:/temp/I%04d.pgm";
209 if (getOptions(argc, argv, opt_display, nframes, save, opath, deviceType) ==
false) {
226 vpCTRACE <<
"Cannot acquire an image... "
227 <<
"Check if a camera is connected to your computer."
232 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: "
239 display.
init(I,100,100,
"OpenCV framegrabber");
243 double tbegin=0, tend=0, tloop=0, ttotal=0;
248 for (
unsigned i = 0; i < nframes; i++) {
259 char buf[FILENAME_MAX];
260 sprintf(buf, opath.c_str(), i);
261 std::string filename(buf);
262 std::cout <<
"Write: " << filename << std::endl;
266 tloop = tend - tbegin;
268 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
271 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
272 std::cout <<
"Mean frequency: " << 1000./(ttotal / nframes) <<
" fps" << std::endl;
277 vpCERROR <<
"Failure: exit" << std::endl;
281 #else // defined (VISP_HAVE_OPENCV)
285 vpTRACE(
"OpenCV is not available...") ;
287 #endif // defined (VISP_HAVE_OPENCV)
void setDeviceType(int type)
static void write(const vpImage< unsigned char > &I, const char *filename)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
unsigned int getWidth() const
static double measureTimeMs()
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
void acquire(vpImage< unsigned char > &I)
unsigned int getHeight() const
Class for cameras video capture using OpenCV library.