2 #include <visp3/core/vpImage.h>
3 #include <visp3/gui/vpDisplayGDI.h>
4 #include <visp3/gui/vpDisplayOpenCV.h>
5 #include <visp3/gui/vpDisplayX.h>
6 #include <visp3/sensor/vpUeyeGrabber.h>
7 #include <visp3/io/vpImageStorageWorker.h>
16 int main(
int argc,
const char *argv[])
18 #if defined(VISP_HAVE_UEYE) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
20 unsigned int opt_camera = 0;
21 std::string opt_seqname;
22 int opt_record_mode = 0;
23 std::string opt_config_file =
"";
24 std::string opt_fps =
"";
25 std::string opt_gain =
"";
26 std::string opt_shutter =
"";
27 std::string opt_color_mode =
"";
28 int opt_white_balance = -1;
29 int opt_subsample = 1;
30 bool opt_verbose =
false;
32 for (
int i = 0; i < argc; i++) {
33 if (std::string(argv[i]) ==
"--camera")
34 opt_camera = (
unsigned int)atoi(argv[i + 1]);
35 else if (std::string(argv[i]) ==
"--config-file")
36 opt_config_file = std::string(argv[i + 1]);
37 else if (std::string(argv[i]) ==
"--fps")
38 opt_fps = std::string(argv[i + 1]);
39 else if (std::string(argv[i]) ==
"--gain")
40 opt_gain = std::string(argv[i + 1]);
41 else if (std::string(argv[i]) ==
"--shutter")
42 opt_shutter = std::string(argv[i + 1]);
43 else if (std::string(argv[i]) ==
"--subsample")
44 opt_subsample = std::atoi(argv[i + 1]);
45 else if (std::string(argv[i]) ==
"--white-balance")
46 opt_white_balance = std::atoi(argv[i + 1]);
47 else if (std::string(argv[i]) ==
"--color-mode")
48 opt_color_mode = std::string(argv[i + 1]);
49 else if (std::string(argv[i]) ==
"--seqname")
50 opt_seqname = std::string(argv[i + 1]);
51 else if (std::string(argv[i]) ==
"--record")
52 opt_record_mode = std::atoi(argv[i + 1]);
53 else if (std::string(argv[i]) ==
"--verbose" || std::string(argv[i]) ==
"-v")
55 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
56 std::cout <<
"\nUsage: " << argv[0]
57 <<
" [--camera <index> (default: 0)]"
58 <<
" [--config-file <filename.ini> (default: empty)]"
59 <<
" [--fps <auto | value> (default: empty)]"
60 <<
" [--gain <auto | value in 0 - 100> (default: empty)]"
61 <<
" [--shutter <auto | exposure value in ms> (default: empty)]"
62 <<
" [--subsample <1,2,3,4,5,6,8,16> (default: 1)]"
63 <<
" [--white-balance <0: disabled, 1: enabled> (default: -1)]"
64 <<
" [--color-mode <mono8, rgb24, rgb32> (default: empty)]"
65 <<
" [--seqname <sequence name> (default: empty)]"
66 <<
" [--record <0: continuous | 1: single shot> (default: 0)]"
67 <<
" [--verbose] [-v]"
69 <<
"\nExample to visualize images:\n"
70 <<
" " << argv[0] <<
" \n"
71 <<
"\nExample to visualize images and set camera parameter from a config file:\n"
72 <<
" " << argv[0] <<
" --config-file UI-388xCP-C.ini\n"
73 <<
"\nExamples to record a sequence:\n"
74 <<
" " << argv[0] <<
" --seqname I%04d.png \n"
75 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 0\n"
76 <<
"\nExamples to record single shot images:\n"
77 <<
" " << argv[0] <<
" --seqname I%04d.png --record 1\n"
78 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 1\n"
100 if (! cam_ids.size()) {
101 std::cout <<
"No camera detected. Plug a camera and try again..." << std::endl;
104 std::cout <<
"Found " << cam_ids.size() <<
" cameras :"<< std::endl;
105 for (
unsigned int i = 0; i < cam_ids.size(); i++) {
106 std::cout << (opt_camera == i ?
" * Camera " :
" Camera ") << i
107 <<
" - ID: " << cam_ids[i] <<
" Model: " << cam_models[i] <<
" S/N: " << cam_serials[i] << std::endl;
113 std::cout <<
"Unable to select camera " << opt_camera << std::endl;
124 if (! opt_config_file.empty()) {
134 if (opt_subsample > 1) {
135 std::cout <<
"Subsampling factor: " << opt_subsample << std::endl;
141 if (! opt_gain.empty()) {
142 if (opt_gain ==
"auto") {
143 std::cout <<
"Auto gain : " << (g.
setGain(
true) ?
"enabled" :
"N/A") << std::endl;
146 std::cout <<
"Manual gain : " << (g.
setGain(
false, std::atoi(opt_gain.c_str())) ? (std::string(opt_gain) +
" %") :
"N/A") << std::endl;
149 if (! opt_shutter.empty()) {
150 if (opt_shutter ==
"auto") {
151 std::cout <<
"Auto shutter : " << (g.
setExposure(
true) ?
"enabled" :
"N/A") << std::endl;
154 std::cout <<
"Manual shutter : " << (g.
setExposure(
false, std::atof(opt_shutter.c_str())) ? (std::string(opt_shutter) +
" ms") :
"N/A") << std::endl;
158 if (opt_white_balance > 0) {
159 bool wb = (opt_white_balance ? true :
false);
160 std::cout <<
"Subsampling factor: " << opt_subsample << std::endl;
161 std::cout <<
"White balance : " << (wb ?
"auto" :
"disabled") << std::endl;
165 if (! opt_color_mode.empty()) {
167 std::cout <<
"Color mode : " << opt_color_mode << std::endl;
171 if (! opt_fps.empty()) {
172 if (opt_fps ==
"auto") {
173 std::cout <<
"Auto framerate : " << (g.
setFrameRate(
true) ?
"enabled" :
"N/A") << std::endl;
176 std::cout <<
"Manual framerate : " << (g.
setFrameRate(
false, std::atof(opt_fps.c_str())) ? (std::string(opt_fps) +
" Hz") :
"N/A") << std::endl;
180 std::cout <<
"Recording : " << (opt_seqname.empty() ?
"disabled" :
"enabled") << std::endl;
182 std::string text_record_mode = std::string(
"Record mode : ") + (opt_record_mode ? std::string(
"single") : std::string(
"continuous"));
184 if (! opt_seqname.empty()) {
185 std::cout << text_record_mode << std::endl;
186 std::cout <<
"Record name : " << opt_seqname << std::endl;
189 std::cout <<
"Config file : " << (opt_config_file.empty() ?
"empty" : opt_config_file) << std::endl;
190 std::cout <<
"Image size : " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
194 #elif defined(VISP_HAVE_GDI)
196 #elif defined(VISP_HAVE_OPENCV)
199 std::cout <<
"No image viewer is available..." << std::endl;
202 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)
218 double timestamp_camera = 0, timestamp_camera_prev = 0;
219 std::string timestamp_system;
221 g.
acquire(I, ×tamp_camera, ×tamp_system);
226 quit = image_queue.record(I, ×tamp_system);
229 std::cout <<
"System timestamp: " << timestamp_system << std::endl;
230 std::cout <<
"Camera timestamp diff: " << timestamp_camera - timestamp_camera_prev << std::endl;
231 timestamp_camera_prev = timestamp_camera;
236 std::stringstream ss;
237 ss <<
"Camera framerate: " << fps;
244 image_queue.cancel();
245 image_storage_thread.join();
247 std::cout <<
"Catch an exception: " << e << std::endl;
252 #ifndef VISP_HAVE_UEYE
253 std::cout <<
"Install IDS uEye SDK, configure and build ViSP again to use this example" << std::endl;
255 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
256 std::cout <<
"This turorial should be built with c++11 support" << std::endl;
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
virtual void setDownScalingFactor(unsigned int scale)
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 emited by ViSP classes.
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getHeight() const
void open(vpImage< unsigned char > &I)
std::vector< std::string > getCameraSerialNumberList() const
void acquire(vpImage< unsigned char > &I, double *timestamp_camera=NULL, std::string *timestamp_system=NULL)
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)
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