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:"
83 void usage(
const char *name,
const char *badparam,
unsigned int camera,
84 const unsigned int &nframes,
const std::string &opath,
85 const unsigned int &roi_left,
const unsigned int &roi_top,
86 const unsigned int &roi_width,
const unsigned int &roi_height,
87 const unsigned int &ringbuffersize,
const unsigned int &panControl);
88 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
89 unsigned int &nframes,
bool &verbose_info,
90 bool &verbose_settings,
91 bool &videomode_is_set,
93 bool &framerate_is_set,
95 bool &colorcoding_is_set,
97 bool &ringbuffersize_is_set,
98 unsigned int &ringbuffersize,
99 bool &display,
bool &save, std::string &opath,
100 unsigned int &roi_left,
unsigned int &roi_top,
101 unsigned int &roi_width,
unsigned int &roi_height,
103 unsigned int &panControl,
bool & panControl_is_set);
120 void usage(
const char *name,
const char *badparam,
unsigned int camera,
121 const unsigned int &nframes,
const std::string &opath,
122 const unsigned int &roi_left,
const unsigned int &roi_top,
123 const unsigned int &roi_width,
const unsigned int &roi_height,
124 const unsigned int &ringbuffersize,
const unsigned int &panControl)
127 fprintf(stderr,
"\nERROR: Bad parameter [%s]\n", badparam);
131 %s [-v <video mode>] [-f <framerate>] \n\
132 [-g <color coding>] [-c <camera id>] [-m] [-n <frames>] \n\
133 [-i] [-s] [-d] [-o <filename>] [-L <format 7 roi left position>] \n\
134 [-T <format 7 roi top position>] [-W <format 7 roi width>] \n\
135 [-H <format 7 roi height>] [-b <ring buffer size>] \n\
136 [-p <pan control value>] [-R] [-h]\n\
139 Test for firewire camera image acquisition.\n\
144 Indicates the current settings for the first camera found on the bus.\n\n\
146 Gives information on the first camera found on the bus.\n\n\
148 Indicates the current settings for all the cameras found on the bus.\n\n\
150 Gives information on all the cameras found on the bus.\n\
152 Grab images from camera 1.\n\n\
154 Grab images from all the cameras.\n\n\
156 If a stereo camera is connected to the bus like the PointGrey Bumblebee,\n\
157 you may set the pan control to select the camera view:\n\
159 Transmit right imge.\n\
161 Transmit left imge.\n\
164 -v [%%u] : Video mode to set for the active camera.\n\
165 Use -s option so see which are the supported \n\
166 video modes. You can select the active \n\
167 camera using -c option.\n\
169 -f [%%u] : Framerate to set for the active camera.\n\
170 Use -s option so see which are the supported \n\
171 framerates. You can select the active \n\
172 camera using -c option.\n\
174 -g [%%u] : Color coding to set for the active camera\n\
175 in format 7 video mode. Use -s option so see if \n\
176 format 7 is supported by the camera and if so, \n\
177 which are the supported color codings. You can \n\
178 select the active camera using -c option.\n\
179 See -t <top>, -l <left>, -w <width>, \n\
180 -h <height> option to set format 7 roi.\n\
182 -L [%%u] : Format 7 region of interest (roi) left %u\n\
183 position. This option is only used if video\n\
186 -T [%%u] : Format 7 region of interest (roi) top %u\n\
187 position. This option is only used if video\n\
190 -W [%%u] : Format 7 region of interest (roi) width. %u\n\
191 Is set to zero, use the maximum width. This\n\
192 option is only used if video mode is format 7.\n\
194 -H [%%u] : Format 7 region of interest (roi) height. %u\n\
195 Is set to zero, use the maximum height. This\n\
196 option is only used if video mode is format 7.\n\
198 -c [%%u] : Active camera identifier. %u\n\
199 Zero is for the first camera found on the bus.\n\
201 -m : Flag to active multi camera acquisition. \n\
202 You need at least two cameras connected on \n\
205 -n [%%u] : Number of frames to acquire. %u\n\
207 -i : Flag to print camera information.\n\
209 -s : Print camera settings capabilities such as \n\
210 video mode and framerates available and exit.\n\
212 -d : Flag to turn off image display.\n\
214 -b [%%u] : Ring buffer size used during capture %u\n\
216 -p [%%u] : Pan control value used to control single or %u\n\
217 multiple image transmission from stereo vision \n\
218 cameras by setting the PAN register 0x884.\n\
220 -o [%%s] : Filename for image saving. \n\
222 The first %%d is for the camera id. The second\n\
223 %%04d is for the image numbering. The format is set \n\
224 by the extension of the file (ex .png, .pgm, ...) \n\
226 -r : Reset the bus attached to the first camera found.\n\
227 Bus reset may help to make firewire working if the\n\
228 program was not properly stopped by a CTRL-C.\n\
230 -h : Print this help.\n\
232 name, name, name, name, name, name, name, name, name,
233 roi_left, roi_top, roi_width, roi_height,
234 camera, nframes, ringbuffersize, panControl, opath.c_str());
279 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
280 unsigned int &nframes,
bool &verbose_info,
281 bool &verbose_settings,
282 bool &videomode_is_set,
284 bool &framerate_is_set,
286 bool &colorcoding_is_set,
288 bool &ringbuffersize_is_set,
289 unsigned int &ringbuffersize,
290 bool &display,
bool &save, std::string &opath,
291 unsigned int &roi_left,
unsigned int &roi_top,
292 unsigned int &roi_width,
unsigned int &roi_height,
294 unsigned int &panControl,
bool & panControl_is_set)
305 camera = (
unsigned int)atoi(optarg_);
break;
307 display =
false;
break;
309 framerate_is_set =
true;
313 colorcoding_is_set =
true;
317 roi_height = (
unsigned int) atoi(optarg_);
break;
319 verbose_info =
true;
break;
321 roi_left = (
unsigned int) atoi(optarg_);
break;
325 nframes = (
unsigned int)atoi(optarg_);
break;
328 opath = optarg_;
break;
330 ringbuffersize_is_set =
true;
331 ringbuffersize = (
unsigned int) atoi(optarg_);
break;
333 panControl = (
unsigned int) atoi(optarg_);
334 panControl_is_set =
true;
339 verbose_settings =
true;
break;
341 roi_top = (
unsigned int) atoi(optarg_);
break;
343 videomode_is_set =
true;
347 roi_width = (
unsigned int) atoi(optarg_);
break;
350 usage(argv[0], NULL, camera, nframes, opath,
351 roi_left, roi_top, roi_width, roi_height, ringbuffersize,
358 if ((c == 1) || (c == -1)) {
360 usage(argv[0], NULL, camera, nframes, opath,
361 roi_left, roi_top, roi_width, roi_height, ringbuffersize, panControl);
362 std::cerr <<
"ERROR: " << std::endl;
363 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
378 main(
int argc,
const char ** argv)
381 unsigned int camera = 0;
383 bool verbose_info =
false;
384 bool verbose_settings =
false;
386 unsigned int nframes = 50;
388 bool videomode_is_set =
false;
390 bool framerate_is_set =
false;
392 bool colorcoding_is_set =
false;
394 bool ringbuffersize_is_set =
false;
395 unsigned int ringbuffersize = 4;
398 unsigned int panControl = 0;
399 bool panControl_is_set =
false;
402 unsigned int roi_left=0, roi_top=0, roi_width=0, roi_height=0;
405 std::string opath =
"/tmp/I%d-%04d.ppm";
407 read_options(argc, argv, multi, camera, nframes,
408 verbose_info, verbose_settings,
409 videomode_is_set, videomode,
410 framerate_is_set, framerate,
411 colorcoding_is_set, colorcoding,
412 ringbuffersize_is_set, ringbuffersize,
413 display, save, opath,
414 roi_left, roi_top, roi_width, roi_height, reset,
415 panControl, panControl_is_set);
427 unsigned int ncameras = 0;
428 g.getNumCameras(ncameras);
430 std::cout <<
"Number of cameras on the bus: " << ncameras << std::endl;
436 std::cout <<
"You have only " << ncameras <<
" camera connected on the bus." << std::endl;
437 std::cout <<
"It is not possible to active multi-camera acquisition." << std::endl;
438 std::cout <<
"Disable -m command line option, or connect an other " << std::endl;
439 std::cout <<
"cameras on the bus." << std::endl;
444 if (camera >= ncameras) {
445 std::cout <<
"You have only " << ncameras;
446 std::cout <<
" camera connected on the bus." << std::endl;
447 std::cout <<
"It is not possible to select camera " << camera << std::endl;
448 std::cout <<
"Check your -c <camera> command line option." << std::endl;
465 if (verbose_info || verbose_settings) {
466 for (
unsigned int i=0; i < ncameras; i ++) {
468 g.setCamera(i+offset);
473 if (verbose_settings) {
477 std::list<vp1394TwoGrabber::vp1394TwoVideoModeType> lmode;
478 std::list<vp1394TwoGrabber::vp1394TwoFramerateType> lfps;
479 std::list<vp1394TwoGrabber::vp1394TwoColorCodingType> lcoding;
480 std::list<vp1394TwoGrabber::vp1394TwoVideoModeType>::const_iterator it_lmode;
481 std::list<vp1394TwoGrabber::vp1394TwoFramerateType>::const_iterator it_lfps;
482 std::list<vp1394TwoGrabber::vp1394TwoColorCodingType>::const_iterator it_lcoding;
485 g.getVideoMode(curmode);
486 g.getFramerate(curfps);
487 g.getColorCoding(curcoding);
488 g.getVideoModeSupported(lmode);
491 std::cout <<
"----------------------------------------------------------"
493 <<
"---- Video modes and framerates supported by camera "
494 << i+offset <<
" ----" << std::endl
495 <<
"---- with guid 0x" << std::hex << guid <<
" ----" << std::endl
496 <<
"---- * is for the current settings ----"
498 <<
"---- between ( ) you have the corresponding option ----"
500 <<
"---- to use. ----"
502 <<
"----------------------------------------------------------"
505 for (it_lmode = lmode.begin(); it_lmode != lmode.end(); ++it_lmode) {
508 if (curmode == supmode)
510 <<
" (-v " << (int)supmode <<
")" << std::endl;
513 <<
" (-v " << (int)supmode <<
")" << std::endl;
515 if (g.isVideoModeFormat7(supmode)){
518 g.getColorCodingSupported(supmode, lcoding);
519 for (it_lcoding = lcoding.begin(); it_lcoding != lcoding.end(); ++it_lcoding) {
521 supcoding = *it_lcoding;
522 if ( (curmode == supmode) && (supcoding == curcoding) )
525 <<
" (-g " << (int)supcoding <<
")" << std::endl;
529 <<
" (-g " << (int)supcoding <<
")" << std::endl;
535 g.getFramerateSupported(supmode, lfps);
536 for (it_lfps = lfps.begin(); it_lfps != lfps.end(); ++it_lfps) {
538 if ( (curmode == supmode) && (supfps == curfps) )
541 <<
" (-f " << (int)supfps <<
")" << std::endl;
545 <<
" (-f " << (int)supfps <<
")" << std::endl;
549 std::cout <<
"----------------------------------------------------------"
559 if (panControl_is_set) {
560 g.setPanControl(panControl);
564 if (videomode_is_set) {
566 g.setVideoMode(videomode);
571 g.getVideoMode(videomode);
573 if (framerate_is_set) {
575 g.setFramerate(framerate);
577 if (colorcoding_is_set) {
579 g.setColorCoding(colorcoding);
581 if (ringbuffersize_is_set) {
582 g.setRingBufferSize(ringbuffersize);
586 if (g.isVideoModeFormat7(videomode))
587 g.setFormat7ROI(roi_left, roi_top, roi_width, roi_height);
590 bool *grab_color =
new bool [ncameras];
604 for (
unsigned int i=0; i < ncameras; i ++) {
606 g.setCamera(i+offset);
609 grab_color[i] = g.isColor();
613 std::cout <<
"Image size for camera " << i+offset <<
" : width: "
621 sprintf(title,
"Images captured by camera %u", i+offset);
622 d[i].
init(Ic[i], (
int)(100+i*50), (
int)(100+i*50), title) ;
630 std::cout <<
"Image size for camera " << i+offset <<
" : width: "
638 sprintf(title,
"Images captured by camera %u", i+offset);
639 d[i].
init(Ig[i], (
int)(100+i*50), (
int)(100+i*50), title) ;
649 std::cout <<
"Capture in process..." << std::endl;
651 double tbegin=0, tend=0, tloop=0, ttotal=0;
655 for (
unsigned int i = 0; i < nframes; i++) {
656 for (
unsigned int c = 0; c < ncameras; c++) {
658 g.setCamera(c+offset);
682 char buf[FILENAME_MAX];
683 sprintf(buf, opath.c_str(), c+offset, i);
684 std::string filename(buf);
685 std::cout <<
"Write: " << filename << std::endl;
695 tloop = tend - tbegin;
697 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
701 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
702 std::cout <<
"Mean frequency: " << 1000./(ttotal / nframes) <<
" fps" << std::endl;
711 delete [] grab_color;
720 std::cout <<
"Catch an exception: " << e << std::endl;
728 vpTRACE(
"Ieee 1394 grabber capabilities are not available...\n"
729 "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.
error that can be emited by ViSP classes.
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)