3 #include <visp3/core/vpConfig.h>
4 #include <visp3/core/vpImageConvert.h>
5 #include <visp3/gui/vpDisplayOpenCV.h>
6 #include <visp3/io/vpImageStorageWorker.h>
8 #if defined(HAVE_OPENCV_VIDEOIO)
9 #include <opencv2/videoio.hpp>
14 void usage(
const char *argv[],
int error)
16 std::cout <<
"SYNOPSIS" << std::endl
17 <<
" " << argv[0] <<
" [--device <index>]"
18 <<
" [--seqname <sequence name>]"
19 <<
" [--record <mode>]"
21 <<
" [--help] [-h]" << std::endl
23 std::cout <<
"DESCRIPTION" << std::endl
24 <<
" --device <index> " << std::endl
25 <<
" Camera device index. Set 0 to dial with the first camera," << std::endl
26 <<
" and 1 to dial with the second camera attached to the computer." << std::endl
27 <<
" Default: 0 to consider /dev/video0 device." << std::endl
29 <<
" --seqname <sequence name>" << std::endl
30 <<
" Name of the sequence of image to create (ie: /tmp/image%04d.jpg)." << std::endl
31 <<
" Default: empty." << std::endl
33 <<
" --record <mode>" << std::endl
34 <<
" Allowed values for mode are:" << std::endl
35 <<
" 0: record all the captures images (continuous mode)," << std::endl
36 <<
" 1: record only images selected by a user click (single shot mode)." << std::endl
37 <<
" Default mode: 0" << std::endl
39 <<
" --no-display" << std::endl
40 <<
" Disable displaying captured images." << std::endl
41 <<
" When used and sequence name specified, record mode is internally set to 1 (continuous mode)."
44 <<
" --help, -h" << std::endl
45 <<
" Print this helper message." << std::endl
47 std::cout <<
"USAGE" << std::endl
48 <<
" Example to visualize images:" << std::endl
49 <<
" " << argv[0] << std::endl
51 <<
" Example to visualize images from a second camera:" << std::endl
52 <<
" " << argv[0] <<
" --device 1" << std::endl
54 <<
" Examples to record a sequence:" << std::endl
55 <<
" " << argv[0] <<
" --seqname I%04d.png" << std::endl
56 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 0" << std::endl
58 <<
" Examples to record single shot images:\n"
59 <<
" " << argv[0] <<
" --seqname I%04d.png --record 1\n"
60 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 1" << std::endl
64 std::cout <<
"Error" << std::endl
66 <<
"Unsupported parameter " << argv[error] << std::endl;
73 int main(
int argc,
const char *argv[])
75 #ifdef ENABLE_VISP_NAMESPACE
79 std::string opt_seqname;
80 int opt_record_mode = 0;
81 bool opt_display =
true;
83 for (
int i = 1; i < argc; i++) {
84 if (std::string(argv[i]) ==
"--device") {
85 opt_device = std::atoi(argv[i + 1]);
88 else if (std::string(argv[i]) ==
"--seqname") {
89 opt_seqname = std::string(argv[i + 1]);
92 else if (std::string(argv[i]) ==
"--record") {
93 opt_record_mode = std::atoi(argv[i + 1]);
96 else if (std::string(argv[i]) ==
"--no-display") {
99 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
109 if ((!opt_display) && (!opt_seqname.empty())) {
113 std::cout <<
"Use device : " << opt_device << std::endl;
114 std::cout <<
"Recording : " << (opt_seqname.empty() ?
"disabled" :
"enabled") << std::endl;
115 std::cout <<
"Display : " << (opt_display ?
"enabled" :
"disabled") << std::endl;
117 std::string text_record_mode =
118 std::string(
"Record mode: ") + (opt_record_mode ? std::string(
"single") : std::string(
"continuous"));
120 if (!opt_seqname.empty()) {
121 std::cout << text_record_mode << std::endl;
122 std::cout <<
"Record name: " << opt_seqname << std::endl;
125 #if defined(HAVE_OPENCV_VIDEOIO) && defined(HAVE_OPENCV_HIGHGUI) && defined(VISP_HAVE_THREADS)
127 cv::VideoCapture cap(opt_device);
128 if (!cap.isOpened()) {
129 std::cout <<
"Failed to open the camera" << std::endl;
134 while ((i++ < 20) && !cap.read(frame)) {
137 std::cout <<
"Image size : " << frame.rows <<
" " << frame.cols << std::endl;
152 vpImageQueue<vpRGBa> image_queue(opt_seqname, opt_record_mode);
156 vpImageQueue<unsigned char> image_queue(opt_seqname, opt_record_mode);
170 quit = image_queue.record(I);
172 std::stringstream ss;
177 image_queue.cancel();
178 image_storage_thread.join();
185 std::cout <<
"Catch an exception: " << e << std::endl;
190 #if !defined(HAVE_OPENCV_VIDEOIO)
191 std::cout <<
"Install OpenCV videoio module, configure and build ViSP again to use this example" << std::endl;
193 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
194 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()