2 #include <visp/vpDisplayGDI.h>
3 #include <visp/vpDisplayGTK.h>
4 #include <visp/vpDisplayOpenCV.h>
5 #include <visp/vpDisplayX.h>
6 #include <visp/vpTime.h>
7 #include <visp/vpVideoWriter.h>
8 #include <visp/vpV4l2Grabber.h>
16 int main(
int argc,
const char *argv[])
18 #if ((defined(VISP_HAVE_V4L2) || (VISP_HAVE_OPENCV_VERSION >= 0x020100)) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK)))
19 std::string opt_videoname =
"video-recorded.mpg";
22 for (
int i=0; i<argc; i++) {
23 if (std::string(argv[i]) ==
"--device")
24 opt_device = atoi(argv[i+1]);
25 else if (std::string(argv[i]) ==
"--name")
26 opt_videoname = std::string(argv[i+1]);
27 else if (std::string(argv[i]) ==
"--help") {
28 std::cout <<
"\nUsage: " << argv[0] <<
" [--device <device number>] [--name <video name>] [--help]\n" << std::endl;
33 std::cout <<
"Use device: " << opt_device << std::endl;
34 std::cout <<
"Record video in: " << opt_videoname << std::endl;
40 #if defined(VISP_HAVE_V4L2)
42 std::ostringstream device;
43 device <<
"/dev/video" << opt_device;
47 #elif defined(VISP_HAVE_OPENCV)
48 cv::VideoCapture g(opt_device);
50 std::cout <<
"Failed to open the camera" << std::endl;
60 #if defined(VISP_HAVE_X11)
62 #elif defined(VISP_HAVE_GDI)
64 #elif defined(VISP_HAVE_OPENCV)
66 #elif defined(VISP_HAVE_GTK)
69 d.
init(I, 0, 0,
"Camera view");
72 #ifdef VISP_HAVE_FFMPEG
76 # if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,51,110) // libavcodec 54.51.100
77 writer.
setCodec(CODEC_ID_MPEG2VIDEO);
79 writer.
setCodec(AV_CODEC_ID_MPEG2VIDEO);
81 #elif VISP_HAVE_OPENCV_VERSION >= 0x030000
82 writer.
setCodec( cv::VideoWriter::fourcc(
'P',
'I',
'M',
'1') );
83 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
84 writer.
setCodec( CV_FOURCC(
'P',
'I',
'M',
'1') );
88 bool recording =
false;
91 #if defined(VISP_HAVE_V4L2)
93 #elif defined(VISP_HAVE_OPENCV)
98 if (recording ==
false) {
112 std::cout <<
"The video was recorded in \"" << opt_videoname <<
"\"" << std::endl;
115 std::cout <<
"Catch an exception: " << e << std::endl;
120 std::cout <<
"Install OpenCV and rebuild ViSP to use this example." << std::endl;
void acquire(vpImage< unsigned char > &I)
void open(vpImage< unsigned char > &I)
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void setBitRate(const unsigned int bitrate)
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)
Define the X11 console to display images.
void setDevice(const std::string &devname)
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
void setCodec(const AVCodecID codec_id)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
Class that enables to write easily a video file or a sequence of images.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void saveFrame(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
Class for the Video4Linux2 video device.
unsigned int getHeight() const
virtual bool getClick(bool blocking=true)=0