Compare commits

...

11 Commits

18 changed files with 286 additions and 109 deletions

View File

@@ -43,10 +43,10 @@ include_directories (AFTER ${NIX_INCLUDE_DIR})
# #######################################
# OPENCV
message ("=> finding opencv ...")
find_package(OpenCV REQUIRED opencv_highgui opencv_core)
include_directories(AFTER ${OpenCV_INCLUDE_DIRS} )
set(LINK_LIBS ${LINK_LIBS} ${OpenCV_LIBRARIES})
# message ("=> finding opencv ...")
# find_package(OpenCV REQUIRED opencv_highgui opencv_core)
# include_directories(AFTER ${OpenCV_INCLUDE_DIRS} )
# set(LINK_LIBS ${LINK_LIBS} ${OpenCV_LIBRARIES})
#######################################
# Pylon
@@ -58,5 +58,5 @@ file (GLOB RECORDER_SOURCES *.cpp)
file (GLOB RECORDER_INCLUDES *.hpp)
add_executable ( recorder ${RECORDER_SOURCES} ${RECORDER_INCLUDES} ${RECORDER_RES_SOURCES} )
target_include_directories ( recorder PUBLIC "${PROJECT_BINARY_DIR}" )
target_link_libraries ( recorder Qt5::PrintSupport Qt5::Core Qt5::Widgets Qt5::Gui ${NIX_LIBRARIES} pylon::pylon ${OpenCV_LIBRARIES})
target_link_libraries ( recorder Qt5::PrintSupport Qt5::Core Qt5::Widgets Qt5::Gui ${NIX_LIBRARIES} pylon::pylon)
# ${PYLON_LIBRARIES} ${OpenCV_LIBRARIES})

View File

@@ -86,6 +86,7 @@ void CamConfigurator::modeChanged(int idx) {
stack->setCurrentIndex(1);
QString device = device_combo->currentText();
preview->setPrimaryCamera(device);
mode_combo->setEnabled(false);
} else if (idx == 2) {
qDebug() << "Mode changed to dual camera mode";
preview = stereoCameraView();
@@ -100,6 +101,7 @@ void CamConfigurator::modeChanged(int idx) {
}
QString device2 = device_combo->itemText(1 - i);
preview->setSecondaryCamera(device2);
mode_combo->setEnabled(false);
} else {
qDebug() << "Mode changed mode selection";
stack->setCurrentIndex(0);

View File

@@ -60,13 +60,12 @@ CameraPreview::CameraPreview(QWidget *parent):cameraname(""), camera(nullptr), Q
void CameraPreview::setCamera(QString &device){
qDebug() << "update camera! ";// << device.toStdString();
cameraname = device;
label->setText(device);
if (camera != NULL) {
if (camera != nullptr) {
qDebug() << "camera is not nullptr! ";
delete camera;
camera = nullptr;
}
camera = new PylonWrapper(cameraname.toStdString());
camera = new SingleCamWrapper(cameraname.toStdString());
std::string message;
bool success = camera->openCamera(message);
if (!success) {
@@ -76,7 +75,9 @@ void CameraPreview::setCamera(QString &device){
QString msg = "<p><b>Could not open camera device!</b><p><p>" + QString::fromStdString(message) + "</p>";
msgBox.setText(msg);
msgBox.exec();
return;
}
label->setText(device + " - " + camera->userName());
takeStill();
}

View File

@@ -12,7 +12,7 @@
#include <QPainter>
#include <pylon/PylonIncludes.h>
#include "pylonwrapper.h"
#include "singlecamwrapper.h"
#include "util.h"
namespace Ui {
class CameraPreview;
@@ -53,7 +53,7 @@ private:
void setImage(const QPixmap &img);
void validate(QSpinBox *origin, QSpinBox *dest, int limit);
PylonWrapper *camera;
SingleCamWrapper *camera;
};

48
camids.cpp Normal file
View File

@@ -0,0 +1,48 @@
#include "camids.h"
#include "mylogger.h"
#include "util.h"
CameraID::CameraID(Pylon::DeviceInfoList &deviceList, QWidget *parent) :
deviceList(deviceList), QDialog(parent) {
device_combo = new QComboBox(this);
for (auto d : deviceList) {
device_combo->addItem(QString(d.GetFullName()) + " - " + QString(d.GetUserDefinedName()));
}
connect(device_combo, SIGNAL(currentIndexChanged(int)), SLOT(primaryDeviceChanged(int)));
QWidget *header = new QWidget(this);
QGridLayout *grid = new QGridLayout(header);
grid->addWidget(new QLabel("Camera device:", this), 1, 0);
grid->addWidget(device_combo, 1, 1);
edit = new QLineEdit(this);
grid->addWidget(new QLabel("Camera Id", this), 2, 0);
grid->addWidget(edit, 2, 1);
header->setLayout(grid);
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->addWidget(header);
buttonbox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
connect(buttonbox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonbox, &QDialogButtonBox::rejected, this, &QDialog::reject);
vbox->addWidget(buttonbox);
std::cerr <<"ping\n";
}
void CameraID::setID() {
std::cerr << "Set ID!" << std::endl;
}
QString CameraID::newID() {
std::cerr <<"ping\n";
return edit->text();
}
int CameraID::cameraIndex() {
std::cerr <<"ping\n";
return device_combo->currentIndex();
}

45
camids.h Normal file
View File

@@ -0,0 +1,45 @@
#ifndef CAMIDS_H
#define CAMIDS_H
#include <QDialog>
#include <QComboBox>
#include <QLabel>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QLineEdit>
#include <QDialogButtonBox>
#include <pylon/PylonIncludes.h>
#include "mylogger.h"
namespace Ui {
class CameraID;
}
class CameraID : public QDialog
{
Q_OBJECT
public:
explicit CameraID(Pylon::DeviceInfoList_t &deviceList, QWidget *parent = 0);
// ~CameraID(){};
QString newID();
int cameraIndex();
public slots:
void setID();
// signals:
// void column_visibility_changed(QString who, QString column, bool state);
// void recent_file_changed(QStringList);
private:
Pylon::DeviceInfoList_t deviceList;
QComboBox *device_combo;
QLineEdit *edit;
QDialogButtonBox *buttonbox;
};
#endif // CAMIDS_H

View File

@@ -2,6 +2,11 @@
#include <iostream>
#include <pylon/PylonIncludes.h>
#include <stitchimage.h>
#include <chrono>
using namespace std::chrono;
typedef high_resolution_clock Time;
typedef milliseconds ms;
typedef duration<float> fsec;
void DualcamGrabber::run() {
stop_request = false;
@@ -9,9 +14,10 @@ void DualcamGrabber::run() {
if (wrapper->isOpen()) {
Pylon::CInstantCameraArray &cameras = wrapper->getCameraArray();
wrapper->frameRate(static_cast<uint>(framerate));
wrapper->frameRate(static_cast<uint>(framerate), -1);
wrapper->exposureTime(exposure);
wrapper->gain(gain);
cameras.StartGrabbing();
Pylon::CGrabResultPtr frame0, frame1;
Pylon::CPylonImage leftImage;
@@ -19,14 +25,27 @@ void DualcamGrabber::run() {
Pylon::CPylonImage stitchedImage;
std::string errorMessage = "";
// int ifi = 0;
// int deviation = 0;
// std::cerr << wrapper->frameRate(0) << "\t" << wrapper->frameRate(1) << "\t" << framerate << std::endl;
// int desired_ifi = (1./wrapper->frameRate(0) * 1000000);
// auto framestart = high_resolution_clock::now();
while (cameras.IsGrabbing() && !stop_request) {
// if (counter > 0) {
// deviation = desired_ifi - ifi;
// if (deviation > 0)
// // usleep(deviation);
// std::cerr << desired_ifi << "\t" << deviation << std::endl;
// }
// auto start = high_resolution_clock::now();
MyImage *img = new MyImage();
// auto stop1 = high_resolution_clock::now();
cameras[0].RetrieveResult( 5000, frame0, Pylon::TimeoutHandling_ThrowException );
// auto stop2 = high_resolution_clock::now();
cameras[1].RetrieveResult( 5000, frame1, Pylon::TimeoutHandling_ThrowException );
// auto stop3 = high_resolution_clock::now();
leftImage.AttachGrabResultBuffer( frame0 );
rightImage.AttachGrabResultBuffer( frame1 );
if (leftImage.IsValid() && rightImage.IsValid()) {
try {
StitchImage::StitchToRight(leftImage, rightImage, &stitchedImage, errorMessage);
@@ -36,6 +55,17 @@ void DualcamGrabber::run() {
std::cerr << e.what() << '\n';
}
}
// auto stop4 = high_resolution_clock::now();
// auto duration1 = duration_cast<microseconds>(stop1 - start);
// auto duration2 = duration_cast<microseconds>(stop2 - stop1);
// auto duration3 = duration_cast<microseconds>(stop3 - stop2);
// auto duration4 = duration_cast<microseconds>(stop4 - stop3);
// std::cerr << "framecount: " << counter << " image constr: " << duration1.count() << "\t" << " retrieve1: " << duration2.count() << "\t" << " retrieve2: " << duration3.count() << "\t" << "conversion: " << duration4.count() << std::endl;
// ifi = duration_cast<microseconds>(stop4 - framestart).count();
// framestart = stop4;
// if (counter > 0) {
// std::cerr << "frame " << counter << " inter frame interval: " << ifi << "microseconds" << std::endl;
// }
counter += 1;
}
cameras.StopGrabbing();

View File

@@ -54,8 +54,8 @@ bool DualcamWrapper::frameRate(uint new_framerate, int camindex) {
frameRate(new_framerate, 0);
frameRate(new_framerate, 1);
return true;
} else if (camindex == 0 && camindex ==1) {
GenApi::INodeMap& nodemap = getNodemap(0);
} else if (camindex >= 0 && camindex < 2) {
GenApi::INodeMap& nodemap = getNodemap(camindex);
GenApi::INode* n = nodemap.GetNode( "AcquisitionFrameRateEnable" );
Pylon::CBooleanParameter enableframerate(n);
enableframerate.SetValue(true);
@@ -72,7 +72,7 @@ bool DualcamWrapper::frameRate(uint new_framerate, int camindex) {
double DualcamWrapper::frameRate(int camindex) {
assert(camindex > 0 && camindex < 2);
assert(camindex >= 0 && camindex < 2);
double rate = -1.;
if (valid) {
GenApi::INodeMap& nodemap = getNodemap(camindex);
@@ -173,14 +173,14 @@ bool DualcamWrapper::grabFrame(MyImage &img, int camindex) {
qDebug() << "grabFrame from camera " << camindex;
if (valid) {
GenApi::INodeMap &nodemap = getNodemap(camindex);
qDebug() << "Setting width" << layout.rois[0].width;
Pylon::CIntegerParameter(nodemap, "Width").SetValue(layout.rois[0].width);
qDebug() << "Setting width" << layout.rois[camindex].width;
Pylon::CIntegerParameter(nodemap, "Width").SetValue(layout.rois[camindex].width);
qDebug() << "Setting height" << layout.rois[0].height;
Pylon::CIntegerParameter(nodemap, "Height").SetValue(layout.rois[0].height);
qDebug() << "Setting xoffset" << layout.rois[0].x;
Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(layout.rois[0].x);
qDebug() << "Setting yoffset" << layout.rois[0].y;
Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(layout.rois[0].y);
Pylon::CIntegerParameter(nodemap, "Height").SetValue(layout.rois[camindex].height);
qDebug() << "Setting xoffset" << layout.rois[camindex].x;
Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(layout.rois[camindex].x);
qDebug() << "Setting yoffset" << layout.rois[camindex].y;
Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(layout.rois[camindex].y);
camera->StartGrabbing();
camera->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
@@ -191,15 +191,25 @@ bool DualcamWrapper::grabFrame(MyImage &img, int camindex) {
}
void DualcamWrapper::setROI() {
for (int camindex = 0; camindex < 2; camindex++){
qDebug() << "Setting ROI: w" << layout.rois[camindex].width << " h: "<< layout.rois[camindex].height << " x " << layout.rois[camindex].x << " y " << layout.rois[camindex].y;
GenApi::INodeMap &nodemap = getNodemap(camindex);
Pylon::CIntegerParameter(nodemap, "Width").SetValue(layout.rois[camindex].width);
Pylon::CIntegerParameter(nodemap, "Height").SetValue(layout.rois[camindex].height);
Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(layout.rois[camindex].x);
Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(layout.rois[camindex].y);
}
}
void DualcamWrapper::resetCamera(int camindex) {
GenApi::INodeMap &nodemap = getNodemap( camindex );
int64_t dfltWidth = 2048;
int64_t dfltHeight = 1536;
qDebug() << "resetting camera to default ROI (" << dfltWidth << ", " << dfltHeight << ")";
try {
// std::cerr << "MaxWidth: " << Pylon::CIntegerParameter(nodemap, "WidthMax").GetValue() << std::endl;
Pylon::CIntegerParameter(nodemap, "Width").SetValue(dfltWidth, false);
// std::cerr << "MaxHeight: " << Pylon::CIntegerParameter(nodemap, "HeightMax").GetValue() << std::endl;
Pylon::CIntegerParameter(nodemap, "Height").SetValue(dfltHeight, false);
Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(0);
Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(0);
@@ -229,8 +239,9 @@ bool DualcamWrapper::openCameras(std::string &message) {
valid = false;
return valid;
}
resetCamera(0);
resetCamera(1);
// resetCamera(0);
// resetCamera(1);
setROI();
return valid;
}

View File

@@ -15,7 +15,6 @@ public:
DualcamWrapper(const CameraLayout &layout);
~DualcamWrapper();
ImageSettings getImageSettings(int camindex);
bool isOpen();
void terminate();
@@ -35,6 +34,7 @@ private:
void resetCamera(int camindex);
Pylon::CInstantCameraArray cameras;
GenApi::INodeMap& getNodemap(int camindex);
void setROI();
bool valid, withLayout;
CameraLayout layout;

View File

@@ -27,6 +27,8 @@ bool MyImage::setFrame( Pylon::CPylonImage &img) {
img_width = img.GetWidth();
img_height = img.GetHeight();
memcpy(&buffer, img.GetBuffer(), img.GetImageSize());
auto t = std::chrono::system_clock::now();
img_timestamp = std::chrono::system_clock::to_time_t(t);
}
return valid;
}

View File

@@ -61,8 +61,8 @@ PylonRecorder::PylonRecorder(QWidget *parent)
QPalette progressPalette = pressureBar->palette();
progressPalette.setBrush(QPalette::Highlight, QBrush(color));
pressureBar->setPalette(progressPalette);
QLabel *preassureLabel = new QLabel("Buffer preassure:", this);
preassureLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;font-weight: Bold}");
QLabel *pressureLabel = new QLabel("Buffer pressure:", this);
pressureLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;font-weight: Bold}");
loadBar = new QProgressBar(this);
loadBar->setRange(0, defaultBufferSize);
loadBar->setFixedSize(200, 25);
@@ -89,7 +89,7 @@ PylonRecorder::PylonRecorder(QWidget *parent)
fileHeader->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial; font-weight: Bold}");
statusBar()->addWidget(camHeader);
statusBar()->addWidget(cameraConnectedLabel);
statusBar()->addWidget(preassureLabel);
statusBar()->addWidget(pressureLabel);
statusBar()->addWidget(pressureBar);
statusBar()->addWidget(loadLabel);
statusBar()->addWidget(loadBar);
@@ -280,8 +280,8 @@ void PylonRecorder::saveAs() {
void PylonRecorder::print() {
QPixmap map = imageLabel->pixmap(Qt::ReturnByValue);
Q_ASSERT(!map.isNull());
const QPixmap *map = imageLabel->pixmap();
Q_ASSERT(!map->isNull());
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
QPrintDialog dialog(&printer, this);
@@ -289,11 +289,11 @@ void PylonRecorder::print() {
if (dialog.exec()) {
QPainter painter(&printer);
QRect rect = painter.viewport();
QSize size = map.size();
QSize size = map->size();
size.scale(rect.size(), Qt::KeepAspectRatio);
painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
painter.setWindow(map.rect());
painter.drawPixmap(0, 0, map);
painter.setWindow(map->rect());
painter.drawPixmap(0, 0, *map);
}
#endif
}
@@ -434,6 +434,7 @@ void PylonRecorder::createActions() {
connect_camera_action->setStatusTip(tr("Connect to to camera and open device"));
disconnect_camera_action = camera_menu->addAction(disconnect_icon, tr("&disconnect"), this, &PylonRecorder::disconnectCamera);
disconnect_camera_action->setStatusTip(tr("Disconnect from the camera device"));
disconnect_camera_action->setEnabled(false);
camera_menu->addSeparator();
grab_still_action = camera_menu->addAction(snapshot_icon, tr("&grab still"), this, &PylonRecorder::grabStillFromPylon);
grab_still_action->setStatusTip(tr("Grab single image from Pylon camera"));
@@ -442,6 +443,9 @@ void PylonRecorder::createActions() {
grab_continuous_action->setShortcut(tr("Ctrl+Enter"));
grab_stop_action = camera_menu->addAction(stop_icon, tr("&stop grabbing"), this, &PylonRecorder::stopRecording);
grab_stop_action->setShortcut(tr("Ctrl+Shift+Enter"));
set_cam_identifier_action = camera_menu->addAction(tr("set identifier"), this, &PylonRecorder::setCameraIDs);
set_cam_identifier_action->setStatusTip(tr("Set human readable camera identifier or easier recognition."));
set_cam_identifier_action->setToolTip(tr("Set human readable camera identifier or easier recognition."));
selectStorageAction = new QAction(tr("storage location"), this);
selectStorageAction->setStatusTip(tr("Select a storage location for the recorded videos"));
@@ -534,20 +538,42 @@ void PylonRecorder::updateActions() {
zoomInAct->setEnabled(!fitToWindowAct->isChecked());
zoomOutAct->setEnabled(!fitToWindowAct->isChecked());
normalSizeAct->setEnabled(!fitToWindowAct->isChecked());
disconnect_camera_action->setEnabled(deviceList.size() > 0);
disconnect_camera_action->setEnabled(cameraOpened);
connect_camera_action->setEnabled(true);
grab_still_action->setEnabled(deviceList.size() > 0);
grab_still_action->setEnabled(cameraOpened);
grab_continuous_action->setEnabled(cameraOpened && !grabbing);
// grab_continuous_action->setEnabled(!grabbing);
grab_stop_action->setEnabled(grabbing);
set_cam_identifier_action->setEnabled(false);
}
void PylonRecorder::setCameraIDs() {
if (deviceList.size() == 0) {
QMessageBox msgBox;
QString msg = "<p><b>No camera device found!</b></p><br><p>Connect camera and try again!</p>";
msgBox.setText(msg);
msgBox.exec();
qWarning() << msg.toStdString().c_str();
return;
}
cameraIdDialog = new CameraID(deviceList, this);
connect(cameraConfigDialog, SIGNAL(accepted()), SLOT(cameraIDAccepted()));
std::cerr <<"ping\n";
cameraIdDialog->exec();
}
void PylonRecorder::cameraIDAccepted() {
QString newid = cameraIdDialog->newID();
int deviceindex = cameraIdDialog->cameraIndex();
std::cerr << "New camera id " << newid.toStdString() << " index: " << deviceindex << std::endl;
delete(cameraIdDialog);
}
void PylonRecorder::scaleImage(double factor) {
QPixmap map = imageLabel->pixmap(Qt::ReturnByValue);
Q_ASSERT(!map.isNull());
const QPixmap *map = imageLabel->pixmap();
Q_ASSERT(!map->isNull());
scaleFactor *= factor;
imageLabel->resize(scaleFactor * map.size());
imageLabel->resize(scaleFactor * map->size());
adjustScrollBar(scrollArea->horizontalScrollBar(), factor);
adjustScrollBar(scrollArea->verticalScrollBar(), factor);
@@ -558,7 +584,7 @@ void PylonRecorder::scaleImage(double factor) {
void PylonRecorder::applyScaling(){
imageLabel->resize(scaleFactor * imageLabel->pixmap(Qt::ReturnByValue).size());
imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());
}
@@ -582,19 +608,19 @@ void PylonRecorder::adjustScrollBar(QScrollBar *scrollBar, double factor) {
void PylonRecorder::cameraConfiguration(){
d = new CamConfigurator(deviceList, this);
connect(d, SIGNAL(accepted()), SLOT(cameraConfigurationAccepted()));
connect(d, SIGNAL(rejected()), SLOT(cameraConfigurationAborted()));
cameraConfigDialog = new CamConfigurator(deviceList, this);
connect(cameraConfigDialog, SIGNAL(accepted()), SLOT(cameraConfigurationAccepted()));
connect(cameraConfigDialog, SIGNAL(rejected()), SLOT(cameraConfigurationAborted()));
// QObject::connect(&d, SIGNAL(column_visibility_changed(QString, QString,bool)), this, SLOT(visible_columns_update(QString, QString,bool)));
d->exec();
cameraConfigDialog->exec();
}
void PylonRecorder::cameraConfigurationAccepted() {
qDebug() << "Cameras setting " << ((d->result()) ? "Accepted" : "Discarded");
this->layout = d->layout();
qDebug() << "Cameras setting " << ((cameraConfigDialog->result()) ? "Accepted" : "Discarded");
this->layout = cameraConfigDialog->layout();
camsconfigured = true;
delete d;
delete cameraConfigDialog;
}
@@ -626,7 +652,7 @@ void PylonRecorder::connectCamera() {
std::string cname = layout.devices[0];
std::string message;
qDebug() << "connecting to camera " << cname.c_str();
singlecam = new PylonWrapper(layout);
singlecam = new SingleCamWrapper(layout);
bool success = singlecam->openCamera(message);
if (success) {
cameraConnectedLabel->setText("connected");
@@ -736,7 +762,7 @@ void PylonRecorder::startSinglecamRecording() {
delete singlecamgrabber;
singlecamgrabber = nullptr;
}
singlecamgrabber = new Grabber(singlecam, buffer, defaultFrameRate);
singlecamgrabber = new SinglecamGrabber(singlecam, buffer, defaultFrameRate);
if (framerateSpinner->value() != singlecamgrabber->currentFramerate())
singlecamgrabber->setFrameRate(framerateSpinner->value());
@@ -750,8 +776,8 @@ void PylonRecorder::startSinglecamRecording() {
delete writer;
writer = nullptr;
}
writer = new Writer(buffer, 0);
connect(writer, SLOT(writingDone()), this, SLOT(writerDone()));
writer = new Writer(buffer);
connect(writer, SIGNAL(writingDone()), this, SLOT(writerDone()));
writer->setVideoSpecs(specs);
QSettings s;
@@ -781,7 +807,7 @@ void PylonRecorder::startDualcamRecording() {
VideoSpecs specs = getVideoSpecs(settings);
specs.filename = filename;
specs.format = VideoFormat::mp4;
qDebug() << "got video specifications";
qDebug() << "got video specifications " << specs.fps;
if (buffer != nullptr) {
buffer->clear();
delete buffer;
@@ -813,7 +839,7 @@ void PylonRecorder::startDualcamRecording() {
delete writer;
writer = nullptr;
}
writer = new Writer(buffer, 0);
writer = new Writer(buffer);
connect(writer, SIGNAL(writingDone()), this, SLOT(writerDone()));
writer->setVideoSpecs(specs);

View File

@@ -7,15 +7,15 @@
#include <QCheckBox>
#include <QSettings>
#include <pylon/PylonIncludes.h>
#include "pylonwrapper.h"
#include "singlecamwrapper.h"
#include "dualcamwrapper.h"
#include "imagebuffer.h"
#include "grabber.h"
#include "singlecamgrabber.h"
#include "dualcamgrabber.h"
#include "writer.h"
#include "opencvwriter.h"
#include "projectsettings.h"
#include "camconfig.h"
#include "camids.h"
#include "util.h"
#include <QImage>
@@ -71,6 +71,8 @@ private slots:
void selectStorageLocation();
void cameraConfigurationAccepted();
void cameraConfigurationAborted();
void setCameraIDs();
void cameraIDAccepted();
private:
void createActions();
@@ -87,7 +89,6 @@ private:
VideoSpecs getVideoSpecs(const ImageSettings &settings);
void startSinglecamRecording();
void startDualcamRecording();
bool saveFile(const QString &fileName);
void setImage(const QImage &newImage);
void scaleImage(double factor);
@@ -104,10 +105,10 @@ private:
QProgressBar *loadBar;
QScrollArea *scrollArea;
double scaleFactor = 1;
PylonWrapper *singlecam;
SingleCamWrapper *singlecam;
DualcamWrapper *dualcam;
ImageBuffer *buffer;
Grabber *singlecamgrabber;
SinglecamGrabber *singlecamgrabber;
DualcamGrabber *dualcamgrabber;
Writer *writer;
CameraLayout layout;
@@ -122,8 +123,9 @@ private:
QString storageLocation = "";
ProjectMetadata mdata;
Pylon::DeviceInfoList_t deviceList;
CamConfigurator *d;
Pylon::PylonAutoInitTerm autoInitTerm;
CamConfigurator *cameraConfigDialog;
CameraID *cameraIdDialog;
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
@@ -142,6 +144,7 @@ private:
QAction *grab_stop_action;
QAction *connect_camera_action;
QAction *disconnect_camera_action;
QAction *set_cam_identifier_action;
};
#endif

View File

@@ -1,8 +1,8 @@
#include "grabber.h"
#include "singlecamgrabber.h"
#include <iostream>
#include <pylon/PylonIncludes.h>
void Grabber::run() {
void SinglecamGrabber::run() {
stop_request = false;
int count = 0;
if (camera->isOpen()) {

View File

@@ -1,16 +1,16 @@
#ifndef GRABBER_H
#define GRABBER_H
#ifndef SINGLECAMGRABBER_H
#define SINGLECAMGRABBER_H
#include <QObject>
#include <QThread>
#include "pylonwrapper.h"
#include "singlecamwrapper.h"
#include "imagebuffer.h"
class Grabber : public QThread
class SinglecamGrabber : public QThread
{
Q_OBJECT
public:
Grabber(PylonWrapper *camera, ImageBuffer*buffer, int framerate, QObject *parent = nullptr) :
SinglecamGrabber(SingleCamWrapper *camera, ImageBuffer*buffer, int framerate, QObject *parent = nullptr) :
QThread(parent), camera(camera), buffer(buffer), framerate(framerate) {}
void run() override;
@@ -29,7 +29,7 @@ public:
private:
bool stop_request = false;
PylonWrapper *camera;
SingleCamWrapper *camera;
ImageBuffer *buffer;
int framerate;
double exposure, gain;
@@ -51,4 +51,4 @@ signals:
void terminated();
};
#endif // GRABBER_H
#endif // SINGLECAMGRABBER_H

View File

@@ -1,19 +1,19 @@
#include "pylonwrapper.h"
#include "singlecamwrapper.h"
PylonWrapper::PylonWrapper(const std::string &fullName):
SingleCamWrapper::SingleCamWrapper(const std::string &fullName):
valid(false), fullName(fullName), camera(nullptr), withLayout(false) {
qDebug() << "Constructor with name";
Pylon::PylonInitialize();
}
PylonWrapper::PylonWrapper(const CameraLayout &layout): valid(false), withLayout(true), camera(nullptr) {
SingleCamWrapper::SingleCamWrapper(const CameraLayout &layout): valid(false), withLayout(true), camera(nullptr) {
qDebug() << "Constructor with layout";
this->fullName = layout.devices[0];
this->layout = layout;
Pylon::PylonInitialize();
}
PylonWrapper::~PylonWrapper() {
SingleCamWrapper::~SingleCamWrapper() {
qDebug() << "wrapper destructor";
if (camera != nullptr){
if (camera->IsOpen()) {
@@ -27,7 +27,7 @@ PylonWrapper::~PylonWrapper() {
qDebug() << "Successfully deleted camera";
}
void PylonWrapper::terminate() {
void SingleCamWrapper::terminate() {
qDebug() << "Terminate";
try {
Pylon::PylonTerminate();
@@ -36,11 +36,11 @@ void PylonWrapper::terminate() {
}
}
bool PylonWrapper::isOpen() {
bool SingleCamWrapper::isOpen() {
return valid;
}
double PylonWrapper::maxFrameRate() {
double SingleCamWrapper::maxFrameRate() {
double max_rate = -1;
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
@@ -51,7 +51,7 @@ double PylonWrapper::maxFrameRate() {
return max_rate;
}
bool PylonWrapper::frameRate(uint new_framerate) {
bool SingleCamWrapper::frameRate(uint new_framerate) {
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
GenApi::INode* n = nodemap.GetNode( "AcquisitionFrameRateEnable" );
@@ -66,7 +66,7 @@ bool PylonWrapper::frameRate(uint new_framerate) {
return false;
}
double PylonWrapper::frameRate() {
double SingleCamWrapper::frameRate() {
double rate = -1.;
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
@@ -77,7 +77,7 @@ double PylonWrapper::frameRate() {
return rate;
}
double PylonWrapper::exposureTime() {
double SingleCamWrapper::exposureTime() {
double time = -1.;
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
@@ -88,7 +88,7 @@ double PylonWrapper::exposureTime() {
return time;
}
bool PylonWrapper::exposureTime(double exposure_time) {
bool SingleCamWrapper::exposureTime(double exposure_time) {
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
double d = GenApi::CFloatPtr(nodemap.GetNode("ExposureTime"))->GetValue();
@@ -105,7 +105,7 @@ bool PylonWrapper::exposureTime(double exposure_time) {
return false;
}
double PylonWrapper::gain() {
double SingleCamWrapper::gain() {
double gain = -1.;
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
@@ -116,7 +116,7 @@ double PylonWrapper::gain() {
return gain;
}
bool PylonWrapper::gain(double gain_db) {
bool SingleCamWrapper::gain(double gain_db) {
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
GenApi::CFloatPtr(nodemap.GetNode("Gain"))->SetValue(gain_db);
@@ -125,7 +125,7 @@ bool PylonWrapper::gain(double gain_db) {
return false;
}
ImageSettings PylonWrapper::getImageSettings() {
ImageSettings SingleCamWrapper::getImageSettings() {
ImageSettings settings;
if (valid) {
Pylon::CEnumParameter pixelFormat( camera->GetNodeMap(), "PixelFormat" );
@@ -141,7 +141,7 @@ ImageSettings PylonWrapper::getImageSettings() {
return settings;
}
bool PylonWrapper::grabFrame(MyImage &img) {
bool SingleCamWrapper::grabFrame(MyImage &img) {
Pylon::CGrabResultPtr frame;
qDebug() << "grabFrame";
if (valid) {
@@ -162,7 +162,7 @@ bool PylonWrapper::grabFrame(MyImage &img) {
return frame.IsValid();
}
void PylonWrapper::resetCamera() {
void SingleCamWrapper::resetCamera() {
int64_t dfltWidth = 2048;
int64_t dfltHeight = 1536;
qDebug() << "resetting camera to default ROI (" << dfltWidth << ", " << dfltHeight << ")";
@@ -181,7 +181,7 @@ void PylonWrapper::resetCamera() {
}
}
bool PylonWrapper::openCamera(std::string &message) {
bool SingleCamWrapper::openCamera(std::string &message) {
qDebug() << "opening camera";
try {
camera = new Pylon::CInstantCamera();
@@ -215,7 +215,7 @@ bool PylonWrapper::openCamera(std::string &message) {
return valid;
}
void PylonWrapper::closeCamera() {
void SingleCamWrapper::closeCamera() {
qDebug() << "Close camera!";
if (camera->IsOpen()) {
try {
@@ -229,6 +229,12 @@ void PylonWrapper::closeCamera() {
}
}
Pylon::CInstantCamera *PylonWrapper::getCamera() {
Pylon::CInstantCamera *SingleCamWrapper::getCamera() {
return camera;
}
QString SingleCamWrapper::userName() {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
QString username = Pylon::CStringParameter(nodemap, "DeviceUserID").GetValue().c_str();
return username;
}

View File

@@ -1,5 +1,5 @@
#ifndef PYLONWRAPPER_H
#define PYLONWRAPPER_H
#ifndef SINGLECAMWRAPPER_H
#define SINGLECAMWRAPPER_H
#include <pylon/PylonIncludes.h>
#include <pylon/BaslerUniversalInstantCamera.h>
@@ -7,12 +7,12 @@
#include "util.h"
#include "myimage.h"
class PylonWrapper
class SingleCamWrapper
{
public:
PylonWrapper(const std::string &name);
PylonWrapper(const CameraLayout &layout);
~PylonWrapper();
SingleCamWrapper(const std::string &name);
SingleCamWrapper(const CameraLayout &layout);
~SingleCamWrapper();
ImageSettings getImageSettings();
bool isOpen();
@@ -27,6 +27,7 @@ public:
bool exposureTime(double exposure_time);
double gain();
bool gain(double gain_db);
QString userName();
Pylon::CInstantCamera *getCamera();
void resetCamera();
@@ -40,4 +41,4 @@ private:
};
#endif // PYLONWRAPPER_H
#endif // SINGLECAMWRAPPER_H

View File

@@ -1,9 +1,7 @@
#include "writer.h"
#include <chrono>
#include <fstream>
#include <pylon/VideoWriter.h>
using namespace std::chrono;
void Writer::setVideoSpecs(VideoSpecs specs) {
videoSpecs = specs;
@@ -37,7 +35,7 @@ void Writer::run() {
// Releases all pylon resources.
// PylonTerminate();
// Return with error code 1.
emit writingDone(this->cam_number);
emit writingDone();
return;
}
qDebug() << "checks done!";
@@ -114,7 +112,12 @@ void Writer::run() {
}
}
if (count < chunksize) {
try {
stamps_buffer[count] = nix::util::timeToStr(img->timestamp());
} catch (...) {
std::cerr << "Bad time to string conversion " << img->timestamp() << std::endl;
stamps_buffer[count] = "invalid";
}
ids_buffer[count] = img->index();
count ++;
} else {
@@ -138,11 +141,11 @@ void Writer::run() {
frametimes.setData(nix::DataType::String, stamps_buffer.data(), chunk_shape, offset);
frameindices.setData(nix::DataType::Int64, ids_buffer.data(), chunk_shape, offset);
}
// videoWriter.Close();
videoWriter.Close();
myFile.close();
nix_file.close();
} else {
std::cerr << "Got no video specifications, not writing!" << std::endl;
}
emit writingDone(cam_number);
emit writingDone();
}

View File

@@ -6,7 +6,7 @@
#include <pylon/PylonIncludes.h>
#include <nix.hpp>
#include "pylonwrapper.h"
#include "singlecamwrapper.h"
#include "imagebuffer.h"
#include "projectsettings.h"
#include "util.h"
@@ -15,8 +15,8 @@ class Writer : public QThread
{
Q_OBJECT
public:
explicit Writer(ImageBuffer*buffer, int number, QObject *parent = nullptr) :
QThread(parent), buffer(buffer), cam_number(number) {}
explicit Writer(ImageBuffer*buffer, QObject *parent = nullptr) :
QThread(parent), buffer(buffer) {}
void setVideoSpecs(VideoSpecs specs);
void setProjectMetadata(ProjectMetadata mdata);
@@ -25,10 +25,9 @@ public:
signals:
void terminated();
void writingDone(int cam);
void writingDone();
private:
int cam_number;
ImageBuffer *buffer;
VideoSpecs videoSpecs;
ProjectMetadata metadata;