2 #include <visp3/core/vpConfig.h>
3 #include <visp3/core/vpTime.h>
4 #include <visp3/gui/vpDisplayFactory.h>
5 #include <visp3/gui/vpDisplayX.h>
6 #include <visp3/io/vpVideoWriter.h>
7 #include <visp3/sensor/vpV4l2Grabber.h>
9 #if defined(HAVE_OPENCV_VIDEOIO)
10 #include <opencv2/videoio.hpp>
30 int main(
int argc,
const char *argv[])
32 #if (defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO)) && defined(VISP_HAVE_DISPLAY)
33 #ifdef ENABLE_VISP_NAMESPACE
36 std::string opt_videoname =
"video-recorded.mpg";
39 for (
int i = 0; i < argc; i++) {
40 if (std::string(argv[i]) ==
"--device")
41 opt_device = atoi(argv[i + 1]);
42 else if (std::string(argv[i]) ==
"--recorded-name")
43 opt_videoname = std::string(argv[i + 1]);
44 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
45 std::cout <<
"\nUsage: " << argv[0]
46 <<
" [--device <device number>] [--recorded-name <video name>] [--help][-h]\n"
52 std::cout <<
"Use device: " << opt_device << std::endl;
53 std::cout <<
"Record video in: " << opt_videoname << std::endl;
59 #if defined(VISP_HAVE_V4L2)
60 std::cout <<
"Use v4l2 grabber..." << std::endl;
62 std::ostringstream device;
63 device <<
"/dev/video" << opt_device;
68 #elif defined(HAVE_OPENCV_VIDEOIO)
69 std::cout <<
"Use OpenCV grabber..." << std::endl;
70 cv::VideoCapture g(opt_device);
72 std::cout <<
"Failed to open the camera" << std::endl;
82 #if defined(VISP_HAVE_DISPLAY)
84 d->
init(I, 0, 0,
"Camera view");
88 #if defined(HAVE_OPENCV_VIDEOIO)
89 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
90 writer.
setCodec(cv::VideoWriter::fourcc(
'P',
'I',
'M',
'1'));
92 writer.
setCodec(CV_FOURCC(
'P',
'I',
'M',
'1'));
97 bool recording =
false;
100 #if defined(VISP_HAVE_V4L2)
102 #elif defined(HAVE_OPENCV_VIDEOIO)
107 if (recording ==
false) {
121 std::cout <<
"The video was recorded in \"" << opt_videoname <<
"\"" << std::endl;
122 #ifdef VISP_HAVE_DISPLAY
127 std::cout <<
"Catch an exception: " << e << std::endl;
132 std::cout <<
"Install OpenCV and rebuild ViSP to use this example." << std::endl;
static const vpColor green
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="") VP_OVERRIDE
Class that defines generic functionalities for display.
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)
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.