fixes and improvements, no segfaults anymore
This commit is contained in:
parent
bb500f465c
commit
be22594369
@ -3,15 +3,25 @@
|
|||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
||||||
ImageBuffer::ImageBuffer(size_t buffer_size, QObject *parent) : QObject(parent), buffer_size(buffer_size) {
|
ImageBuffer::ImageBuffer(size_t buffer_size, QObject *parent) : QObject(parent), buffer_size(buffer_size) {
|
||||||
buffer.resize(buffer_size);
|
buffer.resize(buffer_size, nullptr);
|
||||||
|
std::cerr << "imagebuffer constructor!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageBuffer::clear() {
|
void ImageBuffer::clear() {
|
||||||
|
std::cerr << "Clear Image buffer!" << std::endl;
|
||||||
|
|
||||||
for (auto & img: buffer) {
|
for (auto & img: buffer) {
|
||||||
|
std::cerr << "Clear Image buffer!" << std::endl;
|
||||||
|
|
||||||
if (img != nullptr)
|
if (img != nullptr)
|
||||||
delete(img);
|
delete(img);
|
||||||
|
img = nullptr;
|
||||||
}
|
}
|
||||||
|
std::cerr << "Clear Image buffer!" << std::endl;
|
||||||
|
|
||||||
resize(buffer_size);
|
resize(buffer_size);
|
||||||
|
std::cerr << "Clear Image buffer! done" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ImageBuffer::capacity() {
|
size_t ImageBuffer::capacity() {
|
||||||
@ -35,10 +45,12 @@ size_t ImageBuffer::bufferLoad() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ImageBuffer::resize(size_t new_size) {
|
void ImageBuffer::resize(size_t new_size) {
|
||||||
|
std::cerr << "Buffer Resize" << std::endl;
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
|
|
||||||
buffer_size = new_size;
|
buffer_size = new_size;
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
buffer.resize(new_size);
|
buffer.resize(new_size, nullptr);
|
||||||
current_read_index = 0;
|
current_read_index = 0;
|
||||||
current_write_index = 0;
|
current_write_index = 0;
|
||||||
load = 0;
|
load = 0;
|
||||||
|
6
main.cpp
6
main.cpp
@ -4,9 +4,12 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <pylon/PylonIncludes.h>
|
#include <pylon/PylonIncludes.h>
|
||||||
|
#include "mylogger.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
Logger::init();
|
||||||
|
qInfo() << "PylonRecorder start";
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
QGuiApplication::setApplicationDisplayName(PylonRecorder::tr("Pylon Recorder"));
|
QGuiApplication::setApplicationDisplayName(PylonRecorder::tr("Pylon Recorder"));
|
||||||
QGuiApplication::setOrganizationName("Bendalab");
|
QGuiApplication::setOrganizationName("Bendalab");
|
||||||
@ -38,5 +41,8 @@ int main(int argc, char *argv[])
|
|||||||
settings.setValue("app/height", recorder.height());
|
settings.setValue("app/height", recorder.height());
|
||||||
settings.setValue("app/pos_x", pos.x());
|
settings.setValue("app/pos_x", pos.x());
|
||||||
settings.setValue("app/pos_y", pos.y());
|
settings.setValue("app/pos_y", pos.y());
|
||||||
|
qInfo() << "PylonRecorder stop";
|
||||||
|
Logger::clean();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
PylonRecorder::PylonRecorder(QWidget *parent)
|
PylonRecorder::PylonRecorder(QWidget *parent)
|
||||||
: QMainWindow(parent), imageLabel(new QLabel), scrollArea(new QScrollArea)
|
: QMainWindow(parent), imageLabel(new QLabel), scrollArea(new QScrollArea), grabber(nullptr), writer(nullptr), buffer(nullptr), pyloncam(nullptr)
|
||||||
{
|
{
|
||||||
dryRun = false;
|
dryRun = false;
|
||||||
imageLabel->setBackgroundRole(QPalette::Base);
|
imageLabel->setBackgroundRole(QPalette::Base);
|
||||||
@ -44,7 +44,6 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
|||||||
scrollArea->setWidget(imageLabel);
|
scrollArea->setWidget(imageLabel);
|
||||||
scrollArea->setVisible(false);
|
scrollArea->setVisible(false);
|
||||||
setCentralWidget(scrollArea);
|
setCentralWidget(scrollArea);
|
||||||
std::cerr << "PylonRecorder::constructor" << std::endl;
|
|
||||||
// Pylon::DeviceInfoList_t deviceList = detectCameras();
|
// Pylon::DeviceInfoList_t deviceList = detectCameras();
|
||||||
// for (auto dev : deviceList) {
|
// for (auto dev : deviceList) {
|
||||||
// std::cout << dev.GetFullName() << " " << dev.GetFriendlyName() << std::endl;
|
// std::cout << dev.GetFullName() << " " << dev.GetFriendlyName() << std::endl;
|
||||||
@ -63,14 +62,12 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
|||||||
// writer = new Writer(buffer);
|
// writer = new Writer(buffer);
|
||||||
// connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone);
|
// connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone);
|
||||||
// }
|
// }
|
||||||
std::cerr << "PylonRecorder::constructor 1" << std::endl;
|
|
||||||
frameTimer = new QTimer(this);
|
frameTimer = new QTimer(this);
|
||||||
connect(frameTimer, &QTimer::timeout, this, &PylonRecorder::displaySingleFrame);
|
connect(frameTimer, &QTimer::timeout, this, &PylonRecorder::displaySingleFrame);
|
||||||
preassureTimer = new QTimer(this);
|
preassureTimer = new QTimer(this);
|
||||||
connect(preassureTimer, &QTimer::timeout, this, &PylonRecorder::displayBufferPreassure);
|
connect(preassureTimer, &QTimer::timeout, this, &PylonRecorder::displayBufferPressure);
|
||||||
labelTimer = new QTimer(this);
|
labelTimer = new QTimer(this);
|
||||||
connect(labelTimer, &QTimer::timeout, this, &PylonRecorder::displayActivity);
|
connect(labelTimer, &QTimer::timeout, this, &PylonRecorder::displayActivity);
|
||||||
std::cerr << "PylonRecorder::constructor 2" << std::endl;
|
|
||||||
preassureBar = new QProgressBar(this);
|
preassureBar = new QProgressBar(this);
|
||||||
preassureBar->setRange(0, 100);
|
preassureBar->setRange(0, 100);
|
||||||
preassureBar->setTextVisible(true);
|
preassureBar->setTextVisible(true);
|
||||||
@ -86,7 +83,6 @@ std::cerr << "PylonRecorder::constructor 2" << std::endl;
|
|||||||
loadBar->setFixedSize(200, 25);
|
loadBar->setFixedSize(200, 25);
|
||||||
QLabel *loadLabel = new QLabel("Load:", this);
|
QLabel *loadLabel = new QLabel("Load:", this);
|
||||||
loadLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;font-weight: Bold}");
|
loadLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;font-weight: Bold}");
|
||||||
std::cerr << "PylonRecorder::constructor 3" << std::endl;
|
|
||||||
writingLabel = new QLabel("writing");
|
writingLabel = new QLabel("writing");
|
||||||
writingLabel->setEnabled(false);
|
writingLabel->setEnabled(false);
|
||||||
writingLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;}");
|
writingLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;}");
|
||||||
@ -97,7 +93,6 @@ std::cerr << "PylonRecorder::constructor 3" << std::endl;
|
|||||||
cameraConnectedLabel = new QLabel("not connected");
|
cameraConnectedLabel = new QLabel("not connected");
|
||||||
cameraConnectedLabel->setStyleSheet("QLabel { color : red; }");
|
cameraConnectedLabel->setStyleSheet("QLabel { color : red; }");
|
||||||
cameraConnectedLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;}");
|
cameraConnectedLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;}");
|
||||||
std::cerr << "PylonRecorder::constructor 4" << std::endl;
|
|
||||||
fileLabel = new QLabel();
|
fileLabel = new QLabel();
|
||||||
fileLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;}");
|
fileLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;}");
|
||||||
|
|
||||||
@ -107,7 +102,6 @@ std::cerr << "PylonRecorder::constructor 4" << std::endl;
|
|||||||
statusHeader->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial; font-weight: Bold}");
|
statusHeader->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial; font-weight: Bold}");
|
||||||
QLabel *fileHeader = new QLabel("Output file:");
|
QLabel *fileHeader = new QLabel("Output file:");
|
||||||
fileHeader->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial; font-weight: Bold}");
|
fileHeader->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial; font-weight: Bold}");
|
||||||
std::cerr << "PylonRecorder::constructor 5" << std::endl;
|
|
||||||
statusBar()->addWidget(camHeader);
|
statusBar()->addWidget(camHeader);
|
||||||
statusBar()->addWidget(cameraConnectedLabel);
|
statusBar()->addWidget(cameraConnectedLabel);
|
||||||
statusBar()->addWidget(preassureLabel);
|
statusBar()->addWidget(preassureLabel);
|
||||||
@ -120,15 +114,10 @@ std::cerr << "PylonRecorder::constructor 5" << std::endl;
|
|||||||
statusBar()->addWidget(fileHeader);
|
statusBar()->addWidget(fileHeader);
|
||||||
statusBar()->addWidget(fileLabel);
|
statusBar()->addWidget(fileLabel);
|
||||||
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
|
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
|
||||||
std::cerr << "PylonRecorder::constructor 6" << std::endl;
|
|
||||||
detectCameras();
|
detectCameras();
|
||||||
std::cerr << "PylonRecorder::constructor 7" << std::endl;
|
|
||||||
createActions();
|
createActions();
|
||||||
std::cerr << "PylonRecorder::constructor 8 " << std::endl;
|
|
||||||
updateActions();
|
updateActions();
|
||||||
std::cerr << "PylonRecorder::constructor 9" << std::endl;
|
|
||||||
applySettings();
|
applySettings();
|
||||||
std::cerr << "PylonRecorder::constructor done" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PylonRecorder::setupCameras(){
|
void PylonRecorder::setupCameras(){
|
||||||
@ -140,13 +129,14 @@ void PylonRecorder::setupCameras(){
|
|||||||
std::cout << "peng\n";
|
std::cout << "peng\n";
|
||||||
|
|
||||||
if (deviceList.size() == 0) {
|
if (deviceList.size() == 0) {
|
||||||
std::cout << "device list is empty!" << std::endl;
|
qWarning() << "device list is empty!";
|
||||||
QErrorMessage message(this);
|
QErrorMessage message(this);
|
||||||
message.showMessage("No camera detected!");
|
message.showMessage("No camera detected!");
|
||||||
} else {
|
} else {
|
||||||
std::cout << "peng\n";
|
std::cout << "peng\n";
|
||||||
// std::string cname = (std::string)deviceList[0].GetFullName();
|
// std::string cname = (std::string)deviceList[0].GetFullName();
|
||||||
// pyloncam = new PylonWrapper(cname);
|
// pyloncam = new PylonWrapper(cname);
|
||||||
|
qDebug() << "Creating buffer, grabber, and writer";
|
||||||
buffer = new ImageBuffer(defaultBufferSize);
|
buffer = new ImageBuffer(defaultBufferSize);
|
||||||
grabber = new Grabber(pyloncam, buffer, defaultFrameRate);
|
grabber = new Grabber(pyloncam, buffer, defaultFrameRate);
|
||||||
writer = new Writer(buffer);
|
writer = new Writer(buffer);
|
||||||
@ -155,27 +145,37 @@ void PylonRecorder::setupCameras(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PylonRecorder::detectCameras() {
|
void PylonRecorder::detectCameras() {
|
||||||
Pylon::PylonAutoInitTerm autoInitTerm;
|
|
||||||
Pylon::CTlFactory& TlFactory = Pylon::CTlFactory::GetInstance();
|
Pylon::CTlFactory& TlFactory = Pylon::CTlFactory::GetInstance();
|
||||||
TlFactory.EnumerateDevices(deviceList);
|
TlFactory.EnumerateDevices(deviceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
PylonRecorder::~PylonRecorder(){
|
PylonRecorder::~PylonRecorder(){
|
||||||
if (grabber->isRunning()) {
|
qDebug() << "Destructing PylonRecorder";
|
||||||
|
if (grabber != nullptr && grabber->isRunning()) {
|
||||||
grabber->requestStop();
|
grabber->requestStop();
|
||||||
grabber->wait(1000);
|
grabber->wait(1000);
|
||||||
}
|
}
|
||||||
if (writer->isRunning()) {
|
if (writer != nullptr && writer->isRunning()) {
|
||||||
writer->forceStop();
|
writer->forceStop();
|
||||||
writer->wait(1000);
|
writer->wait(1000);
|
||||||
}
|
}
|
||||||
storeSettings();
|
storeSettings();
|
||||||
std::cerr << "recorder::destructor" << std::endl;
|
if (pyloncam != nullptr) {
|
||||||
|
qDebug() << "Deleting pyloncam";
|
||||||
delete pyloncam;
|
delete pyloncam;
|
||||||
std::cerr << "recorder::destructor" << std::endl;
|
pyloncam = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer != nullptr) {
|
||||||
|
qDebug() << "Deleting buffer";
|
||||||
delete buffer;
|
delete buffer;
|
||||||
|
buffer = nullptr;
|
||||||
|
}
|
||||||
|
qDebug() << "Deleting grabber";
|
||||||
delete grabber;
|
delete grabber;
|
||||||
|
qDebug() << "Deleting writer";
|
||||||
delete writer;
|
delete writer;
|
||||||
|
qDebug() << "Deleting setting";
|
||||||
delete settings;
|
delete settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,7 +556,7 @@ void PylonRecorder::updateActions() {
|
|||||||
disconnect_camera_action->setEnabled(deviceList.size() > 0);
|
disconnect_camera_action->setEnabled(deviceList.size() > 0);
|
||||||
connect_camera_action->setEnabled(true);
|
connect_camera_action->setEnabled(true);
|
||||||
grab_still_action->setEnabled(deviceList.size() > 0);
|
grab_still_action->setEnabled(deviceList.size() > 0);
|
||||||
grab_continuous_action->setEnabled(deviceList.size() > 0 && pyloncam->isOpen() && !grabbing);
|
//grab_continuous_action->setEnabled(deviceList.size() > 0 && pyloncam->isOpen() && !grabbing);
|
||||||
grab_stop_action->setEnabled(grabbing);
|
grab_stop_action->setEnabled(grabbing);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,15 +582,14 @@ void PylonRecorder::applyScaling(){
|
|||||||
|
|
||||||
void PylonRecorder::quitApplication() {
|
void PylonRecorder::quitApplication() {
|
||||||
std::cerr << "Quit Application!" << std::endl;
|
std::cerr << "Quit Application!" << std::endl;
|
||||||
if (pyloncam->isOpen()) {
|
// if (pyloncam->isOpen()) {
|
||||||
std::cerr << "Cam is open!" << std::endl;
|
// std::cerr << "Cam is open!" << std::endl;
|
||||||
|
std::cerr << "Stop grabbing" << std::endl;
|
||||||
|
|
||||||
if (grabbing) {
|
if (grabbing) {
|
||||||
stopRecording();
|
stopRecording();
|
||||||
buffer->clear();
|
|
||||||
}
|
|
||||||
pyloncam->closeCamera();
|
|
||||||
}
|
}
|
||||||
|
std::cerr << "done!" << std::endl;
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,10 +600,16 @@ void PylonRecorder::adjustScrollBar(QScrollBar *scrollBar, double factor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PylonRecorder::cameraConfiguration(){
|
void PylonRecorder::cameraConfiguration(){
|
||||||
CamConfigurator d(this);
|
d = new CamConfigurator(deviceList, this);
|
||||||
// QObject::connect(&d, SIGNAL(recent_file_changed(QStringList)), this, SLOT(recent_file_update(QStringList)));
|
connect(d, SIGNAL(accepted()), SLOT(camerasetup()));
|
||||||
// QObject::connect(&d, SIGNAL(column_visibility_changed(QString, QString,bool)), this, SLOT(visible_columns_update(QString, QString,bool)));
|
// QObject::connect(&d, SIGNAL(column_visibility_changed(QString, QString,bool)), this, SLOT(visible_columns_update(QString, QString,bool)));
|
||||||
d.exec();
|
d->exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PylonRecorder::camerasetup() {
|
||||||
|
std::cerr << "camera settings accepted" << std::endl;
|
||||||
|
std::cerr << d->result() << std::endl;
|
||||||
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PylonRecorder::connectCamera() {
|
void PylonRecorder::connectCamera() {
|
||||||
@ -695,22 +700,37 @@ void PylonRecorder::startRecording() {
|
|||||||
|
|
||||||
|
|
||||||
void PylonRecorder::stopRecording() {
|
void PylonRecorder::stopRecording() {
|
||||||
|
std::cerr << "StopRecording!" << std::endl;
|
||||||
|
|
||||||
if (!stopRequest) {
|
if (!stopRequest) {
|
||||||
|
std::cerr << "StopRecording2!" << std::endl;
|
||||||
|
|
||||||
frameTimer->stop();
|
frameTimer->stop();
|
||||||
|
std::cerr << "StopRecording3!" << std::endl;
|
||||||
|
if (grabber !=nullptr)
|
||||||
grabber->requestStop();
|
grabber->requestStop();
|
||||||
|
std::cerr << "StopRecording4!" << std::endl;
|
||||||
|
if (writer != nullptr)
|
||||||
writer->requestStop();
|
writer->requestStop();
|
||||||
|
std::cerr << "StopRecording5!" << std::endl;
|
||||||
grabbing = false;
|
grabbing = false;
|
||||||
stopRequest = true;
|
stopRequest = true;
|
||||||
grab_stop_action->setEnabled(false);
|
grab_stop_action->setEnabled(false);
|
||||||
if(dryRun) {
|
std::cerr << "stop recording buffer" << buffer << std::endl;
|
||||||
|
if(buffer != nullptr) {
|
||||||
|
std::cerr << "stop recording buffer" << buffer << std::endl;
|
||||||
buffer->clear();
|
buffer->clear();
|
||||||
writerDone();
|
writerDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::cerr << "StopRecording done!" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PylonRecorder::writerDone() {
|
void PylonRecorder::writerDone() {
|
||||||
|
std::cerr << "writerDone slot!" << std::endl;
|
||||||
|
|
||||||
preassureTimer->stop();
|
preassureTimer->stop();
|
||||||
preassureBar->reset();
|
preassureBar->reset();
|
||||||
loadBar->reset();
|
loadBar->reset();
|
||||||
@ -721,6 +741,8 @@ void PylonRecorder::writerDone() {
|
|||||||
writer->wait(10000);
|
writer->wait(10000);
|
||||||
writing = false;
|
writing = false;
|
||||||
updateActions();
|
updateActions();
|
||||||
|
std::cerr << "writerDone slot done!" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -770,7 +792,7 @@ std::string PylonRecorder::createFilename() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PylonRecorder::displayBufferPreassure() {
|
void PylonRecorder::displayBufferPressure() {
|
||||||
int value = static_cast<int>(round(buffer->bufferPreassure()));
|
int value = static_cast<int>(round(buffer->bufferPreassure()));
|
||||||
preassureBar->setValue(value);
|
preassureBar->setValue(value);
|
||||||
QColor color = progressColor(value);
|
QColor color = progressColor(value);
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "grabber.h"
|
#include "grabber.h"
|
||||||
#include "writer.h"
|
#include "writer.h"
|
||||||
#include "projectsettings.h"
|
#include "projectsettings.h"
|
||||||
|
#include "camconfig.h"
|
||||||
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#if defined(QT_PRINTSUPPORT_LIB)
|
#if defined(QT_PRINTSUPPORT_LIB)
|
||||||
@ -60,10 +61,11 @@ private slots:
|
|||||||
void stopRecording();
|
void stopRecording();
|
||||||
void quitApplication();
|
void quitApplication();
|
||||||
void displaySingleFrame();
|
void displaySingleFrame();
|
||||||
void displayBufferPreassure();
|
void displayBufferPressure();
|
||||||
void displayActivity();
|
void displayActivity();
|
||||||
void writerDone();
|
void writerDone();
|
||||||
void selectStorageLocation();
|
void selectStorageLocation();
|
||||||
|
void camerasetup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createActions();
|
void createActions();
|
||||||
@ -110,6 +112,9 @@ private:
|
|||||||
QString storageLocation = "";
|
QString storageLocation = "";
|
||||||
ProjectMetadata mdata;
|
ProjectMetadata mdata;
|
||||||
Pylon::DeviceInfoList_t deviceList;
|
Pylon::DeviceInfoList_t deviceList;
|
||||||
|
CamConfigurator *d;
|
||||||
|
Pylon::PylonAutoInitTerm autoInitTerm;
|
||||||
|
|
||||||
|
|
||||||
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
|
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
|
||||||
QPrinter printer;
|
QPrinter printer;
|
||||||
|
@ -1,20 +1,34 @@
|
|||||||
#include "pylonwrapper.h"
|
#include "pylonwrapper.h"
|
||||||
|
|
||||||
PylonWrapper::PylonWrapper(const std::string &fullName):
|
PylonWrapper::PylonWrapper(const std::string &fullName):
|
||||||
valid(false), fullName(fullName) {
|
valid(false), fullName(fullName), camera(nullptr) {
|
||||||
Pylon::PylonInitialize();
|
Pylon::PylonInitialize();
|
||||||
camera = new Pylon::CInstantCamera();
|
// camera = new Pylon::CInstantCamera();
|
||||||
// std::cerr << "Wrapper:camera is open" << camera->IsOpen() << std::endl;
|
// std::cerr << "Wrapper:camera is open" << camera->IsOpen() << std::endl;
|
||||||
// std::cerr << "Wrapper:is valid" << valid << std::endl;
|
// std::cerr << "Wrapper:is valid" << valid << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
PylonWrapper::~PylonWrapper() {
|
PylonWrapper::~PylonWrapper() {
|
||||||
Pylon::PylonTerminate();
|
std::cerr << "wrapper destructor" << std::endl;
|
||||||
|
if (camera != nullptr){
|
||||||
|
std::cerr << "check camera!" << std::endl;
|
||||||
|
if (camera->IsOpen()) {
|
||||||
|
std::cerr << "close camera!" << std::endl;
|
||||||
|
camera->Close();
|
||||||
|
// std::cerr << "terminate pylon" << std::endl;
|
||||||
|
// terminate();
|
||||||
|
}
|
||||||
|
std::cerr << "delete camera!" << std::endl;
|
||||||
|
|
||||||
|
delete camera;
|
||||||
|
camera = nullptr;
|
||||||
|
}
|
||||||
|
std::cerr << "wrapper: deleted camera" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PylonWrapper::terminate() {
|
void PylonWrapper::terminate() {
|
||||||
try {
|
try {
|
||||||
//Pylon::PylonTerminate();
|
Pylon::PylonTerminate();
|
||||||
} catch (const Pylon::GenericException &e) {
|
} catch (const Pylon::GenericException &e) {
|
||||||
std::cerr << e.GetDescription() << std::endl;
|
std::cerr << e.GetDescription() << std::endl;
|
||||||
}
|
}
|
||||||
@ -136,15 +150,17 @@ bool PylonWrapper::grabFrame(MyImage &img) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool PylonWrapper::openCamera(std::string &message) {
|
bool PylonWrapper::openCamera(std::string &message) {
|
||||||
std::cerr << "open Camera" << std::endl;
|
|
||||||
try {
|
try {
|
||||||
|
camera = new Pylon::CInstantCamera();
|
||||||
|
|
||||||
// Pylon::CInstantCamera camera( pTl->CreateDevice( lstDevices[0] );
|
// Pylon::CInstantCamera camera( pTl->CreateDevice( lstDevices[0] );
|
||||||
camera->Attach(Pylon::CTlFactory::GetInstance().CreateFirstDevice());
|
// Pylon::IPylonDevice *pDevice = Pylon::CTlFactory::GetInstance().CreateFirstDevice();
|
||||||
|
Pylon::String_t fname(fullName.c_str());
|
||||||
|
Pylon::IPylonDevice *pDevice = Pylon::CTlFactory::GetInstance().CreateDevice(fname);
|
||||||
|
camera->Attach(pDevice);
|
||||||
camera->Open();
|
camera->Open();
|
||||||
valid = camera->IsOpen();
|
valid = camera->IsOpen();
|
||||||
message = "Successfully opened camera!";
|
message = "Successfully opened camera!";
|
||||||
std::cerr << message << std::endl;
|
|
||||||
|
|
||||||
} catch (const Pylon::GenericException &e) {
|
} catch (const Pylon::GenericException &e) {
|
||||||
message = e.GetDescription();
|
message = e.GetDescription();
|
||||||
std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
||||||
@ -159,6 +175,8 @@ void PylonWrapper::closeCamera() {
|
|||||||
try {
|
try {
|
||||||
camera->Close();
|
camera->Close();
|
||||||
valid = false;
|
valid = false;
|
||||||
|
delete camera;
|
||||||
|
camera = nullptr;
|
||||||
} catch (const Pylon::GenericException &e) {
|
} catch (const Pylon::GenericException &e) {
|
||||||
std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user