2#include <visp3/core/vpConfig.h>
3#include <visp3/core/vpImage.h>
4#include <visp3/gui/vpDisplayFactory.h>
5#include <visp3/io/vpImageStorageWorker.h>
6#include <visp3/sensor/vpUeyeGrabber.h>
10void usage(
const char *argv[],
int error)
12 std::cout <<
"SYNOPSIS" << std::endl
13 <<
" " << argv[0] <<
" [--device <index>]"
14 <<
" [--config-file <filename.ini>]"
15 <<
" [--fps <auto|fps value like 6|15|30|60>]"
16 <<
" [--gain <auto|value in 0 - 100>]"
17 <<
" [--shutter <auto|exposure value in ms>]"
18 <<
" [--subsample <factor>]"
19 <<
" [--white-balance <value>]"
20 <<
" [--color-mode <mode>]"
21 <<
" [--seqname <sequence name>]"
22 <<
" [--record <mode>]"
24 <<
" [--verbose] [-v]"
25 <<
" [--help] [-h]" << std::endl
27 std::cout <<
"DESCRIPTION" << std::endl
28 <<
" --device <index>" << std::endl
29 <<
" Camera device index. Set 0 to dial with the first camera," << std::endl
30 <<
" and 1 to dial with the second camera attached to the computer." << std::endl
31 <<
" Default: 0" << std::endl
33 <<
" --config-file <filename.ini>" << std::endl
34 <<
" Camera config file." << std::endl
35 <<
" Default: empty." << std::endl
37 <<
" --fps <auto|fps value like 6|15|30|60>" << std::endl
38 <<
" \"Auto\" or a frames per second value." << std::endl
39 <<
" Default: current setting." << std::endl
41 <<
" --gain <auto|value in 0 - 100>" << std::endl
42 <<
" \"Auto\" or manual gain with a value in 0 - 100." << std::endl
43 <<
" Default: current setting." << std::endl
45 <<
" --shutter <auto|manu>" << std::endl
46 <<
" \"Auto\" or manual shutter." << std::endl
47 <<
" Default: current setting." << std::endl
49 <<
" --subsample <factor>" << std::endl
50 <<
" Subsample factor to reduce image size alog rows and columns." << std::endl
51 <<
" Default: 1." << std::endl
53 <<
" --white-balance <value>" << std::endl
54 <<
" Possible values are 0 (disabled) or 1 (enabled)." << std::endl
55 <<
" Default: current setting." << std::endl
57 <<
" --color-mode <mode>" << std::endl
58 <<
" Possible modes are: mono8, rgb24, rgb32, bayer8." << std::endl
59 <<
" Default: current setting." << std::endl
61 <<
" --seqname <sequence name>" << std::endl
62 <<
" Name of the sequence of image to create (ie: /tmp/image%04d.jpg)." << std::endl
63 <<
" Default: empty." << std::endl
65 <<
" --record <mode>" << std::endl
66 <<
" Allowed values for mode are:" << std::endl
67 <<
" 0: record all the captures images (continuous mode)," << std::endl
68 <<
" 1: record only images selected by a user click (single shot mode)." << std::endl
69 <<
" Default mode: 0" << std::endl
71 <<
" --no-display" << std::endl
72 <<
" Disable displaying captured images." << std::endl
73 <<
" When used and sequence name specified, record mode is internally set to 1 (continuous mode)."
76 <<
" --verbose, -v" << std::endl
77 <<
" Enable extra printings." << std::endl
79 <<
" --help, -h" << std::endl
80 <<
" Print this helper message." << std::endl
82 std::cout <<
"USAGE" << std::endl
83 <<
" Example to visualize images:" << std::endl
84 <<
" " << argv[0] << std::endl
86 <<
" Examples to record a sequence of images:" << std::endl
87 <<
" " << argv[0] <<
" --seqname I%04d.png" << std::endl
88 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 0" << std::endl
90 <<
" Examples to record single shot images:\n"
91 <<
" " << argv[0] <<
" --seqname I%04d.png --record 1\n"
92 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 1" << std::endl
96 std::cout <<
"Error" << std::endl
98 <<
"Unsupported parameter " << argv[
error] << std::endl;
107int main(
int argc,
const char *argv[])
109#if defined(VISP_HAVE_UEYE) && defined(VISP_HAVE_THREADS)
110#ifdef ENABLE_VISP_NAMESPACE
113#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
114 std::shared_ptr<vpDisplay> display;
119 unsigned int opt_device = 0;
120 std::string opt_seqname;
121 int opt_record_mode = 0;
122 std::string opt_config_file =
"";
123 std::string opt_fps =
"";
124 std::string opt_gain =
"";
125 std::string opt_shutter =
"";
126 std::string opt_color_mode =
"";
127 int opt_white_balance = -1;
128 int opt_subsample = 1;
129 bool opt_verbose =
false;
130 bool opt_display =
true;
132 for (
int i = 1;
i < argc;
i++) {
133 if (std::string(argv[i]) ==
"--device" && i + 1 < argc) {
134 opt_device =
static_cast<unsigned int>(std::atoi(argv[++i]));
137 else if (std::string(argv[i]) ==
"--config-file" && i + 1 < argc) {
138 opt_config_file = std::string(argv[++i]);
141 else if (std::string(argv[i]) ==
"--fps" && i + 1 < argc) {
142 opt_fps = std::string(argv[++i]);
145 else if (std::string(argv[i]) ==
"--gain" && i + 1 < argc) {
146 opt_gain = std::string(argv[++i]);
149 else if (std::string(argv[i]) ==
"--shutter" && i + 1 < argc) {
150 opt_shutter = std::string(argv[++i]);
153 else if (std::string(argv[i]) ==
"--subsample" && i + 1 < argc) {
154 opt_subsample = std::atoi(argv[++i]);
157 else if (std::string(argv[i]) ==
"--white-balance" && i + 1 < argc) {
158 opt_white_balance = std::atoi(argv[++i]);
161 else if (std::string(argv[i]) ==
"--color-mode" && i + 1 < argc) {
162 opt_color_mode = std::string(argv[++i]);
165 else if (std::string(argv[i]) ==
"--seqname" && i + 1 < argc) {
166 opt_seqname = std::string(argv[++i]);
169 else if (std::string(argv[i]) ==
"--record" && i + 1 < argc) {
170 opt_record_mode = std::atoi(argv[++i]);
173 else if (std::string(argv[i]) ==
"--verbose" || std::string(argv[i]) ==
"-v") {
176 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
186 if ((!opt_display) && (!opt_seqname.empty())) {
206 if (!cam_ids.size()) {
207 std::cout <<
"No camera detected. Plug a camera and try again..." << std::endl;
210 std::cout <<
"Found " << cam_ids.size() <<
" cameras :" << std::endl;
211 for (
unsigned int i = 0;
i < cam_ids.size();
i++) {
212 std::cout << (opt_device ==
i ?
" * Camera " :
" Camera ") << i <<
" - ID: " << cam_ids[i]
213 <<
" Model: " << cam_models[i] <<
" S/N: " << cam_serials[i] << std::endl;
219 std::cout <<
"Unable to select camera " << opt_device << std::endl;
231 if (!opt_config_file.empty()) {
241 if (opt_subsample > 1) {
242 std::cout <<
"Subsampling factor: " << opt_subsample << std::endl;
248 if (!opt_gain.empty()) {
249 if (opt_gain ==
"auto") {
250 std::cout <<
"Auto gain : " << (g.
setGain(
true) ?
"enabled" :
"N/A") << std::endl;
253 std::cout <<
"Manual gain : "
254 << (g.
setGain(
false, std::atoi(opt_gain.c_str())) ? (std::string(opt_gain) +
" %") :
"N/A")
258 if (!opt_shutter.empty()) {
259 if (opt_shutter ==
"auto") {
260 std::cout <<
"Auto shutter : " << (g.
setExposure(
true) ?
"enabled" :
"N/A") << std::endl;
263 std::cout <<
"Manual shutter : "
264 << (g.
setExposure(
false, std::atof(opt_shutter.c_str())) ? (std::string(opt_shutter) +
" ms") :
"N/A")
269 if (opt_white_balance > 0) {
270 bool wb = (opt_white_balance ? true :
false);
271 std::cout <<
"Subsampling factor: " << opt_subsample << std::endl;
272 std::cout <<
"White balance : " << (wb ?
"auto" :
"disabled") << std::endl;
276 if (!opt_color_mode.empty()) {
278 std::cout <<
"Color mode : " << opt_color_mode << std::endl;
282 if (!opt_fps.empty()) {
283 if (opt_fps ==
"auto") {
284 std::cout <<
"Auto framerate : " << (g.
setFrameRate(
true) ?
"enabled" :
"N/A") << std::endl;
287 std::cout <<
"Manual framerate : "
288 << (g.
setFrameRate(
false, std::atof(opt_fps.c_str())) ? (std::string(opt_fps) +
" Hz") :
"N/A")
293 std::cout <<
"Recording : " << (opt_seqname.empty() ?
"disabled" :
"enabled") << std::endl;
294 std::cout <<
"Display : " << (opt_display ?
"enabled" :
"disabled") << std::endl;
296 std::string text_record_mode =
297 std::string(
"Record mode : ") + (opt_record_mode ? std::string(
"single") : std::string(
"continuous"));
299 if (!opt_seqname.empty()) {
300 std::cout << text_record_mode << std::endl;
301 std::cout <<
"Record name : " << opt_seqname << std::endl;
304 std::cout <<
"Config file : " << (opt_config_file.empty() ?
"empty" : opt_config_file) << std::endl;
305 std::cout <<
"Image size : " << I.getWidth() <<
" " << I.getHeight() << std::endl;
308#if !(defined(VISP_HAVE_DISPLAY))
309 std::cout <<
"No image viewer is available..." << std::endl;
312#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
323 vpImageQueue<vpRGBa> image_queue(opt_seqname, opt_record_mode);
327 vpImageQueue<unsigned char> image_queue(opt_seqname, opt_record_mode);
333 double timestamp_camera = 0, timestamp_camera_prev = 0;
334 std::string timestamp_system;
336 g.
acquire(I, ×tamp_camera, ×tamp_system);
341 quit = image_queue.record(I, ×tamp_system);
344 std::cout <<
"System timestamp: " << timestamp_system << std::endl;
345 std::cout <<
"Camera timestamp diff: " << timestamp_camera - timestamp_camera_prev << std::endl;
346 timestamp_camera_prev = timestamp_camera;
351 std::stringstream ss;
352 ss <<
"Camera framerate: " <<
fps;
359 image_queue.cancel();
360 image_storage_thread.join();
363 std::cout <<
"Catch an exception: " <<
e << std::endl;
366#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
367 if (display !=
nullptr) {
374#ifndef VISP_HAVE_UEYE
375 std::cout <<
"Install IDS uEye SDK, configure and build ViSP again to use this example" << std::endl;
377#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
378 std::cout <<
"This tutorial should be built with c++11 support" << std::endl;
Class that defines generic functionalities for display.
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
unsigned int getDownScalingFactor()
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.
Definition of the vpImage class member functions.
void open(vpImage< unsigned char > &I)
std::vector< std::string > getCameraSerialNumberList() const
bool setExposure(bool auto_exposure, double exposure_ms=-1)
bool setFrameRate(bool auto_frame_rate, double manual_frame_rate_hz=-1)
void setWhiteBalance(bool auto_wb)
bool setGain(bool auto_gain, int master_gain=-1, bool gain_boost=false)
void acquire(vpImage< unsigned char > &I, double *timestamp_camera=nullptr, std::string *timestamp_system=nullptr)
double getFramerate() const
void loadParameters(const std::string &filename)
std::vector< std::string > getCameraModelList() const
std::vector< unsigned int > getCameraIDList() const
void setSubsampling(int factor)
unsigned int getFrameHeight() const
unsigned int getFrameWidth() const
bool setActiveCamera(unsigned int cam_index)
bool setColorMode(const std::string &color_mode)
std::string getActiveCameraModel() const
std::string getActiveCameraSerialNumber() const
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.