4#include <visp3/core/vpConfig.h>
6#include <visp3/core/vpCameraParameters.h>
7#include <visp3/core/vpHSV.h>
8#include <visp3/core/vpImageConvert.h>
9#include <visp3/core/vpImageTools.h>
10#include <visp3/core/vpPixelMeterConversion.h>
11#include <visp3/core/vpColorDepthConversion.h>
12#include <visp3/gui/vpDisplayFactory.h>
13#include <visp3/io/vpVideoReader.h>
14#include <visp3/sensor/vpRealSense2.h>
16int main(
int argc,
const char *argv[])
18#if defined(VISP_HAVE_DISPLAY)
19#ifdef ENABLE_VISP_NAMESPACE
23 std::string opt_hsv_filename =
"calib/hsv-thresholds.yml";
24 std::string opt_video_filename;
25 bool show_helper =
false;
27 for (
int i = 1;
i < argc;
i++) {
28 if ((std::string(argv[i]) ==
"--hsv-thresholds") && ((i+1) < argc)) {
29 opt_hsv_filename = std::string(argv[++i]);
31 else if (std::string(argv[i]) ==
"--video") {
33 opt_video_filename = std::string(argv[++i]);
37 std::cout <<
"ERROR \nMissing input video name after parameter " << std::string(argv[i]) << std::endl;
40 else if (show_helper || std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
41 std::cout <<
"\nSYNOPSIS " << std::endl
43 <<
" [--video <input video>]"
44 <<
" [--hsv-thresholds <filename.yml>]"
47 std::cout <<
"\nOPTIONS " << std::endl
48 <<
" --video <input video>" << std::endl
49 <<
" Name of the input video filename." << std::endl
50 <<
" When this option is not set, we use librealsense to stream images from a Realsense camera. " << std::endl
51 <<
" Example: --video image-%04d.jpg" << std::endl
53 <<
" --hsv-thresholds <filename.yaml>" << std::endl
54 <<
" Path to a yaml filename that contains H <min,max>, S <min,max>, V <min,max> threshold values." << std::endl
55 <<
" An Example of such a file could be:" << std::endl
56 <<
" rows: 6" << std::endl
57 <<
" cols: 1" << std::endl
58 <<
" data:" << std::endl
59 <<
" - [0]" << std::endl
60 <<
" - [42]" << std::endl
61 <<
" - [177]" << std::endl
62 <<
" - [237]" << std::endl
63 <<
" - [148]" << std::endl
64 <<
" - [208]" << std::endl
66 <<
" --help, -h" << std::endl
67 <<
" Display this helper message." << std::endl
73 bool use_realsense =
false;
74#if defined(VISP_HAVE_REALSENSE2)
78 if (!opt_video_filename.empty()) {
79 use_realsense =
false;
82 else if (opt_video_filename.empty()) {
83 std::cout <<
"Error: you should use --image <input image> option to specify an input image..." << std::endl;
89 std::cout <<
"Load HSV threshold values from " << opt_hsv_filename << std::endl;
90 std::cout <<
"HSV low/high values: " << hsv_values.
t() << std::endl;
93 std::cout <<
"Warning: unable to load HSV thresholds values from " << opt_hsv_filename << std::endl;
102#if defined(VISP_HAVE_REALSENSE2)
107#if defined(VISP_HAVE_REALSENSE2)
110 config.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, fps);
111 config.disable_stream(RS2_STREAM_DEPTH);
112 config.disable_stream(RS2_STREAM_INFRARED, 1);
113 config.disable_stream(RS2_STREAM_INFRARED, 2);
124 std::cout <<
e.getStringMessage() << std::endl;
127 width = I.getWidth();
134#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
148 double loop_time = 0., total_loop_time = 0.;
154#if defined(VISP_HAVE_REALSENSE2)
163#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
168 reinterpret_cast<unsigned char *
>(H.bitmap),
169 reinterpret_cast<unsigned char *
>(S.bitmap),
170 reinterpret_cast<unsigned char *
>(V.bitmap), I.getSize());
173 reinterpret_cast<unsigned char *
>(S.bitmap),
174 reinterpret_cast<unsigned char *
>(V.bitmap),
176 reinterpret_cast<unsigned char *
>(mask.bitmap),
194 total_loop_time += loop_time;
197 std::cout <<
"Mean loop time: " << total_loop_time / nb_iter << std::endl;
199#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
200 if (d_I !=
nullptr) {
204 if (d_I_segmented !=
nullptr) {
205 delete d_I_segmented;
211 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.
Class that defines generic functionalities for display.
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.
static void RGBaToHSV(const unsigned char *rgba, double *hue, double *saturation, double *value, unsigned int size)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Definition of the vpImage class member functions.
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 open(vpImage< vpRGBa > &I) VP_OVERRIDE
void setFileName(const std::string &filename)
void acquire(vpImage< vpRGBa > &I) VP_OVERRIDE
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()