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>
10 #if defined(HAVE_OPENCV_VIDEOIO)
11 #include <opencv2/videoio.hpp>
31 int main(
int argc,
const char *argv [])
33 #if ((defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO)) && \
34 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(HAVE_OPENCV_HIGHGUI) || defined(VISP_HAVE_GTK)))
35 std::string opt_videoname =
"video-recorded.mpg";
38 for (
int i = 0; i < argc; i++) {
39 if (std::string(argv[i]) ==
"--device")
40 opt_device = atoi(argv[i + 1]);
41 else if (std::string(argv[i]) ==
"--name")
42 opt_videoname = std::string(argv[i + 1]);
43 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
44 std::cout <<
"\nUsage: " << argv[0] <<
" [--device <device number>] [--name <video name>] [--help][-h]\n"
50 std::cout <<
"Use device: " << opt_device << std::endl;
51 std::cout <<
"Record video in: " << opt_videoname << std::endl;
57 #if defined(VISP_HAVE_V4L2)
59 std::ostringstream device;
60 device <<
"/dev/video" << opt_device;
65 #elif defined(HAVE_OPENCV_VIDEOIO)
66 cv::VideoCapture g(opt_device);
68 std::cout <<
"Failed to open the camera" << std::endl;
78 #if defined(VISP_HAVE_X11)
80 #elif defined(VISP_HAVE_GDI)
82 #elif defined(HAVE_OPENCV_HIGHGUI)
84 #elif defined(VISP_HAVE_GTK)
87 d.
init(I, 0, 0,
"Camera view");
90 #if defined(HAVE_OPENCV_VIDEOIO)
91 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
92 writer.
setCodec(cv::VideoWriter::fourcc(
'P',
'I',
'M',
'1'));
94 writer.
setCodec(CV_FOURCC(
'P',
'I',
'M',
'1'));
99 bool recording =
false;
102 #if defined(VISP_HAVE_V4L2)
104 #elif defined(HAVE_OPENCV_VIDEOIO)
109 if (recording ==
false) {
123 std::cout <<
"The video was recorded in \"" << opt_videoname <<
"\"" << std::endl;
126 std::cout <<
"Catch an exception: " << e << std::endl;
131 std::cout <<
"Install OpenCV and rebuild ViSP to use this example." << std::endl;
static const vpColor green
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
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)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
unsigned int getWidth() const
unsigned int getHeight() const
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
void open(vpImage< unsigned char > &I)
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
void setDevice(const std::string &devname)
void acquire(vpImage< unsigned char > &I)
Class that enables to write easily a video file or a sequence of images.
void saveFrame(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
void open(vpImage< vpRGBa > &I)
void setCodec(const int fourcc_codec)