2 #include <visp3/core/vpTime.h> 3 #include <visp3/gui/vpDisplayGDI.h> 4 #include <visp3/gui/vpDisplayGTK.h> 5 #include <visp3/gui/vpDisplayOpenCV.h> 6 #include <visp3/gui/vpDisplayX.h> 7 #include <visp3/io/vpVideoWriter.h> 8 #include <visp3/sensor/vpV4l2Grabber.h> 27 int main(
int argc,
const char *argv[])
29 #if ((defined(VISP_HAVE_V4L2) || (VISP_HAVE_OPENCV_VERSION >= 0x020100)) && \ 30 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK))) 31 std::string opt_videoname =
"video-recorded.mpg";
34 for (
int i = 0; i < argc; i++) {
35 if (std::string(argv[i]) ==
"--device")
36 opt_device = atoi(argv[i + 1]);
37 else if (std::string(argv[i]) ==
"--name")
38 opt_videoname = std::string(argv[i + 1]);
39 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
40 std::cout <<
"\nUsage: " << argv[0]
41 <<
" [--device <device number>] [--name <video name>] [--help][-h]\n" 47 std::cout <<
"Use device: " << opt_device << std::endl;
48 std::cout <<
"Record video in: " << opt_videoname << std::endl;
54 #if defined(VISP_HAVE_V4L2) 56 std::ostringstream device;
57 device <<
"/dev/video" << opt_device;
62 #elif defined(VISP_HAVE_OPENCV) 63 cv::VideoCapture g(opt_device);
65 std::cout <<
"Failed to open the camera" << std::endl;
75 #if defined(VISP_HAVE_X11) 77 #elif defined(VISP_HAVE_GDI) 79 #elif defined(VISP_HAVE_OPENCV) 81 #elif defined(VISP_HAVE_GTK) 84 d.
init(I, 0, 0,
"Camera view");
87 #if VISP_HAVE_OPENCV_VERSION >= 0x030000 88 writer.
setCodec(cv::VideoWriter::fourcc(
'P',
'I',
'M',
'1'));
89 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100 90 writer.
setCodec(CV_FOURCC(
'P',
'I',
'M',
'1'));
94 bool recording =
false;
97 #if defined(VISP_HAVE_V4L2) 99 #elif defined(VISP_HAVE_OPENCV) 104 if (recording ==
false) {
117 std::cout <<
"The video was recorded in \"" << opt_videoname <<
"\"" << std::endl;
119 std::cout <<
"Catch an exception: " << e << std::endl;
124 std::cout <<
"Install OpenCV and rebuild ViSP to use this example." << std::endl;
void acquire(vpImage< unsigned char > &I)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void open(vpImage< unsigned char > &I)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Display for windows using GDI (available on any windows 32 platform).
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void setDevice(const std::string &devname)
error that can be emited by ViSP classes.
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
Class that enables to write easily a video file or a sequence of images.
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
void saveFrame(vpImage< vpRGBa > &I)
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
void open(vpImage< vpRGBa > &I)
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
unsigned int getHeight() const
void setCodec(const int fourcc_codec)
void setFileName(const std::string &filename)
unsigned int getWidth() const