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/io/vpImageStorageWorker.h>
7#include <visp3/sensor/vpPylonFactory.h>
9void usage(
const char *argv[],
int error)
11 std::cout <<
"SYNOPSIS" << std::endl
12 <<
" " << argv[0] <<
" [--device <index>]"
13 <<
" [--type <device type>]"
14 <<
" [--seqname <sequence name>]"
15 <<
" [--record <mode>]"
17 <<
" [--help] [-h]" << std::endl
19 std::cout <<
"DESCRIPTION" << std::endl
20 <<
" --device <index> " << std::endl
21 <<
" Camera device index in range [0...9]. Set 0 to dial with the first camera," << std::endl
22 <<
" and 1 to dial with the second camera attached to the computer." << std::endl
23 <<
" Default: 0." << std::endl
25 <<
" --type <device type>" << std::endl
26 <<
" Camera device type: GigE or USB" << std::endl
27 <<
" Default: GigE" << std::endl
29 <<
" --seqname <sequence name>" << std::endl
30 <<
" Name of the sequence of image to create (ie: /tmp/image%04d.jpg)." << std::endl
31 <<
" Default: empty." << std::endl
33 <<
" --record <mode>" << std::endl
34 <<
" Allowed values for mode are:" << std::endl
35 <<
" 0: record all the captures images (continuous mode)," << std::endl
36 <<
" 1: record only images selected by a user click (single shot mode)." << std::endl
37 <<
" Default mode: 0" << std::endl
39 <<
" --no-display" << std::endl
40 <<
" Disable displaying captured images." << std::endl
41 <<
" When used and sequence name specified, record mode is internally set to 1 (continuous mode)."
44 <<
" --help, -h" << std::endl
45 <<
" Print this helper message." << std::endl
47 std::cout <<
"USAGE" << std::endl
48 <<
" Example to visualize images:" << std::endl
49 <<
" " << argv[0] << std::endl
51 <<
" Example to visualize images from a second camera GigE:" << std::endl
52 <<
" " << argv[0] <<
" --device 1 --type GigE" << std::endl
54 <<
" Examples to record a sequence:" << std::endl
55 <<
" " << argv[0] <<
" --seqname I%04d.png" << std::endl
56 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 0" << std::endl
58 <<
" Examples to record single shot images:\n"
59 <<
" " << argv[0] <<
" --seqname I%04d.png --record 1\n"
60 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 1" << std::endl
64 std::cout <<
"Error" << std::endl
66 <<
"Unsupported parameter " << argv[error] << std::endl;
74int main(
int argc,
const char *argv[])
76#if defined(VISP_HAVE_PYLON) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
78 unsigned int opt_device = 0;
79 std::string opt_type(
"GigE");
80 std::string opt_seqname;
81 int opt_record_mode = 0;
82 bool opt_change_settings =
false;
83 bool opt_display =
true;
85 for (
int i = 1; i < argc; i++) {
86 if (std::string(argv[i]) ==
"--device") {
87 opt_device = std::atoi(argv[i + 1]);
90 if (std::string(argv[i]) ==
"--type") {
91 opt_type = std::string(argv[i + 1]);
93 }
else if (std::string(argv[i]) ==
"--seqname") {
94 opt_seqname = std::string(argv[i + 1]);
96 }
else if (std::string(argv[i]) ==
"--record") {
97 opt_record_mode = std::atoi(argv[i + 1]);
99 }
else if (std::string(argv[i]) ==
"--no-display") {
101 }
else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
110 if ((!opt_display) && (!opt_seqname.empty())) {
114 std::cout <<
"Settings : " << (opt_change_settings ?
"modified" :
"current") << std::endl;
115 std::cout <<
"Recording : " << (opt_seqname.empty() ?
"disabled" :
"enabled") << std::endl;
116 std::cout <<
"Display : " << (opt_display ?
"enabled" :
"disabled") << std::endl;
118 std::string text_record_mode =
119 std::string(
"Record mode: ") + (opt_record_mode ? std::string(
"single") : std::string(
"continuous"));
121 if (!opt_seqname.empty()) {
122 std::cout << text_record_mode << std::endl;
123 std::cout <<
"Record name: " << opt_seqname << std::endl;
131 if (opt_type ==
"GigE" || opt_type ==
"gige") {
133 std::cout <<
"Opening Basler GigE camera: " << opt_device << std::endl;
134 }
else if (opt_type ==
"USB" || opt_type ==
"usb") {
136 std::cout <<
"Opening Basler USB camera: " << opt_device << std::endl;
138 std::cout <<
"Error: only Basler GigE or USB cameras are supported." << std::endl;
145 std::cout <<
"Image size : " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
149#if !(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
150 std::cout <<
"No image viewer is available..." << std::endl;
157#elif defined(VISP_HAVE_GDI)
159#elif defined(HAVE_OPENCV_HIGHGUI)
175 quit = image_queue.record(I);
177 std::stringstream ss;
182 image_queue.cancel();
183 image_storage_thread.join();
189 std::cout <<
"Catch an exception: " << e << std::endl;
194#ifndef VISP_HAVE_PYLON
195 std::cout <<
"Install Basler Pylon SDK, configure and build ViSP again to use this example" << std::endl;
197#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
198 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...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
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.
Definition of the vpImage class member functions.
unsigned int getWidth() const
unsigned int getHeight() const
Factory singleton class to create vpPylonGrabber subclass instances.
@ BASLER_GIGE
Basler GigE camera.
@ BASLER_USB
Basler USB camera.
static vpPylonFactory & instance()
Get the vpPylonFactory singleton.
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()