Visual Servoing Platform  version 3.1.0
tutorial-grabber-basler-pylon.cpp
1 
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/vpPylonFactory.h>
7 
14 int main(int argc, const char *argv[])
15 {
16 #ifdef VISP_HAVE_PYLON
17  try {
18  unsigned int opt_camera = 0;
19  std::string opt_device("GigE");
20 
21  for (int i = 0; i < argc; i++) {
22  if (std::string(argv[i]) == "--camera")
23  opt_camera = (unsigned int)atoi(argv[i + 1]);
24  if (std::string(argv[i]) == "--device")
25  opt_device = std::string(argv[i + 1]);
26  else if (std::string(argv[i]) == "--help") {
27  std::cout << "Usage: " << argv[0] << " [--camera <0...9>] [--device <\"GigE\"|\"USB\">] [--help]" << std::endl;
28  return EXIT_SUCCESS;
29  }
30  }
31 
33 
35 
36  vpPylonGrabber *g;
37  if (opt_device == "GigE" || opt_device == "gige") {
39  std::cout << "Opening Basler GigE camera: " << opt_camera << std::endl;
40  } else if (opt_device == "USB" || opt_device == "usb") {
42  std::cout << "Opening Basler USB camera: " << opt_camera << std::endl;
43  } else {
44  std::cout << "Error: only Basler GigE or USB cameras are supported." << std::endl;
45  return EXIT_SUCCESS;
46  }
47  g->setCameraIndex(opt_camera);
48 
49  g->open(I);
50 
51  std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;
52 
53 #ifdef VISP_HAVE_X11
54  vpDisplayX d(I);
55 #elif defined(VISP_HAVE_GDI)
56  vpDisplayGDI d(I);
57 #elif defined(VISP_HAVE_OPENCV)
58  vpDisplayOpenCV d(I);
59 #else
60  std::cout << "No image viewer is available..." << std::endl;
61 #endif
62 
63  while (1) {
64  g->acquire(I);
66  vpDisplay::displayText(I, 10, 10, "A click to quit", vpColor::red);
68  if (vpDisplay::getClick(I, false))
69  break;
70  }
71  } catch (vpException &e) {
72  std::cout << "Catch an exception: " << e << std::endl;
73  }
74 #else
75  (void)argc;
76  (void)argv;
77 #endif
78 }
virtual void open(vpImage< unsigned char > &I)=0
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:129
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:151
error that can be emited by ViSP classes.
Definition: vpException.h:71
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:180
Basler GigE camera.
Factory singleton class to create vpPylonGrabber subclass instances.
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
virtual void acquire(vpImage< unsigned char > &I)=0
static vpPylonFactory & instance()
Get the vpPylonFactory singleton.
Basler USB camera.
virtual void setCameraIndex(unsigned int index)=0
unsigned int getHeight() const
Definition: vpImage.h:178
vpPylonGrabber * createPylonGrabber(DeviceClass dev_class)
Create an object of vpPylonGrabber.
unsigned int getWidth() const
Definition: vpImage.h:229