3 #include <visp3/core/vpImageConvert.h>
4 #include <visp3/gui/vpDisplayOpenCV.h>
5 #include <visp3/io/vpImageStorageWorker.h>
7 #if defined(HAVE_OPENCV_VIDEOIO)
8 #include <opencv2/videoio.hpp>
13 void usage(
const char *argv[],
int error)
15 std::cout <<
"SYNOPSIS" << std::endl
16 <<
" " << argv[0] <<
" [--device <index>]"
17 <<
" [--seqname <sequence name>]"
18 <<
" [--record <mode>]"
20 <<
" [--help] [-h]" << std::endl
22 std::cout <<
"DESCRIPTION" << std::endl
23 <<
" --device <index> " << std::endl
24 <<
" Camera device index. Set 0 to dial with the first camera," << std::endl
25 <<
" and 1 to dial with the second camera attached to the computer." << std::endl
26 <<
" Default: 0 to consider /dev/video0 device." << std::endl
28 <<
" --seqname <sequence name>" << std::endl
29 <<
" Name of the sequence of image to create (ie: /tmp/image%04d.jpg)." << std::endl
30 <<
" Default: empty." << std::endl
32 <<
" --record <mode>" << std::endl
33 <<
" Allowed values for mode are:" << std::endl
34 <<
" 0: record all the captures images (continuous mode)," << std::endl
35 <<
" 1: record only images selected by a user click (single shot mode)." << std::endl
36 <<
" Default mode: 0" << std::endl
38 <<
" --no-display" << std::endl
39 <<
" Disable displaying captured images." << std::endl
40 <<
" When used and sequence name specified, record mode is internally set to 1 (continuous mode)."
43 <<
" --help, -h" << std::endl
44 <<
" Print this helper message." << std::endl
46 std::cout <<
"USAGE" << std::endl
47 <<
" Example to visualize images:" << std::endl
48 <<
" " << argv[0] << std::endl
50 <<
" Example to visualize images from a second camera:" << std::endl
51 <<
" " << argv[0] <<
" --device 1" << std::endl
53 <<
" Examples to record a sequence:" << std::endl
54 <<
" " << argv[0] <<
" --seqname I%04d.png" << std::endl
55 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 0" << std::endl
57 <<
" Examples to record single shot images:\n"
58 <<
" " << argv[0] <<
" --seqname I%04d.png --record 1\n"
59 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 1" << std::endl
63 std::cout <<
"Error" << std::endl
65 <<
"Unsupported parameter " << argv[error] << std::endl;
72 int main(
int argc,
const char *argv[])
75 std::string opt_seqname;
76 int opt_record_mode = 0;
77 bool opt_display =
true;
79 for (
int i = 1; i < argc; i++) {
80 if (std::string(argv[i]) ==
"--device") {
81 opt_device = std::atoi(argv[i + 1]);
84 else if (std::string(argv[i]) ==
"--seqname") {
85 opt_seqname = std::string(argv[i + 1]);
88 else if (std::string(argv[i]) ==
"--record") {
89 opt_record_mode = std::atoi(argv[i + 1]);
92 else if (std::string(argv[i]) ==
"--no-display") {
95 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
105 if ((!opt_display) && (!opt_seqname.empty())) {
109 std::cout <<
"Use device : " << opt_device << std::endl;
110 std::cout <<
"Recording : " << (opt_seqname.empty() ?
"disabled" :
"enabled") << std::endl;
111 std::cout <<
"Display : " << (opt_display ?
"enabled" :
"disabled") << std::endl;
113 std::string text_record_mode =
114 std::string(
"Record mode: ") + (opt_record_mode ? std::string(
"single") : std::string(
"continuous"));
116 if (!opt_seqname.empty()) {
117 std::cout << text_record_mode << std::endl;
118 std::cout <<
"Record name: " << opt_seqname << std::endl;
121 #if defined(HAVE_OPENCV_VIDEOIO) && defined(HAVE_OPENCV_HIGHGUI) && defined(VISP_HAVE_THREADS)
123 cv::VideoCapture cap(opt_device);
124 if (!cap.isOpened()) {
125 std::cout <<
"Failed to open the camera" << std::endl;
130 while ((i++ < 20) && !cap.read(frame)) {
133 std::cout <<
"Image size : " << frame.rows <<
" " << frame.cols << std::endl;
166 quit = image_queue.record(I);
168 std::stringstream ss;
173 image_queue.cancel();
174 image_storage_thread.join();
181 std::cout <<
"Catch an exception: " << e << std::endl;
186 #if !defined(HAVE_OPENCV_VIDEOIO)
187 std::cout <<
"Install OpenCV videoio module, configure and build ViSP again to use this example" << std::endl;
189 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
190 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...
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)
unsigned int getHeight() const
VISP_EXPORT double measureTimeMs()