2 #include <visp3/core/vpConfig.h>
3 #include <visp3/core/vpImage.h>
4 #include <visp3/gui/vpDisplayGDI.h>
5 #include <visp3/gui/vpDisplayOpenCV.h>
6 #include <visp3/gui/vpDisplayX.h>
7 #include <visp3/io/vpImageStorageWorker.h>
8 #include <visp3/sensor/vpPylonFactory.h>
10 void usage(
const char *argv[],
int error)
12 std::cout <<
"SYNOPSIS" << std::endl
13 <<
" " << argv[0] <<
" [--device <index>]"
14 <<
" [--type <device type>]"
15 <<
" [--seqname <sequence name>]"
16 <<
" [--record <mode>]"
18 <<
" [--help] [-h]" << std::endl
20 std::cout <<
"DESCRIPTION" << std::endl
21 <<
" --device <index> " << std::endl
22 <<
" Camera device index in range [0...9]. Set 0 to dial with the first camera," << std::endl
23 <<
" and 1 to dial with the second camera attached to the computer." << std::endl
24 <<
" Default: 0." << std::endl
26 <<
" --type <device type>" << std::endl
27 <<
" Camera device type: GigE or USB" << std::endl
28 <<
" Default: GigE" << std::endl
30 <<
" --seqname <sequence name>" << std::endl
31 <<
" Name of the sequence of image to create (ie: /tmp/image%04d.jpg)." << std::endl
32 <<
" Default: empty." << std::endl
34 <<
" --record <mode>" << std::endl
35 <<
" Allowed values for mode are:" << std::endl
36 <<
" 0: record all the captures images (continuous mode)," << std::endl
37 <<
" 1: record only images selected by a user click (single shot mode)." << std::endl
38 <<
" Default mode: 0" << std::endl
40 <<
" --no-display" << std::endl
41 <<
" Disable displaying captured images." << std::endl
42 <<
" When used and sequence name specified, record mode is internally set to 1 (continuous mode)."
45 <<
" --help, -h" << std::endl
46 <<
" Print this helper message." << std::endl
48 std::cout <<
"USAGE" << std::endl
49 <<
" Example to visualize images:" << std::endl
50 <<
" " << argv[0] << std::endl
52 <<
" Example to visualize images from a second camera GigE:" << std::endl
53 <<
" " << argv[0] <<
" --device 1 --type GigE" << std::endl
55 <<
" Examples to record a sequence:" << std::endl
56 <<
" " << argv[0] <<
" --seqname I%04d.png" << std::endl
57 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 0" << std::endl
59 <<
" Examples to record single shot images:\n"
60 <<
" " << argv[0] <<
" --seqname I%04d.png --record 1\n"
61 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 1" << std::endl
65 std::cout <<
"Error" << std::endl
67 <<
"Unsupported parameter " << argv[error] << std::endl;
75 int main(
int argc,
const char *argv[])
77 #if defined(VISP_HAVE_PYLON) && defined(VISP_HAVE_THREADS)
78 #ifdef ENABLE_VISP_NAMESPACE
82 unsigned int opt_device = 0;
83 std::string opt_type(
"GigE");
84 std::string opt_seqname;
85 int opt_record_mode = 0;
86 bool opt_change_settings =
false;
87 bool opt_display =
true;
89 for (
int i = 1; i < argc; i++) {
90 if (std::string(argv[i]) ==
"--device") {
91 opt_device = std::atoi(argv[i + 1]);
94 if (std::string(argv[i]) ==
"--type") {
95 opt_type = std::string(argv[i + 1]);
98 else if (std::string(argv[i]) ==
"--seqname") {
99 opt_seqname = std::string(argv[i + 1]);
102 else if (std::string(argv[i]) ==
"--record") {
103 opt_record_mode = std::atoi(argv[i + 1]);
106 else if (std::string(argv[i]) ==
"--no-display") {
109 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
119 if ((!opt_display) && (!opt_seqname.empty())) {
123 std::cout <<
"Settings : " << (opt_change_settings ?
"modified" :
"current") << std::endl;
124 std::cout <<
"Recording : " << (opt_seqname.empty() ?
"disabled" :
"enabled") << std::endl;
125 std::cout <<
"Display : " << (opt_display ?
"enabled" :
"disabled") << std::endl;
127 std::string text_record_mode =
128 std::string(
"Record mode: ") + (opt_record_mode ? std::string(
"single") : std::string(
"continuous"));
130 if (!opt_seqname.empty()) {
131 std::cout << text_record_mode << std::endl;
132 std::cout <<
"Record name: " << opt_seqname << std::endl;
140 if (opt_type ==
"GigE" || opt_type ==
"gige") {
142 std::cout <<
"Opening Basler GigE camera: " << opt_device << std::endl;
144 else if (opt_type ==
"USB" || opt_type ==
"usb") {
146 std::cout <<
"Opening Basler USB camera: " << opt_device << std::endl;
149 std::cout <<
"Error: only Basler GigE or USB cameras are supported." << std::endl;
156 std::cout <<
"Image size : " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
160 #if !(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
161 std::cout <<
"No image viewer is available..." << std::endl;
167 d =
new vpDisplayX(I);
168 #elif defined(VISP_HAVE_GDI)
170 #elif defined(HAVE_OPENCV_HIGHGUI)
175 vpImageQueue<vpRGBa> image_queue(opt_seqname, opt_record_mode);
186 quit = image_queue.record(I);
188 std::stringstream ss;
193 image_queue.cancel();
194 image_storage_thread.join();
201 std::cout <<
"Catch an exception: " << e << std::endl;
206 #ifndef VISP_HAVE_PYLON
207 std::cout <<
"Install Basler Pylon SDK, configure and build ViSP again to use this example" << std::endl;
209 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
210 std::cout <<
"This tutorial 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...
Class that defines generic functionalities for display.
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.
unsigned int getWidth() const
unsigned int getHeight() const
Factory singleton class to create vpPylonGrabber subclass instances.
static vpPylonFactory & instance()
Get the vpPylonFactory singleton.
@ BASLER_GIGE
Basler GigE camera.
@ BASLER_USB
Basler USB camera.
vpPylonGrabber * createPylonGrabber(DeviceClass dev_class)
Create an object of vpPylonGrabber.
virtual void acquire(vpImage< unsigned char > &I)=0
virtual void open(vpImage< unsigned char > &I)=0
virtual void setCameraIndex(unsigned int index)=0
VISP_EXPORT double measureTimeMs()