Visual Servoing Platform  version 3.6.1 under development (2024-04-26)
testPylonGrabber.cpp
/****************************************************************************
*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2023 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See https://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Basler cameras video capture using Pylon SDK.
*
* Authors:
* Wenfeng CAI
*
*****************************************************************************/
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpDebug.h>
#include <iostream>
#include <string>
#if defined(VISP_HAVE_PYLON)
#include <visp3/core/vpIoTools.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/sensor/vpPylonFactory.h>
int main()
{
try {
std::cout << "Basler camera test with Pylon in progress..." << std::endl;
// Get the user name
std::string username;
std::string outputpath = "/tmp/" + username;
// Creation of an empty image container
// Creation of a framegrabber
std::string guid;
// Get the number of cameras connected on the bus
unsigned int ncameras; // Number of cameras on the bus
ncameras = g->getNumCameras();
for (unsigned int i = 0; i < ncameras; i++) {
guid = g->getCameraSerial(i);
std::cout << "Detected camera with serial: " << guid << std::endl;
}
// If more than one camera connected, use the first one
if (ncameras > 1) {
guid = g->getCameraSerial(0);
std::cout << "Use camera with serial: " << guid << std::endl;
// to be sure that the setCamera() in the next line with
// guid as parameter works
g->setCameraSerial(guid);
}
g->getCameraInfo(std::cout);
std::cout << "Frame rate: " << g->getFrameRate() << std::endl;
std::cout << "Gain: " << g->getGain() << std::endl;
std::cout << "Gamma: " << g->getGamma() << std::endl;
std::cout << "Exposure time (ms): " << g->getExposure() << std::endl;
float blackLevel = g->getBlackLevel();
std::cout << "Black level: " << blackLevel << std::endl;
for (int i = 0; i < 10; i++)
g->acquire(I);
g->close();
std::cout << "Current image size: " << g->getWidth() << "x" << g->getHeight() << std::endl;
std::string filename = outputpath + "/imagetest1.pgm";
std::cout << "Write image: " << filename << std::endl;
vpImageIo::write(I, filename);
std::cout << "New connection..." << std::endl;
g->open(I);
g->close();
std::cout << "New connection..." << std::endl;
g->open(I);
g->close();
filename = outputpath + "/imagetest2.pgm";
std::cout << "Write image: " << filename << std::endl;
vpImageIo::write(I, filename);
} catch (const vpException &e) {
vpCERROR << e.what() << std::endl;
} catch (const std::exception &e) {
vpCERROR << e.what() << std::endl;
} catch (...) {
vpCERROR << "Failure: exit" << std::endl;
}
}
#else
int main()
{
vpTRACE("Basler Pylon grabber capabilities are not available...\n"
"You should install pylon SDK to use this binary.");
}
#endif
error that can be emitted by ViSP classes.
Definition: vpException.h:59
const char * what() const
Definition: vpException.cpp:70
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: vpImageIo.cpp:287
static std::string getUserName()
Definition: vpIoTools.cpp:725
static void makeDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:981
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 std::ostream & getCameraInfo(std::ostream &os)=0
virtual void setCameraIndex(unsigned int index)=0
virtual float getGamma()=0
#define vpCERROR
Definition: vpDebug.h:356
#define vpTRACE
Definition: vpDebug.h:405