2 #include <visp3/core/vpImage.h> 3 #include <visp3/gui/vpDisplayX.h> 4 #include <visp3/gui/vpDisplayOpenCV.h> 5 #include <visp3/sensor/vpV4l2Grabber.h> 6 #include <visp3/io/vpImageStorageWorker.h> 16 int main(
int argc,
const char *argv[])
18 #if defined(VISP_HAVE_V4L2) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 21 unsigned int opt_scale = 1;
23 std::string opt_seqname;
24 int opt_record_mode = 0;
26 for (
int i = 0; i < argc; i++) {
27 if (std::string(argv[i]) ==
"--camera_device")
28 opt_device = std::atoi(argv[i + 1]);
29 else if (std::string(argv[i]) ==
"--scale")
30 opt_scale = (
unsigned int)atoi(argv[i + 1]);
31 else if (std::string(argv[i]) ==
"--seqname")
32 opt_seqname = std::string(argv[i + 1]);
33 else if (std::string(argv[i]) ==
"--record")
34 opt_record_mode = std::atoi(argv[i + 1]);
35 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
36 std::cout <<
"\nUsage: " << argv[0]
37 <<
" [--camera_device <camera device (default: 0)>] [--scale <subsampling factor (default: 1)>]" 38 " [--seqname <sequence name (default: empty>] [--record <0: continuous | 1: single shot (default: 0)>]" 40 <<
"\nExample to visualize images:\n" 41 <<
" " << argv[0] <<
"\n" 42 <<
"\nExample to visualize images from a second camera:\n" 43 <<
" " << argv[0] <<
" --camera_device 1\n" 44 <<
"\nExamples to record a sequence:\n" 45 <<
" " << argv[0] <<
" --seqname I%04d.png \n" 46 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 0\n" 47 <<
"\nExamples to record single shot images:\n" 48 <<
" " << argv[0] <<
" --seqname I%04d.png --record 1\n" 49 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 1\n" 55 std::cout <<
"Use device : " << opt_device << std::endl;
56 std::cout <<
"Recording : " << (opt_seqname.empty() ?
"disabled" :
"enabled") << std::endl;
58 std::string text_record_mode = std::string(
"Record mode: ") + (opt_record_mode ? std::string(
"single") :
std::string(
"continuous"));
60 if (! opt_seqname.empty()) {
61 std::cout << text_record_mode << std::endl;
62 std::cout <<
"Record name: " << opt_seqname << std::endl;
72 std::ostringstream device;
73 device <<
"/dev/video" << opt_device;
78 std::cout <<
"Image size : " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
82 #elif defined(VISP_HAVE_OPENCV) 85 std::cout <<
"No image viewer is available..." << std::endl;
105 quit = image_queue.record(I);
107 std::stringstream ss;
112 image_queue.cancel();
113 image_storage_thread.join();
115 std::cout <<
"Catch an exception: " << e << std::endl;
120 #ifndef VISP_HAVE_V4L2 121 std::cout <<
"Install Video 4 Linux 2 (v4l2), configure and build ViSP again to use this example" << std::endl;
123 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11) 124 std::cout <<
"This turorial should be built with c++11 support" << std::endl;
void acquire(vpImage< unsigned char > &I)
void open(vpImage< unsigned char > &I)
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 void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
unsigned int getHeight() const
unsigned int getWidth() const