57 #include <visp3/core/vpConfig.h> 58 #include <visp3/core/vpDebug.h> 59 #if defined(VISP_HAVE_DC1394) 61 #include <visp3/core/vpDisplay.h> 62 #include <visp3/core/vpImage.h> 63 #include <visp3/core/vpRGBa.h> 64 #include <visp3/core/vpTime.h> 65 #include <visp3/gui/vpDisplayX.h> 66 #include <visp3/io/vpImageIo.h> 67 #include <visp3/io/vpParseArgv.h> 68 #include <visp3/sensor/vp1394TwoGrabber.h> 73 #define GETOPTARGS "b:c:df:g:hH:L:mn:io:p:rsT:v:W:" 76 void usage(
const char *name,
const char *badparam,
unsigned int camera,
const unsigned int &nframes,
77 const std::string &opath,
const unsigned int &roi_left,
const unsigned int &roi_top,
78 const unsigned int &roi_width,
const unsigned int &roi_height,
const unsigned int &ringbuffersize,
79 const unsigned int &panControl);
80 void read_options(
int argc,
const char **argv,
bool &multi,
unsigned int &camera,
unsigned int &nframes,
81 bool &verbose_info,
bool &verbose_settings,
bool &videomode_is_set,
85 unsigned int &ringbuffersize,
bool &display,
bool &save, std::string &opath,
unsigned int &roi_left,
86 unsigned int &roi_top,
unsigned int &roi_width,
unsigned int &roi_height,
bool &reset,
87 unsigned int &panControl,
bool &panControl_is_set);
104 void usage(
const char *name,
const char *badparam,
unsigned int camera,
const unsigned int &nframes,
105 const std::string &opath,
const unsigned int &roi_left,
const unsigned int &roi_top,
106 const unsigned int &roi_width,
const unsigned int &roi_height,
const unsigned int &ringbuffersize,
107 const unsigned int &panControl)
110 fprintf(stderr,
"\nERROR: Bad parameter [%s]\n", badparam);
114 %s [-v <video mode>] [-f <framerate>] \n\ 115 [-g <color coding>] [-c <camera id>] [-m] [-n <frames>] \n\ 116 [-i] [-s] [-d] [-o <filename>] [-L <format 7 roi left position>] \n\ 117 [-T <format 7 roi top position>] [-W <format 7 roi width>] \n\ 118 [-H <format 7 roi height>] [-b <ring buffer size>] \n\ 119 [-p <pan control value>] [-R] [-h]\n\ 122 Test for firewire camera image acquisition.\n\ 127 Indicates the current settings for the first camera found on the bus.\n\n\ 129 Gives information on the first camera found on the bus.\n\n\ 131 Indicates the current settings for all the cameras found on the bus.\n\n\ 133 Gives information on all the cameras found on the bus.\n\ 135 Grab images from camera 1.\n\n\ 137 Grab images from all the cameras.\n\n\ 139 If a stereo camera is connected to the bus like the PointGrey Bumblebee,\n\ 140 you may set the pan control to select the camera view:\n\ 142 Transmit right imge.\n\ 144 Transmit left imge.\n\ 147 -v [%%u] : Video mode to set for the active camera.\n\ 148 Use -s option so see which are the supported \n\ 149 video modes. You can select the active \n\ 150 camera using -c option.\n\ 152 -f [%%u] : Framerate to set for the active camera.\n\ 153 Use -s option so see which are the supported \n\ 154 framerates. You can select the active \n\ 155 camera using -c option.\n\ 157 -g [%%u] : Color coding to set for the active camera\n\ 158 in format 7 video mode. Use -s option so see if \n\ 159 format 7 is supported by the camera and if so, \n\ 160 which are the supported color codings. You can \n\ 161 select the active camera using -c option.\n\ 162 See -t <top>, -l <left>, -w <width>, \n\ 163 -h <height> option to set format 7 roi.\n\ 165 -L [%%u] : Format 7 region of interest (roi) left %u\n\ 166 position. This option is only used if video\n\ 169 -T [%%u] : Format 7 region of interest (roi) top %u\n\ 170 position. This option is only used if video\n\ 173 -W [%%u] : Format 7 region of interest (roi) width. %u\n\ 174 Is set to zero, use the maximum width. This\n\ 175 option is only used if video mode is format 7.\n\ 177 -H [%%u] : Format 7 region of interest (roi) height. %u\n\ 178 Is set to zero, use the maximum height. This\n\ 179 option is only used if video mode is format 7.\n\ 181 -c [%%u] : Active camera identifier. %u\n\ 182 Zero is for the first camera found on the bus.\n\ 184 -m : Flag to active multi camera acquisition. \n\ 185 You need at least two cameras connected on \n\ 188 -n [%%u] : Number of frames to acquire. %u\n\ 190 -i : Flag to print camera information.\n\ 192 -s : Print camera settings capabilities such as \n\ 193 video mode and framerates available and exit.\n\ 195 -d : Flag to turn off image display.\n\ 197 -b [%%u] : Ring buffer size used during capture %u\n\ 199 -p [%%u] : Pan control value used to control single or %u\n\ 200 multiple image transmission from stereo vision \n\ 201 cameras by setting the PAN register 0x884.\n\ 203 -o [%%s] : Filename for image saving. \n\ 205 The first %%d is for the camera id. The second\n\ 206 %%04d is for the image numbering. The format is set \n\ 207 by the extension of the file (ex .png, .pgm, ...) \n\ 209 -r : Reset the bus attached to the first camera found.\n\ 210 Bus reset may help to make firewire working if the\n\ 211 program was not properly stopped by a CTRL-C.\n\ 213 -h : Print this help.\n\ 214 \n", name, name, name, name, name, name, name, name, name, 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,
unsigned int &nframes,
261 bool &verbose_info,
bool &verbose_settings,
bool &videomode_is_set,
265 unsigned int &ringbuffersize,
bool &display,
bool &save, std::string &opath,
unsigned int &roi_left,
266 unsigned int &roi_top,
unsigned int &roi_width,
unsigned int &roi_height,
bool &reset,
267 unsigned int &panControl,
bool &panControl_is_set)
278 camera = (
unsigned int)atoi(optarg_);
284 framerate_is_set =
true;
288 colorcoding_is_set =
true;
292 roi_height = (
unsigned int)atoi(optarg_);
298 roi_left = (
unsigned int)atoi(optarg_);
304 nframes = (
unsigned int)atoi(optarg_);
311 ringbuffersize_is_set =
true;
312 ringbuffersize = (
unsigned int)atoi(optarg_);
315 panControl = (
unsigned int)atoi(optarg_);
316 panControl_is_set =
true;
322 verbose_settings =
true;
325 roi_top = (
unsigned int)atoi(optarg_);
328 videomode_is_set =
true;
332 roi_width = (
unsigned int)atoi(optarg_);
336 usage(argv[0], NULL, camera, nframes, opath, roi_left, roi_top, roi_width, roi_height, ringbuffersize,
343 if ((c == 1) || (c == -1)) {
345 usage(argv[0], NULL, camera, nframes, opath, roi_left, roi_top, roi_width, roi_height, ringbuffersize, panControl);
346 std::cerr <<
"ERROR: " << std::endl;
347 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
361 int main(
int argc,
const char **argv)
364 unsigned int camera = 0;
366 bool verbose_info =
false;
367 bool verbose_settings =
false;
369 unsigned int nframes = 50;
371 bool videomode_is_set =
false;
373 bool framerate_is_set =
false;
375 bool colorcoding_is_set =
false;
377 bool ringbuffersize_is_set =
false;
378 unsigned int ringbuffersize = 4;
381 unsigned int panControl = 0;
382 bool panControl_is_set =
false;
385 unsigned int roi_left = 0, roi_top = 0, roi_width = 0, roi_height = 0;
388 std::string opath =
"/tmp/I%d-%04d.ppm";
390 read_options(argc, argv, multi, camera, nframes, verbose_info, verbose_settings, videomode_is_set, videomode,
391 framerate_is_set, framerate, colorcoding_is_set, colorcoding, ringbuffersize_is_set, ringbuffersize,
392 display, save, opath, roi_left, roi_top, roi_width, roi_height, reset, panControl, panControl_is_set);
404 unsigned int ncameras = 0;
405 g.getNumCameras(ncameras);
407 std::cout <<
"Number of cameras on the bus: " << ncameras << std::endl;
413 std::cout <<
"You have only " << ncameras <<
" camera connected on the bus." << std::endl;
414 std::cout <<
"It is not possible to active multi-camera acquisition." << std::endl;
415 std::cout <<
"Disable -m command line option, or connect an other " << std::endl;
416 std::cout <<
"cameras on the bus." << std::endl;
421 if (camera >= ncameras) {
422 std::cout <<
"You have only " << ncameras;
423 std::cout <<
" camera connected on the bus." << std::endl;
424 std::cout <<
"It is not possible to select camera " << camera << std::endl;
425 std::cout <<
"Check your -c <camera> command line option." << std::endl;
441 if (verbose_info || verbose_settings) {
442 for (
unsigned int i = 0; i < ncameras; i++) {
444 g.setCamera(i + offset);
449 if (verbose_settings) {
453 std::list<vp1394TwoGrabber::vp1394TwoVideoModeType> lmode;
454 std::list<vp1394TwoGrabber::vp1394TwoFramerateType> lfps;
455 std::list<vp1394TwoGrabber::vp1394TwoColorCodingType> lcoding;
456 std::list<vp1394TwoGrabber::vp1394TwoVideoModeType>::const_iterator it_lmode;
457 std::list<vp1394TwoGrabber::vp1394TwoFramerateType>::const_iterator it_lfps;
458 std::list<vp1394TwoGrabber::vp1394TwoColorCodingType>::const_iterator it_lcoding;
461 g.getVideoMode(curmode);
462 g.getFramerate(curfps);
463 g.getColorCoding(curcoding);
464 g.getVideoModeSupported(lmode);
467 std::cout <<
"----------------------------------------------------------" << std::endl
468 <<
"---- Video modes and framerates supported by camera " << i + offset <<
" ----" << std::endl
469 <<
"---- with guid 0x" << std::hex << guid <<
" ----" << std::endl
470 <<
"---- * is for the current settings ----" << std::endl
471 <<
"---- between ( ) you have the corresponding option ----" << std::endl
472 <<
"---- to use. ----" << std::endl
473 <<
"----------------------------------------------------------" << std::endl;
475 for (it_lmode = lmode.begin(); it_lmode != lmode.end(); ++it_lmode) {
478 if (curmode == supmode)
485 if (g.isVideoModeFormat7(supmode)) {
488 g.getColorCodingSupported(supmode, lcoding);
489 for (it_lcoding = lcoding.begin(); it_lcoding != lcoding.end(); ++it_lcoding) {
491 supcoding = *it_lcoding;
492 if ((curmode == supmode) && (supcoding == curcoding))
502 g.getFramerateSupported(supmode, lfps);
503 for (it_lfps = lfps.begin(); it_lfps != lfps.end(); ++it_lfps) {
505 if ((curmode == supmode) && (supfps == curfps))
514 std::cout <<
"----------------------------------------------------------" << std::endl;
522 if (panControl_is_set) {
523 g.setPanControl(panControl);
527 if (videomode_is_set) {
529 g.setVideoMode(videomode);
533 g.getVideoMode(videomode);
535 if (framerate_is_set) {
537 g.setFramerate(framerate);
539 if (colorcoding_is_set) {
541 g.setColorCoding(colorcoding);
543 if (ringbuffersize_is_set) {
544 g.setRingBufferSize(ringbuffersize);
548 if (g.isVideoModeFormat7(videomode))
549 g.setFormat7ROI(roi_left, roi_top, roi_width, roi_height);
552 bool *grab_color =
new bool[ncameras];
566 for (
unsigned int i = 0; i < ncameras; i++) {
568 g.setCamera(i + offset);
571 grab_color[i] = g.isColor();
575 std::cout <<
"Image size for camera " << i + offset <<
" : width: " << Ic[i].
getWidth()
576 <<
" height: " << Ic[i].
getHeight() << std::endl;
582 sprintf(title,
"Images captured by camera %u", i + offset);
583 d[i].
init(Ic[i], (
int)(100 + i * 50), (
int)(100 + i * 50), title);
590 std::cout <<
"Image size for camera " << i + offset <<
" : width: " << Ig[i].
getWidth()
591 <<
" height: " << Ig[i].
getHeight() << std::endl;
597 sprintf(title,
"Images captured by camera %u", i + offset);
598 d[i].
init(Ig[i], (
int)(100 + i * 50), (
int)(100 + i * 50), title);
607 std::cout <<
"Capture in process..." << std::endl;
609 double tbegin = 0, ttotal = 0;
613 for (
unsigned int i = 0; i < nframes; i++) {
614 for (
unsigned int c = 0; c < ncameras; c++) {
616 g.setCamera(c + offset);
638 char buf[FILENAME_MAX];
639 sprintf(buf, opath.c_str(), c + offset, i);
640 std::string filename(buf);
641 std::cout <<
"Write: " << filename << std::endl;
650 double tloop = tend - tbegin;
652 std::cout <<
"loop time: " << tloop <<
" ms" << std::endl;
656 std::cout <<
"Mean loop time: " << ttotal / nframes <<
" ms" << std::endl;
657 std::cout <<
"Mean frequency: " << 1000. / (ttotal / nframes) <<
" fps" << std::endl;
674 std::cout <<
"Catch an exception: " << e << std::endl;
681 std::cout <<
"This example requires dc1394 SDK. " << std::endl;
682 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
683 std::cout <<
"- Install libdc1394-2, configure again ViSP using cmake and build again this example" << std::endl;
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
VISP_EXPORT int wait(double t0, double t)
static std::string colorCoding2string(vp1394TwoColorCodingType colorcoding)
static std::string framerate2string(vp1394TwoFramerateType fps)
unsigned int getWidth() const
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void write(const vpImage< unsigned char > &I, const std::string &filename)
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.