4 #include <visp3/core/vpConfig.h>
6 #include <visp3/core/vpCameraParameters.h>
7 #include <visp3/core/vpImageConvert.h>
8 #include <visp3/core/vpImageTools.h>
9 #include <visp3/core/vpPixelMeterConversion.h>
10 #include <visp3/core/vpColorDepthConversion.h>
11 #include <visp3/gui/vpDisplayX.h>
12 #include <visp3/io/vpVideoReader.h>
13 #include <visp3/sensor/vpRealSense2.h>
15 int main(
int argc,
const char *argv[])
17 #if defined(VISP_HAVE_X11)
18 #ifdef ENABLE_VISP_NAMESPACE
22 std::string opt_hsv_filename =
"calib/hsv-thresholds.yml";
23 std::string opt_video_filename;
24 bool show_helper =
false;
26 for (
int i = 1; i < argc; i++) {
27 if ((std::string(argv[i]) ==
"--hsv-thresholds") && ((i+1) < argc)) {
28 opt_hsv_filename = std::string(argv[++i]);
30 else if (std::string(argv[i]) ==
"--video") {
32 opt_video_filename = std::string(argv[++i]);
36 std::cout <<
"ERROR \nMissing input video name after parameter " << std::string(argv[i]) << std::endl;
39 else if (show_helper || std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
40 std::cout <<
"\nSYNOPSIS " << std::endl
42 <<
" [--video <input video>]"
43 <<
" [--hsv-thresholds <filename.yml>]"
46 std::cout <<
"\nOPTIONS " << std::endl
47 <<
" --video <input video>" << std::endl
48 <<
" Name of the input video filename." << std::endl
49 <<
" When this option is not set, we use librealsense to stream images from a Realsense camera. " << std::endl
50 <<
" Example: --video image-%04d.jpg" << std::endl
52 <<
" --hsv-thresholds <filename.yaml>" << std::endl
53 <<
" Path to a yaml filename that contains H <min,max>, S <min,max>, V <min,max> threshold values." << std::endl
54 <<
" An Example of such a file could be:" << std::endl
55 <<
" rows: 6" << std::endl
56 <<
" cols: 1" << std::endl
57 <<
" data:" << std::endl
58 <<
" - [0]" << std::endl
59 <<
" - [42]" << std::endl
60 <<
" - [177]" << std::endl
61 <<
" - [237]" << std::endl
62 <<
" - [148]" << std::endl
63 <<
" - [208]" << std::endl
65 <<
" --help, -h" << std::endl
66 <<
" Display this helper message." << std::endl
72 bool use_realsense =
false;
73 #if defined(VISP_HAVE_REALSENSE2)
77 if (!opt_video_filename.empty()) {
78 use_realsense =
false;
81 else if (opt_video_filename.empty()) {
82 std::cout <<
"Error: you should use --image <input image> option to specify an input image..." << std::endl;
88 std::cout <<
"Load HSV threshold values from " << opt_hsv_filename << std::endl;
89 std::cout <<
"HSV low/high values: " << hsv_values.
t() << std::endl;
92 std::cout <<
"Warning: unable to load HSV thresholds values from " << opt_hsv_filename << std::endl;
101 #if defined(VISP_HAVE_REALSENSE2)
106 #if defined(VISP_HAVE_REALSENSE2)
109 config.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, fps);
110 config.disable_stream(RS2_STREAM_DEPTH);
111 config.disable_stream(RS2_STREAM_INFRARED, 1);
112 config.disable_stream(RS2_STREAM_INFRARED, 2);
136 vpDisplayX d_I(I, 0, 0,
"Current frame");
137 vpDisplayX d_I_segmented(I_segmented, I.
getWidth()+75, 0,
"HSV segmented frame");
140 double loop_time = 0., total_loop_time = 0.;
146 #if defined(VISP_HAVE_REALSENSE2)
156 reinterpret_cast<unsigned char *
>(H.bitmap),
157 reinterpret_cast<unsigned char *
>(S.bitmap),
158 reinterpret_cast<unsigned char *
>(V.bitmap), I.
getSize());
161 reinterpret_cast<unsigned char *
>(S.bitmap),
162 reinterpret_cast<unsigned char *
>(V.bitmap),
164 reinterpret_cast<unsigned char *
>(mask.bitmap),
181 total_loop_time += loop_time;
184 std::cout <<
"Mean loop time: " << total_loop_time / nb_iter << std::endl;
188 std::cout <<
"This tutorial needs X11 3rdparty that is not enabled" << std::endl;
static bool loadYAML(const std::string &filename, vpArray2D< double > &A, char *header=nullptr)
Implementation of column vector and the associated operations.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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.
const std::string & getStringMessage() const
static void RGBaToHSV(const unsigned char *rgba, double *hue, double *saturation, double *value, unsigned int size)
unsigned int getWidth() const
unsigned int getSize() const
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
void acquire(vpImage< unsigned char > &grey, double *ts=nullptr)
bool open(const rs2::config &cfg=rs2::config())
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void acquire(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
VISP_EXPORT double measureTimeMs()