#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImage.h>
#include <visp3/core/vpTime.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/io/vpParseArgv.h>
#include <visp3/sensor/vp1394CMUGrabber.h>
#define GRAB_COLOR
#define GETOPTARGS "dhn:o:"
#ifdef ENABLE_VISP_NAMESPACE
#endif
void usage(const char *name, const char *badparam, unsigned &nframes, std::string &opath);
bool getOptions(int argc, const char **argv, bool &display, unsigned int &nframes, bool &save, std::string &opath);
void usage(const char *name, const char *badparam, unsigned &nframes, std::string &opath)
{
fprintf(stdout, "\n\
Acquire images using CMU 1394 Digital Camera SDK (available under Windows only) and display\n\
it using GDI or OpenCV if GDI is not available.\n\
\n\
SYNOPSIS\n\
%s [-d] [-n] [-o] [-h] \n",
name);
fprintf(stdout, "\n\
OPTIONS: Default\n\
-d \n\
Turn off the display.\n\
\n\
-n [%%u] %u\n\
Number of frames to acquire. \n\
\n\
-o [%%s] \n\
Filename for image saving. \n\
Example: -o %s\n\
The %%d is for the image numbering.\n\
\n\
-h \n\
Print the help.\n\
\n",
nframes, opath.c_str());
if (badparam) {
fprintf(stderr, "ERROR: \n");
fprintf(stderr, "\nBad parameter [%s]\n", badparam);
}
}
bool getOptions(int argc, const char **argv, bool &display, unsigned int &nframes, bool &save, std::string &opath)
{
const char *optarg_;
int c;
switch (c) {
case 'd':
display = false;
break;
case 'n':
nframes = (unsigned int)atoi(optarg_);
break;
case 'o':
save = true;
opath = optarg_;
break;
case 'h':
usage(argv[0], nullptr, nframes, opath);
return false;
break;
default:
usage(argv[0], optarg_, nframes, opath);
return false;
break;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], nullptr, nframes, opath);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
return false;
}
return true;
}
#if defined(VISP_HAVE_CMU1394)
int main(int argc, const char **argv)
{
bool opt_display = true;
unsigned nframes = 50;
bool save = false;
#ifdef GRAB_COLOR
#else
#endif
#ifdef GRAB_COLOR
std::string opath = "C:/temp/I%04d.ppm";
#else
std::string opath = "C:/temp/I%04d.pgm";
#endif
if (getOptions(argc, argv, opt_display, nframes, save, opath) == false) {
return EXIT_FAILURE;
}
unsigned short gain_min, gain_max;
std::cout << "Gain range [" << gain_min << ", " << gain_max << "]" << std::endl;
unsigned short shutter_min, shutter_max;
std::cout << "Shutter range [" << shutter_min << ", " << shutter_max << "]" << std::endl;
std::cout <<
"Actual framerate: " << g.
getFramerate() << std::endl;
std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: " << I.
getHeight() << std::endl;
#if (defined(VISP_HAVE_GDI) || defined(HAVE_OPENCV_HIGHGUI))
#if defined(HAVE_OPENCV_HIGHGUI)
#elif defined(VISP_HAVE_GDI)
#endif
if (opt_display) {
display.init(I, 100, 100, "Current image");
}
#endif
try {
double tbegin = 0, ttotal = 0;
ttotal = 0;
for (unsigned i = 0; i < nframes; i++) {
#if (defined(VISP_HAVE_GDI) || defined(HAVE_OPENCV_HIGHGUI))
if (opt_display) {
break;
}
#endif
if (save) {
char buf[FILENAME_MAX];
snprintf(buf, FILENAME_MAX, opath.c_str(), i);
std::string filename(buf);
std::cout << "Write: " << filename << std::endl;
}
double tloop = tend - tbegin;
tbegin = tend;
std::cout << "loop time: " << tloop << " ms" << std::endl;
ttotal += tloop;
}
std::cout << "Mean loop time: " << ttotal / nframes << " ms" << std::endl;
std::cout << "Mean frequency: " << 1000. / (ttotal / nframes) << " fps" << std::endl;
return EXIT_SUCCESS;
}
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
}
#else
int main()
{
std::cout << "This example requires CMU 1394 Digital Camera SDK. " << std::endl;
std::cout << "Tip if you are on a windows-like system:" << std::endl;
std::cout << "- Install CMU 1394 SDK, configure again ViSP using cmake and build again this example" << std::endl;
return EXIT_SUCCESS;
}
#endif
Firewire cameras video capture based on CMU 1394 Digital Camera SDK.
void getGainMinMax(unsigned short &min, unsigned short &max)
void setVideoMode(unsigned long format, unsigned long mode)
void acquire(vpImage< unsigned char > &I)
void setFramerate(unsigned long fps)
void getShutterMinMax(unsigned short &min, unsigned short &max)
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
unsigned int getWidth() const
unsigned int getHeight() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
VISP_EXPORT double measureTimeMs()