54 #include <visp3/core/vpConfig.h> 55 #include <visp3/core/vpDebug.h> 61 #if defined(VISP_HAVE_DC1394) 63 #include <visp3/sensor/vp1394TwoGrabber.h> 64 #include <visp3/core/vpImage.h> 65 #include <visp3/io/vpImageIo.h> 66 #include <visp3/core/vpDisplay.h> 67 #include <visp3/gui/vpDisplayX.h> 68 #include <visp3/core/vpTime.h> 69 #include <visp3/io/vpParseArgv.h> 70 #include <visp3/core/vpRGBa.h> 76 #define GETOPTARGS "b:c:df:g:hH:L:mn:io:p:rsT:v:W:" 79 void usage(
const char *name,
const char *badparam,
unsigned int camera,
80 const unsigned int &nframes,
const std::string &opath,
81 const unsigned int &roi_left,
const unsigned int &roi_top,
82 const unsigned int &roi_width,
const unsigned int &roi_height,
83 const unsigned int &ringbuffersize,
const unsigned int &panControl);
84 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
85 unsigned int &nframes,
bool &verbose_info,
86 bool &verbose_settings,
87 bool &videomode_is_set,
89 bool &framerate_is_set,
91 bool &colorcoding_is_set,
93 bool &ringbuffersize_is_set,
94 unsigned int &ringbuffersize,
95 bool &display,
bool &save, std::string &opath,
96 unsigned int &roi_left,
unsigned int &roi_top,
97 unsigned int &roi_width,
unsigned int &roi_height,
99 unsigned int &panControl,
bool & panControl_is_set);
116 void usage(
const char *name,
const char *badparam,
unsigned int camera,
117 const unsigned int &nframes,
const std::string &opath,
118 const unsigned int &roi_left,
const unsigned int &roi_top,
119 const unsigned int &roi_width,
const unsigned int &roi_height,
120 const unsigned int &ringbuffersize,
const unsigned int &panControl)
123 fprintf(stderr,
"\nERROR: Bad parameter [%s]\n", badparam);
127 %s [-v <video mode>] [-f <framerate>] \n\ 128 [-g <color coding>] [-c <camera id>] [-m] [-n <frames>] \n\ 129 [-i] [-s] [-d] [-o <filename>] [-L <format 7 roi left position>] \n\ 130 [-T <format 7 roi top position>] [-W <format 7 roi width>] \n\ 131 [-H <format 7 roi height>] [-b <ring buffer size>] \n\ 132 [-p <pan control value>] [-R] [-h]\n\ 135 Test for firewire camera image acquisition.\n\ 140 Indicates the current settings for the first camera found on the bus.\n\n\ 142 Gives information on the first camera found on the bus.\n\n\ 144 Indicates the current settings for all the cameras found on the bus.\n\n\ 146 Gives information on all the cameras found on the bus.\n\ 148 Grab images from camera 1.\n\n\ 150 Grab images from all the cameras.\n\n\ 152 If a stereo camera is connected to the bus like the PointGrey Bumblebee,\n\ 153 you may set the pan control to select the camera view:\n\ 155 Transmit right imge.\n\ 157 Transmit left imge.\n\ 160 -v [%%u] : Video mode to set for the active camera.\n\ 161 Use -s option so see which are the supported \n\ 162 video modes. You can select the active \n\ 163 camera using -c option.\n\ 165 -f [%%u] : Framerate to set for the active camera.\n\ 166 Use -s option so see which are the supported \n\ 167 framerates. You can select the active \n\ 168 camera using -c option.\n\ 170 -g [%%u] : Color coding to set for the active camera\n\ 171 in format 7 video mode. Use -s option so see if \n\ 172 format 7 is supported by the camera and if so, \n\ 173 which are the supported color codings. You can \n\ 174 select the active camera using -c option.\n\ 175 See -t <top>, -l <left>, -w <width>, \n\ 176 -h <height> option to set format 7 roi.\n\ 178 -L [%%u] : Format 7 region of interest (roi) left %u\n\ 179 position. This option is only used if video\n\ 182 -T [%%u] : Format 7 region of interest (roi) top %u\n\ 183 position. This option is only used if video\n\ 186 -W [%%u] : Format 7 region of interest (roi) width. %u\n\ 187 Is set to zero, use the maximum width. This\n\ 188 option is only used if video mode is format 7.\n\ 190 -H [%%u] : Format 7 region of interest (roi) height. %u\n\ 191 Is set to zero, use the maximum height. This\n\ 192 option is only used if video mode is format 7.\n\ 194 -c [%%u] : Active camera identifier. %u\n\ 195 Zero is for the first camera found on the bus.\n\ 197 -m : Flag to active multi camera acquisition. \n\ 198 You need at least two cameras connected on \n\ 201 -n [%%u] : Number of frames to acquire. %u\n\ 203 -i : Flag to print camera information.\n\ 205 -s : Print camera settings capabilities such as \n\ 206 video mode and framerates available and exit.\n\ 208 -d : Flag to turn off image display.\n\ 210 -b [%%u] : Ring buffer size used during capture %u\n\ 212 -p [%%u] : Pan control value used to control single or %u\n\ 213 multiple image transmission from stereo vision \n\ 214 cameras by setting the PAN register 0x884.\n\ 216 -o [%%s] : Filename for image saving. \n\ 218 The first %%d is for the camera id. The second\n\ 219 %%04d is for the image numbering. The format is set \n\ 220 by the extension of the file (ex .png, .pgm, ...) \n\ 222 -r : Reset the bus attached to the first camera found.\n\ 223 Bus reset may help to make firewire working if the\n\ 224 program was not properly stopped by a CTRL-C.\n\ 226 -h : Print this help.\n\ 228 name, name, name, name, name, name, name, name, name,
229 roi_left, roi_top, roi_width, roi_height,
230 camera, nframes, ringbuffersize, panControl, opath.c_str());
275 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
276 unsigned int &nframes,
bool &verbose_info,
277 bool &verbose_settings,
278 bool &videomode_is_set,
280 bool &framerate_is_set,
282 bool &colorcoding_is_set,
284 bool &ringbuffersize_is_set,
285 unsigned int &ringbuffersize,
286 bool &display,
bool &save, std::string &opath,
287 unsigned int &roi_left,
unsigned int &roi_top,
288 unsigned int &roi_width,
unsigned int &roi_height,
290 unsigned int &panControl,
bool & panControl_is_set)
301 camera = (
unsigned int)atoi(optarg_);
break;
303 display =
false;
break;
305 framerate_is_set =
true;
309 colorcoding_is_set =
true;
313 roi_height = (
unsigned int) atoi(optarg_);
break;
315 verbose_info =
true;
break;
317 roi_left = (
unsigned int) atoi(optarg_);
break;
321 nframes = (
unsigned int)atoi(optarg_);
break;
324 opath = optarg_;
break;
326 ringbuffersize_is_set =
true;
327 ringbuffersize = (
unsigned int) atoi(optarg_);
break;
329 panControl = (
unsigned int) atoi(optarg_);
330 panControl_is_set =
true;
335 verbose_settings =
true;
break;
337 roi_top = (
unsigned int) atoi(optarg_);
break;
339 videomode_is_set =
true;
343 roi_width = (
unsigned int) atoi(optarg_);
break;
346 usage(argv[0], NULL, camera, nframes, opath,
347 roi_left, roi_top, roi_width, roi_height, ringbuffersize,
354 if ((c == 1) || (c == -1)) {
356 usage(argv[0], NULL, camera, nframes, opath,
357 roi_left, roi_top, roi_width, roi_height, ringbuffersize, panControl);
358 std::cerr <<
"ERROR: " << std::endl;
359 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
374 main(
int argc,
const char ** argv)
377 unsigned int camera = 0;
379 bool verbose_info =
false;
380 bool verbose_settings =
false;
382 unsigned int nframes = 50;
384 bool videomode_is_set =
false;
386 bool framerate_is_set =
false;
388 bool colorcoding_is_set =
false;
390 bool ringbuffersize_is_set =
false;
391 unsigned int ringbuffersize = 4;
394 unsigned int panControl = 0;
395 bool panControl_is_set =
false;
398 unsigned int roi_left=0, roi_top=0, roi_width=0, roi_height=0;
401 std::string opath =
"/tmp/I%d-%04d.ppm";
403 read_options(argc, argv, multi, camera, nframes,
404 verbose_info, verbose_settings,
405 videomode_is_set, videomode,
406 framerate_is_set, framerate,
407 colorcoding_is_set, colorcoding,
408 ringbuffersize_is_set, ringbuffersize,
409 display, save, opath,
410 roi_left, roi_top, roi_width, roi_height, reset,
411 panControl, panControl_is_set);
423 unsigned int ncameras = 0;
424 g.getNumCameras(ncameras);
426 std::cout <<
"Number of cameras on the bus: " << ncameras << std::endl;
432 std::cout <<
"You have only " << ncameras <<
" camera connected on the bus." << std::endl;
433 std::cout <<
"It is not possible to active multi-camera acquisition." << std::endl;
434 std::cout <<
"Disable -m command line option, or connect an other " << std::endl;
435 std::cout <<
"cameras on the bus." << std::endl;
440 if (camera >= ncameras) {
441 std::cout <<
"You have only " << ncameras;
442 std::cout <<
" camera connected on the bus." << std::endl;
443 std::cout <<
"It is not possible to select camera " << camera << std::endl;
444 std::cout <<
"Check your -c <camera> command line option." << std::endl;
461 if (verbose_info || verbose_settings) {
462 for (
unsigned int i=0; i < ncameras; i ++) {
464 g.setCamera(i+offset);
469 if (verbose_settings) {
473 std::list<vp1394TwoGrabber::vp1394TwoVideoModeType> lmode;
474 std::list<vp1394TwoGrabber::vp1394TwoFramerateType> lfps;
475 std::list<vp1394TwoGrabber::vp1394TwoColorCodingType> lcoding;
476 std::list<vp1394TwoGrabber::vp1394TwoVideoModeType>::const_iterator it_lmode;
477 std::list<vp1394TwoGrabber::vp1394TwoFramerateType>::const_iterator it_lfps;
478 std::list<vp1394TwoGrabber::vp1394TwoColorCodingType>::const_iterator it_lcoding;
481 g.getVideoMode(curmode);
482 g.getFramerate(curfps);
483 g.getColorCoding(curcoding);
484 g.getVideoModeSupported(lmode);
487 std::cout <<
"----------------------------------------------------------" 489 <<
"---- Video modes and framerates supported by camera " 490 << i+offset <<
" ----" << std::endl
491 <<
"---- with guid 0x" << std::hex << guid <<
" ----" << std::endl
492 <<
"---- * is for the current settings ----" 494 <<
"---- between ( ) you have the corresponding option ----" 496 <<
"---- to use. ----" 498 <<
"----------------------------------------------------------" 501 for (it_lmode = lmode.begin(); it_lmode != lmode.end(); ++it_lmode) {
504 if (curmode == supmode)
506 <<
" (-v " << (int)supmode <<
")" << std::endl;
509 <<
" (-v " << (int)supmode <<
")" << std::endl;
511 if (g.isVideoModeFormat7(supmode)){
514 g.getColorCodingSupported(supmode, lcoding);
515 for (it_lcoding = lcoding.begin(); it_lcoding != lcoding.end(); ++it_lcoding) {
517 supcoding = *it_lcoding;
518 if ( (curmode == supmode) && (supcoding == curcoding) )
521 <<
" (-g " << (int)supcoding <<
")" << std::endl;
525 <<
" (-g " << (int)supcoding <<
")" << std::endl;
531 g.getFramerateSupported(supmode, lfps);
532 for (it_lfps = lfps.begin(); it_lfps != lfps.end(); ++it_lfps) {
534 if ( (curmode == supmode) && (supfps == curfps) )
537 <<
" (-f " << (int)supfps <<
")" << std::endl;
541 <<
" (-f " << (int)supfps <<
")" << std::endl;
545 std::cout <<
"----------------------------------------------------------" 555 if (panControl_is_set) {
556 g.setPanControl(panControl);
560 if (videomode_is_set) {
562 g.setVideoMode(videomode);
567 g.getVideoMode(videomode);
569 if (framerate_is_set) {
571 g.setFramerate(framerate);
573 if (colorcoding_is_set) {
575 g.setColorCoding(colorcoding);
577 if (ringbuffersize_is_set) {
578 g.setRingBufferSize(ringbuffersize);
582 if (g.isVideoModeFormat7(videomode))
583 g.setFormat7ROI(roi_left, roi_top, roi_width, roi_height);
586 bool *grab_color =
new bool [ncameras];
600 for (
unsigned int i=0; i < ncameras; i ++) {
602 g.setCamera(i+offset);
605 grab_color[i] = g.isColor();
609 std::cout <<
"Image size for camera " << i+offset <<
" : width: " 617 sprintf(title,
"Images captured by camera %u", i+offset);
618 d[i].
init(Ic[i], (
int)(100+i*50), (
int)(100+i*50), title) ;
626 std::cout <<
"Image size for camera " << i+offset <<
" : width: " 634 sprintf(title,
"Images captured by camera %u", i+offset);
635 d[i].
init(Ig[i], (
int)(100+i*50), (
int)(100+i*50), title) ;
645 std::cout <<
"Capture in process..." << std::endl;
647 double tbegin=0, tend=0, tloop=0, ttotal=0;
651 for (
unsigned int i = 0; i < nframes; i++) {
652 for (
unsigned int c = 0; c < ncameras; c++) {
654 g.setCamera(c+offset);
678 char buf[FILENAME_MAX];
679 sprintf(buf, opath.c_str(), c+offset, i);
680 std::string filename(buf);
681 std::cout <<
"Write: " << filename << std::endl;
691 tloop = tend - tbegin;
693 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
697 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
698 std::cout <<
"Mean frequency: " << 1000./(ttotal / nframes) <<
" fps" << std::endl;
707 delete [] grab_color;
716 std::cout <<
"Catch an exception: " << e << std::endl;
724 vpTRACE(
"Ieee 1394 grabber capabilities are not available...\n" 725 "You should install libdc1394-2 to use this example.") ;
static void write(const vpImage< unsigned char > &I, const char *filename)
VISP_EXPORT int wait(double t0, double t)
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 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)
VISP_EXPORT double measureTimeMs()
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)