58 #include <visp/vpConfig.h>
59 #include <visp/vpDebug.h>
65 #if defined(VISP_HAVE_DC1394_2)
67 #include <visp/vp1394TwoGrabber.h>
68 #include <visp/vpImage.h>
69 #include <visp/vpImageIo.h>
70 #include <visp/vpDisplay.h>
71 #include <visp/vpDisplayX.h>
72 #include <visp/vpTime.h>
73 #include <visp/vpParseArgv.h>
74 #include <visp/vpRGBa.h>
80 #define GETOPTARGS "b:c:df:g:hH:L:mn:io:p:rsT:v:W:"
101 void usage(
const char *name,
const char *badparam,
unsigned int camera,
102 const unsigned int &nframes,
const std::string &opath,
103 const unsigned int &roi_left,
const unsigned int &roi_top,
104 const unsigned int &roi_width,
const unsigned int &roi_height,
105 const unsigned int &ringbuffersize,
const unsigned int &panControl)
108 fprintf(stderr,
"\nERROR: Bad parameter [%s]\n", badparam);
112 %s [-v <video mode>] [-f <framerate>] \n\
113 [-g <color coding>] [-c <camera id>] [-m] [-n <frames>] \n\
114 [-i] [-s] [-d] [-o <filename>] [-L <format 7 roi left position>] \n\
115 [-T <format 7 roi top position>] [-W <format 7 roi width>] \n\
116 [-H <format 7 roi height>] [-b <ring buffer size>] \n\
117 [-p <pan control value>] [-R] [-h]\n\
120 Test for firewire camera image acquisition.\n\
125 Indicates the current settings for the first camera found on the bus.\n\n\
127 Gives information on the first camera found on the bus.\n\n\
129 Indicates the current settings for all the cameras found on the bus.\n\n\
131 Gives information on all the cameras found on the bus.\n\
133 Grab images from camera 1.\n\n\
135 Grab images from all the cameras.\n\n\
137 If a stereo camera is connected to the bus like the PointGrey Bumblebee,\n\
138 you may set the pan control to select the camera view:\n\
140 Transmit right imge.\n\
142 Transmit left imge.\n\
145 -v [%%u] : Video mode to set for the active camera.\n\
146 Use -s option so see which are the supported \n\
147 video modes. You can select the active \n\
148 camera using -c option.\n\
150 -f [%%u] : Framerate to set for the active camera.\n\
151 Use -s option so see which are the supported \n\
152 framerates. You can select the active \n\
153 camera using -c option.\n\
155 -g [%%u] : Color coding to set for the active camera\n\
156 in format 7 video mode. Use -s option so see if \n\
157 format 7 is supported by the camera and if so, \n\
158 which are the supported color codings. You can \n\
159 select the active camera using -c option.\n\
160 See -t <top>, -l <left>, -w <width>, \n\
161 -h <height> option to set format 7 roi.\n\
163 -L [%%u] : Format 7 region of interest (roi) left %u\n\
164 position. This option is only used if video\n\
167 -T [%%u] : Format 7 region of interest (roi) top %u\n\
168 position. This option is only used if video\n\
171 -W [%%u] : Format 7 region of interest (roi) width. %u\n\
172 Is set to zero, use the maximum width. This\n\
173 option is only used if video mode is format 7.\n\
175 -H [%%u] : Format 7 region of interest (roi) height. %u\n\
176 Is set to zero, use the maximum height. This\n\
177 option is only used if video mode is format 7.\n\
179 -c [%%u] : Active camera identifier. %u\n\
180 Zero is for the first camera found on the bus.\n\
182 -m : Flag to active multi camera acquisition. \n\
183 You need at least two cameras connected on \n\
186 -n [%%u] : Number of frames to acquire. %u\n\
188 -i : Flag to print camera information.\n\
190 -s : Print camera settings capabilities such as \n\
191 video mode and framerates available and exit.\n\
193 -d : Flag to turn off image display.\n\
195 -b [%%u] : Ring buffer size used during capture %u\n\
197 -p [%%u] : Pan control value used to control single or %u\n\
198 multiple image transmission from stereo vision \n\
199 cameras by setting the PAN register 0x884.\n\
201 -o [%%s] : Filename for image saving. \n\
203 The first %%d is for the camera id. The second\n\
204 %%04d is for the image numbering. The format is set \n\
205 by the extension of the file (ex .png, .pgm, ...) \n\
207 -r : Reset the bus attached to the first camera found.\n\
208 Bus reset may help to make firewire working if the\n\
209 program was not properly stopped by a CTRL-C.\n\
211 -h : Print this help.\n\
213 name, name, name, name, name, name, name, name, name,
214 roi_left, roi_top, roi_width, roi_height,
215 camera, nframes, ringbuffersize, panControl, opath.c_str());
260 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
261 unsigned int &nframes,
bool &verbose_info,
262 bool &verbose_settings,
263 bool &videomode_is_set,
265 bool &framerate_is_set,
267 bool &colorcoding_is_set,
269 bool &ringbuffersize_is_set,
270 unsigned int &ringbuffersize,
271 bool &display,
bool &save, std::string &opath,
272 unsigned int &roi_left,
unsigned int &roi_top,
273 unsigned int &roi_width,
unsigned int &roi_height,
275 unsigned int &panControl,
bool & panControl_is_set)
286 camera = (
unsigned int)atoi(optarg);
break;
288 display =
false;
break;
290 framerate_is_set =
true;
294 colorcoding_is_set =
true;
298 roi_height = (
unsigned int) atoi(optarg);
break;
300 verbose_info =
true;
break;
302 roi_left = (
unsigned int) atoi(optarg);
break;
306 nframes = (
unsigned int)atoi(optarg);
break;
309 opath = optarg;
break;
311 ringbuffersize_is_set =
true;
312 ringbuffersize = (
unsigned int) atoi(optarg);
break;
314 panControl = (
unsigned int) atoi(optarg);
315 panControl_is_set =
true;
320 verbose_settings =
true;
break;
322 roi_top = (
unsigned int) atoi(optarg);
break;
324 videomode_is_set =
true;
328 roi_width = (
unsigned int) atoi(optarg);
break;
331 usage(argv[0], NULL, camera, nframes, opath,
332 roi_left, roi_top, roi_width, roi_height, ringbuffersize,
339 if ((c == 1) || (c == -1)) {
341 usage(argv[0], NULL, camera, nframes, opath,
342 roi_left, roi_top, roi_width, roi_height, ringbuffersize, panControl);
343 std::cerr <<
"ERROR: " << std::endl;
344 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
359 main(
int argc,
const char ** argv)
362 unsigned int camera = 0;
364 bool verbose_info =
false;
365 bool verbose_settings =
false;
367 unsigned int nframes = 50;
369 bool videomode_is_set =
false;
371 bool framerate_is_set =
false;
373 bool colorcoding_is_set =
false;
375 bool ringbuffersize_is_set =
false;
376 unsigned int ringbuffersize = 4;
379 unsigned int panControl = 0;
380 bool panControl_is_set =
false;
383 unsigned int roi_left=0, roi_top=0, roi_width=0, roi_height=0;
386 std::string opath =
"/tmp/I%d-%04d.ppm";
388 read_options(argc, argv, multi, camera, nframes,
389 verbose_info, verbose_settings,
390 videomode_is_set, videomode,
391 framerate_is_set, framerate,
392 colorcoding_is_set, colorcoding,
393 ringbuffersize_is_set, ringbuffersize,
394 display, save, opath,
395 roi_left, roi_top, roi_width, roi_height, reset,
396 panControl, panControl_is_set);
408 unsigned int ncameras = 0;
409 g.getNumCameras(ncameras);
411 std::cout <<
"Number of cameras on the bus: " << ncameras << std::endl;
417 std::cout <<
"You have only " << ncameras <<
" camera connected on the bus." << std::endl;
418 std::cout <<
"It is not possible to active multi-camera acquisition." << std::endl;
419 std::cout <<
"Disable -m command line option, or connect an other " << std::endl;
420 std::cout <<
"cameras on the bus." << std::endl;
425 if (camera >= ncameras) {
426 std::cout <<
"You have only " << ncameras;
427 std::cout <<
" camera connected on the bus." << std::endl;
428 std::cout <<
"It is not possible to select camera " << camera << std::endl;
429 std::cout <<
"Check your -c <camera> command line option." << std::endl;
446 if (verbose_info || verbose_settings) {
447 for (
unsigned int i=0; i < ncameras; i ++) {
449 g.setCamera(i+offset);
454 if (verbose_settings) {
458 std::list<vp1394TwoGrabber::vp1394TwoVideoModeType> lmode;
459 std::list<vp1394TwoGrabber::vp1394TwoFramerateType> lfps;
460 std::list<vp1394TwoGrabber::vp1394TwoColorCodingType> lcoding;
461 std::list<vp1394TwoGrabber::vp1394TwoVideoModeType>::const_iterator it_lmode;
462 std::list<vp1394TwoGrabber::vp1394TwoFramerateType>::const_iterator it_lfps;
463 std::list<vp1394TwoGrabber::vp1394TwoColorCodingType>::const_iterator it_lcoding;
466 g.getVideoMode(curmode);
467 g.getFramerate(curfps);
468 g.getColorCoding(curcoding);
469 g.getVideoModeSupported(lmode);
472 std::cout <<
"----------------------------------------------------------"
474 <<
"---- Video modes and framerates supported by camera "
475 << i+offset <<
" ----" << std::endl
476 <<
"---- with guid 0x" << std::hex << guid <<
" ----" << std::endl
477 <<
"---- * is for the current settings ----"
479 <<
"---- between ( ) you have the corresponding option ----"
481 <<
"---- to use. ----"
483 <<
"----------------------------------------------------------"
486 for (it_lmode = lmode.begin(); it_lmode != lmode.end(); ++it_lmode) {
489 if (curmode == supmode)
491 <<
" (-v " << supmode <<
")" << std::endl;
494 <<
" (-v " << supmode <<
")" << std::endl;
496 if (g.isVideoModeFormat7(supmode)){
499 g.getColorCodingSupported(supmode, lcoding);
500 for (it_lcoding = lcoding.begin(); it_lcoding != lcoding.end(); ++it_lcoding) {
502 supcoding = *it_lcoding;
503 if ( (curmode == supmode) && (supcoding == curcoding) )
506 <<
" (-g " << supcoding <<
")" << std::endl;
510 <<
" (-g " << supcoding <<
")" << std::endl;
516 g.getFramerateSupported(supmode, lfps);
517 for (it_lfps = lfps.begin(); it_lfps != lfps.end(); ++it_lfps) {
519 if ( (curmode == supmode) && (supfps == curfps) )
522 <<
" (-f " << supfps <<
")" << std::endl;
526 <<
" (-f " << supfps <<
")" << std::endl;
530 std::cout <<
"----------------------------------------------------------"
540 if (panControl_is_set) {
541 g.setPanControl(panControl);
545 if (videomode_is_set) {
547 g.setVideoMode(videomode);
552 g.getVideoMode(videomode);
554 if (framerate_is_set) {
556 g.setFramerate(framerate);
558 if (colorcoding_is_set) {
560 g.setColorCoding(colorcoding);
562 if (ringbuffersize_is_set) {
563 g.setRingBufferSize(ringbuffersize);
567 if (g.isVideoModeFormat7(videomode))
568 g.setFormat7ROI(roi_left, roi_top, roi_width, roi_height);
571 bool *grab_color =
new bool [ncameras];
585 for (
unsigned int i=0; i < ncameras; i ++) {
587 g.setCamera(i+offset);
590 grab_color[i] = g.isColor();
594 std::cout <<
"Image size for camera " << i+offset <<
" : width: "
602 sprintf(title,
"Images captured by camera %u", i+offset);
603 d[i].
init(Ic[i], (
int)(100+i*50), (
int)(100+i*50), title) ;
611 std::cout <<
"Image size for camera " << i+offset <<
" : width: "
619 sprintf(title,
"Images captured by camera %u", i+offset);
620 d[i].
init(Ig[i], (
int)(100+i*50), (
int)(100+i*50), title) ;
630 std::cout <<
"Capture in process..." << std::endl;
632 double tbegin=0, tend=0, tloop=0, ttotal=0;
636 for (
unsigned int i = 0; i < nframes; i++) {
637 for (
unsigned int c = 0; c < ncameras; c++) {
639 g.setCamera(c+offset);
663 char buf[FILENAME_MAX];
664 sprintf(buf, opath.c_str(), c+offset, i);
665 std::string filename(buf);
666 std::cout <<
"Write: " << filename << std::endl;
676 tloop = tend - tbegin;
678 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
682 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
683 std::cout <<
"Mean frequency: " << 1000./(ttotal / nframes) <<
" fps" << std::endl;
692 delete [] grab_color;
700 vpCERROR <<
"Failure: exit" << std::endl;
703 std::cout <<
" the end" << std::endl;
709 vpTRACE(
"Ieee 1394 grabber capabilities are not available...\n"
710 "You should install libdc1394-2 to use this example.") ;
static void write(const vpImage< unsigned char > &I, const char *filename)
static std::string colorCoding2string(vp1394TwoColorCodingType colorcoding)
static std::string framerate2string(vp1394TwoFramerateType fps)
unsigned int getWidth() const
Define the X11 console to display images.
static double measureTimeMs()
static int wait(double t0, double t)
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)
static std::string videoMode2string(vp1394TwoVideoModeType videomode)
unsigned int getHeight() const
Class for firewire ieee1394 video devices using libdc1394-2.x api.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)