2 #include <visp3/core/vpConfig.h>
3 #include <visp3/core/vpImage.h>
4 #include <visp3/gui/vpDisplayOpenCV.h>
5 #include <visp3/gui/vpDisplayX.h>
6 #include <visp3/io/vpImageStorageWorker.h>
7 #include <visp3/sensor/vpV4l2Grabber.h>
11 void usage(
const char *argv[],
int error)
13 std::cout <<
"SYNOPSIS" << std::endl
14 <<
" " << argv[0] <<
" [--device <index>]"
15 <<
" [--scale <subsampling factor>]"
16 <<
" [--seqname <sequence name>]"
17 <<
" [--record <mode>]"
19 <<
" [--help] [-h]" << std::endl
21 std::cout <<
"DESCRIPTION" << std::endl
22 <<
" --device <index> " << std::endl
23 <<
" Camera device index. Set 0 to dial with the first camera," << std::endl
24 <<
" and 1 to dial with the second camera attached to the computer." << std::endl
25 <<
" Default: 0 to consider /dev/video0 device." << std::endl
27 <<
" --scale <subsampling factor>" << std::endl
28 <<
" Subsampling factor applied to the images captured by the device." << std::endl
29 <<
" Default: 1" << std::endl
31 <<
" --seqname <sequence name>" << std::endl
32 <<
" Name of the sequence of image to create (ie: /tmp/image%04d.jpg)." << std::endl
33 <<
" Default: empty." << std::endl
35 <<
" --record <mode>" << std::endl
36 <<
" Allowed values for mode are:" << std::endl
37 <<
" 0: record all the captures images (continuous mode)," << std::endl
38 <<
" 1: record only images selected by a user click (single shot mode)." << std::endl
39 <<
" Default mode: 0" << std::endl
41 <<
" --no-display" << std::endl
42 <<
" Disable displaying captured images." << std::endl
43 <<
" When used and sequence name specified, record mode is internally set to 1 (continuous mode)."
46 <<
" --help, -h" << std::endl
47 <<
" Print this helper message." << std::endl
49 std::cout <<
"USAGE" << std::endl
50 <<
" Example to visualize images:" << std::endl
51 <<
" " << argv[0] << std::endl
53 <<
" Example to visualize images from a second camera:" << std::endl
54 <<
" " << argv[0] <<
" --device 1" << std::endl
56 <<
" Examples to record a sequence:" << std::endl
57 <<
" " << argv[0] <<
" --seqname I%04d.png" << std::endl
58 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 0" << std::endl
60 <<
" Examples to record single shot images:\n"
61 <<
" " << argv[0] <<
" --seqname I%04d.png --record 1\n"
62 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 1" << std::endl
66 std::cout <<
"Error" << std::endl
68 <<
"Unsupported parameter " << argv[error] << std::endl;
78 int main(
int argc,
const char *argv[])
80 #if defined(VISP_HAVE_V4L2) && defined(VISP_HAVE_THREADS)
81 #ifdef ENABLE_VISP_NAMESPACE
86 unsigned int opt_scale = 1;
88 std::string opt_seqname;
89 int opt_record_mode = 0;
90 bool opt_display =
true;
92 for (
int i = 1; i < argc; i++) {
93 if (std::string(argv[i]) ==
"--device") {
94 opt_device = std::atoi(argv[i + 1]);
97 else if (std::string(argv[i]) ==
"--scale") {
98 opt_scale = (
unsigned int)atoi(argv[i + 1]);
101 else if (std::string(argv[i]) ==
"--seqname") {
102 opt_seqname = std::string(argv[i + 1]);
105 else if (std::string(argv[i]) ==
"--record") {
106 opt_record_mode = std::atoi(argv[i + 1]);
109 else if (std::string(argv[i]) ==
"--no-display") {
112 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
122 if ((!opt_display) && (!opt_seqname.empty())) {
125 std::cout <<
"Use device : " << opt_device << std::endl;
126 std::cout <<
"Recording : " << (opt_seqname.empty() ?
"disabled" :
"enabled") << std::endl;
127 std::cout <<
"Display : " << (opt_display ?
"enabled" :
"disabled") << std::endl;
129 std::string text_record_mode =
130 std::string(
"Record mode: ") + (opt_record_mode ? std::string(
"single") : std::string(
"continuous"));
132 if (!opt_seqname.empty()) {
133 std::cout << text_record_mode << std::endl;
134 std::cout <<
"Record name: " << opt_seqname << std::endl;
144 std::ostringstream device;
145 device <<
"/dev/video" << opt_device;
150 std::cout <<
"Image size : " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
154 #if !(defined(VISP_HAVE_X11) || defined(VISP_HAVE_OPENCV))
155 std::cout <<
"No image viewer is available..." << std::endl;
161 d =
new vpDisplayX(I);
162 #elif defined(HAVE_OPENCV_HIGHGUI)
168 vpImageQueue<vpRGBa> image_queue(opt_seqname, opt_record_mode);
172 vpImageQueue<unsigned char> image_queue(opt_seqname, opt_record_mode);
184 quit = image_queue.record(I);
186 std::stringstream ss;
191 image_queue.cancel();
192 image_storage_thread.join();
199 std::cout <<
"Catch an exception: " << e << std::endl;
204 #ifndef VISP_HAVE_V4L2
205 std::cout <<
"Install Video 4 Linux 2 (v4l2), configure and build ViSP again to use this example" << std::endl;
207 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
208 std::cout <<
"This tutorial should be built with c++11 support" << std::endl;
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Class that defines generic functionalities for display.
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.
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)
VISP_EXPORT double measureTimeMs()