Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
testPylonGrabber.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See https://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Basler cameras video capture using Pylon SDK.
33 *
34 * Authors:
35 * Wenfeng CAI
36 *
37*****************************************************************************/
38
45#include <visp3/core/vpConfig.h>
46#include <visp3/core/vpDebug.h>
47
48#include <iostream>
49#include <string>
50
51#if defined(VISP_HAVE_PYLON)
52
53#include <visp3/core/vpIoTools.h>
54#include <visp3/io/vpImageIo.h>
55#include <visp3/sensor/vpPylonFactory.h>
59int main()
60{
61 try {
62 std::cout << "Basler camera test with Pylon in progress..." << std::endl;
63
64 // Get the user name
65 std::string username;
66 vpIoTools::getUserName(username);
67 std::string outputpath = "/tmp/" + username;
68 vpIoTools::makeDirectory(outputpath);
69
70 // Creation of an empty image container
72
74 // Creation of a framegrabber
76 std::string guid;
77
78 // Get the number of cameras connected on the bus
79 unsigned int ncameras; // Number of cameras on the bus
80 ncameras = g->getNumCameras();
81 for (unsigned int i = 0; i < ncameras; i++) {
82 g->setCameraIndex(i);
83 guid = g->getCameraSerial(i);
84 std::cout << "Detected camera with serial: " << guid << std::endl;
85 }
86 // If more than one camera connected, use the first one
87 if (ncameras > 1) {
88 g->setCameraIndex(0);
89 guid = g->getCameraSerial(0);
90 std::cout << "Use camera with serial: " << guid << std::endl;
91 // to be sure that the setCamera() in the next line with
92 // guid as parameter works
93 g->setCameraIndex(0);
94 g->setCameraSerial(guid);
95 }
96 g->getCameraInfo(std::cout);
97
98 std::cout << "Frame rate: " << g->getFrameRate() << std::endl;
99 std::cout << "Gain: " << g->getGain() << std::endl;
100 std::cout << "Gamma: " << g->getGamma() << std::endl;
101 std::cout << "Exposure time (ms): " << g->getExposure() << std::endl;
102 float blackLevel = g->getBlackLevel();
103 std::cout << "Black level: " << blackLevel << std::endl;
104
105 for (int i = 0; i < 10; i++)
106 g->acquire(I);
107 g->close();
108 std::cout << "Current image size: " << g->getWidth() << "x" << g->getHeight() << std::endl;
109
110 std::string filename = outputpath + "/imagetest1.pgm";
111 std::cout << "Write image: " << filename << std::endl;
112 vpImageIo::write(I, filename);
113
114 std::cout << "New connection..." << std::endl;
115 g->open(I);
116 g->close();
117
118 std::cout << "New connection..." << std::endl;
119 g->open(I);
120 g->close();
121 filename = outputpath + "/imagetest2.pgm";
122 std::cout << "Write image: " << filename << std::endl;
123 vpImageIo::write(I, filename);
124 } catch (const vpException &e) {
125 vpCERROR << e.what() << std::endl;
126 } catch (const std::exception &e) {
127 vpCERROR << e.what() << std::endl;
128 } catch (...) {
129 vpCERROR << "Failure: exit" << std::endl;
130 }
131}
132#else
133int main()
134{
135 vpTRACE("Basler Pylon grabber capabilities are not available...\n"
136 "You should install pylon SDK to use this binary.");
137}
138
139#endif
error that can be emitted by ViSP classes.
Definition vpException.h:59
const char * what() const
unsigned int getWidth() const
Return the number of columns in the image.
unsigned int getHeight() const
Return the number of rows in the image.
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
Definition vpImage.h:135
static std::string getUserName()
static void makeDirectory(const std::string &dirname)
Factory singleton class to create vpPylonGrabber subclass instances.
@ BASLER_GIGE
Basler GigE camera.
static vpPylonFactory & instance()
Get the vpPylonFactory singleton.
vpPylonGrabber * createPylonGrabber(DeviceClass dev_class)
Create an object of vpPylonGrabber.
virtual void close()=0
Stop active camera capturing images and disconnect the active camera.
virtual float getFrameRate()=0
virtual unsigned int getNumCameras()=0
Get the number of cameras of specific subclasses. GigE, USB, etc.
virtual void setCameraSerial(const std::string &serial)=0
virtual float getBlackLevel()=0
virtual float getGain()=0
virtual void acquire(vpImage< unsigned char > &I)=0
virtual float getExposure()=0
virtual void open(vpImage< unsigned char > &I)=0
virtual std::string getCameraSerial(unsigned int index)=0
virtual void setCameraIndex(unsigned int index)=0
virtual std::ostream & getCameraInfo(std::ostream &os)=0
virtual float getGamma()=0
#define vpCERROR
Definition vpDebug.h:360
#define vpTRACE
Definition vpDebug.h:411