4#include <visp3/core/vpConfig.h>
13#if defined(VISP_HAVE_DISPLAY) && \
14 (defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_OPENCV) && \
15 (((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))))
17#include <visp3/core/vpTime.h>
18#include <visp3/gui/vpDisplayFactory.h>
19#include <visp3/io/vpVideoWriter.h>
20#include <visp3/sensor/vpV4l2Grabber.h>
22#if defined(VISP_HAVE_OPENCV) &&(VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)
23#include <opencv2/highgui/highgui.hpp>
24#elif defined(VISP_HAVE_OPENCV) &&(VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)
25#include <opencv2/videoio/videoio.hpp>
45int main(
int argc,
const char *argv[])
47#ifdef ENABLE_VISP_NAMESPACE
50 std::string opt_videoname =
"video-recorded.mpg";
53 for (
int i = 1;
i < argc;
i++) {
54 if (std::string(argv[i]) ==
"--device" && i + 1 < argc) {
55 opt_device = atoi(argv[i + 1]);
57 else if (std::string(argv[i]) ==
"--recorded-name" && i + 1 < argc) {
58 opt_videoname = std::string(argv[i + 1]);
60 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
61 std::cout <<
"\nUsage: " << argv[0]
62 <<
" [--device <device number>] [--recorded-name <video name>] [--help][-h]\n"
68 std::cout <<
"Use device: " << opt_device << std::endl;
69 std::cout <<
"Record video in: " << opt_videoname << std::endl;
75#if defined(VISP_HAVE_V4L2)
76 std::cout <<
"Use v4l2 grabber..." << std::endl;
78 std::ostringstream device;
79 device <<
"/dev/video" << opt_device;
84#elif defined(VISP_HAVE_OPENCV) && \
85 (((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \
86 ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))
87 std::cout <<
"Use OpenCV grabber..." << std::endl;
88 cv::VideoCapture g(opt_device);
90 std::cout <<
"Failed to open the camera" << std::endl;
98 std::cout <<
"Image size: " << I.getWidth() <<
" " << I.getHeight() << std::endl;
100#if defined(VISP_HAVE_DISPLAY)
105#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_VIDEOIO)
106#if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
107 writer.
setCodec(cv::VideoWriter::fourcc(
'P',
'I',
'M',
'1'));
109 writer.
setCodec(CV_FOURCC(
'P',
'I',
'M',
'1'));
114 bool recording =
false;
117#if defined(VISP_HAVE_V4L2)
119#elif defined(VISP_HAVE_OPENCV) && \
120 (((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \
121 ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))
126 if (recording ==
false) {
140 std::cout <<
"The video was recorded in \"" << opt_videoname <<
"\"" << std::endl;
141#ifdef VISP_HAVE_DISPLAY
146 std::cout <<
"Catch an exception: " <<
e << std::endl;
155#if !defined(VISP_HAVE_DISPLAY)
156 std::cout <<
"Install a 3rdparty to enable display feature (X11, GDI...) and rebuild ViSP to use this tutorial." << std::endl;
158#if !(defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_OPENCV) && \
159 (((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \
160 ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))))
161 std::cout <<
"Install V4l2 or OpenCV 3rdparty and rebuild ViSP to use this tutorial." << std::endl;
static const vpColor green
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)
Definition of the vpImage class member functions.
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.