4#include <visp3/core/vpConfig.h>
6#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && \
7 ((VISP_HAVE_OPENCV_VERSION < 0x030000) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))
9#if defined(HAVE_OPENCV_VIDEOIO)
10#include <opencv2/videoio.hpp>
13#include <opencv2/highgui/highgui.hpp>
15#include <visp3/core/vpImageConvert.h>
16#include <visp3/gui/vpDisplayOpenCV.h>
17#include <visp3/io/vpImageStorageWorker.h>
21void usage(
const char *argv[],
int error)
23 std::cout <<
"SYNOPSIS" << std::endl
24 <<
" " << argv[0] <<
" [--device <index>]"
25 <<
" [--seqname <sequence name>]"
26 <<
" [--record <mode>]"
28 <<
" [--help] [-h]" << std::endl
30 std::cout <<
"DESCRIPTION" << std::endl
31 <<
" --device <index> " << std::endl
32 <<
" Camera device index. Set 0 to dial with the first camera," << std::endl
33 <<
" and 1 to dial with the second camera attached to the computer." << std::endl
34 <<
" Default: 0 to consider /dev/video0 device." << std::endl
36 <<
" --seqname <sequence name>" << std::endl
37 <<
" Name of the sequence of image to create (ie: /tmp/image%04d.jpg)." << std::endl
38 <<
" Default: empty." << std::endl
40 <<
" --record <mode>" << std::endl
41 <<
" Allowed values for mode are:" << std::endl
42 <<
" 0: record all the captures images (continuous mode)," << std::endl
43 <<
" 1: record only images selected by a user click (single shot mode)." << std::endl
44 <<
" Default mode: 0" << std::endl
46 <<
" --no-display" << std::endl
47 <<
" Disable displaying captured images." << std::endl
48 <<
" When used and sequence name specified, record mode is internally set to 1 (continuous mode)."
51 <<
" --help, -h" << std::endl
52 <<
" Print this helper message." << std::endl
54 std::cout <<
"USAGE" << std::endl
55 <<
" Example to visualize images:" << std::endl
56 <<
" " << argv[0] << std::endl
58 <<
" Example to visualize images from a second camera:" << std::endl
59 <<
" " << argv[0] <<
" --device 1" << std::endl
61 <<
" Examples to record a sequence:" << std::endl
62 <<
" " << argv[0] <<
" --seqname I%04d.png" << std::endl
63 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 0" << std::endl
65 <<
" Examples to record single shot images:\n"
66 <<
" " << argv[0] <<
" --seqname I%04d.png --record 1\n"
67 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 1" << std::endl
71 std::cout <<
"Error" << std::endl
73 <<
"Unsupported parameter " << argv[
error] << std::endl;
80int main(
int argc,
const char *argv[])
82#ifdef ENABLE_VISP_NAMESPACE
86 std::string opt_seqname;
87 int opt_record_mode = 0;
88 bool opt_display =
true;
90 for (
int i = 1;
i < argc;
i++) {
91 if (std::string(argv[i]) ==
"--device" && i + 1 < argc) {
92 opt_device = std::atoi(argv[++i]);
94 else if (std::string(argv[i]) ==
"--seqname" && i + 1 < argc) {
95 opt_seqname = std::string(argv[++i]);
97 else if (std::string(argv[i]) ==
"--record" && i + 1 < argc) {
98 opt_record_mode = std::atoi(argv[++i]);
100 else if (std::string(argv[i]) ==
"--no-display") {
103 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
113 if ((!opt_display) && (!opt_seqname.empty())) {
117 std::cout <<
"Use device : " << opt_device << std::endl;
118 std::cout <<
"Recording : " << (opt_seqname.empty() ?
"disabled" :
"enabled") << std::endl;
119 std::cout <<
"Display : " << (opt_display ?
"enabled" :
"disabled") << std::endl;
121 std::string text_record_mode =
122 std::string(
"Record mode: ") + (opt_record_mode ? std::string(
"single") : std::string(
"continuous"));
124 if (!opt_seqname.empty()) {
125 std::cout << text_record_mode << std::endl;
126 std::cout <<
"Record name: " << opt_seqname << std::endl;
130 cv::VideoCapture cap(opt_device);
131 if (!cap.isOpened()) {
132 std::cout <<
"Failed to open the camera" << std::endl;
137 while ((i++ < 20) && !cap.read(frame)) {
140 std::cout <<
"Image size : " << frame.rows <<
" " << frame.cols << std::endl;
155 vpImageQueue<vpRGBa> image_queue(opt_seqname, opt_record_mode);
159 vpImageQueue<unsigned char> image_queue(opt_seqname, opt_record_mode);
173 quit = image_queue.record(I);
175 std::stringstream ss;
180 image_queue.cancel();
181 image_storage_thread.join();
188 std::cout <<
"Catch an exception: " <<
e << std::endl;
194#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && !defined(HAVE_OPENCV_VIDEOIO)
195 std::cout <<
"Install OpenCV videoio module, configure and build ViSP again to use this tutorial." << std::endl;
197#if !defined(HAVE_OPENCV_HIGHGUI)
198 std::cout <<
"Install OpenCV highgui module, configure and build ViSP again to use this tutorial." << 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)
Definition of the vpImage class member functions.
VISP_EXPORT double measureTimeMs()