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") {
40 std::cout <<
"\nUsage: " << argv[0] <<
" [--device <device number>] [--name <video name>] [--help]\n" 46 std::cout <<
"Use device: " << opt_device << std::endl;
47 std::cout <<
"Record video in: " << opt_videoname << std::endl;
53 #if defined(VISP_HAVE_V4L2) 55 std::ostringstream device;
56 device <<
"/dev/video" << opt_device;
61 #elif defined(VISP_HAVE_OPENCV) 62 cv::VideoCapture g(opt_device);
64 std::cout <<
"Failed to open the camera" << std::endl;
74 #if defined(VISP_HAVE_X11) 76 #elif defined(VISP_HAVE_GDI) 78 #elif defined(VISP_HAVE_OPENCV) 80 #elif defined(VISP_HAVE_GTK) 83 d.
init(I, 0, 0,
"Camera view");
86 #if VISP_HAVE_OPENCV_VERSION >= 0x030000 87 writer.
setCodec(cv::VideoWriter::fourcc(
'P',
'I',
'M',
'1'));
88 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100 89 writer.
setCodec(CV_FOURCC(
'P',
'I',
'M',
'1'));
93 bool recording =
false;
96 #if defined(VISP_HAVE_V4L2) 98 #elif defined(VISP_HAVE_OPENCV) 103 if (recording ==
false) {
116 std::cout <<
"The video was recorded in \"" << opt_videoname <<
"\"" << std::endl;
118 std::cout <<
"Catch an exception: " << e << std::endl;
123 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...
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)
void setFileName(const char *filename)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
unsigned int getHeight() const
void setCodec(const int fourcc_codec)
unsigned int getWidth() const