a bit of cleanup and x,y offset to VideoSpecs

This commit is contained in:
Jan Grewe 2024-03-08 09:13:48 +01:00
parent 29abd710e9
commit 47ea6fb27e
4 changed files with 61 additions and 22 deletions

View File

@ -8,20 +8,14 @@ ImageBuffer::ImageBuffer(size_t buffer_size, QObject *parent) : QObject(parent),
}
void ImageBuffer::clear() {
std::cerr << "Clear Image buffer!" << std::endl;
// std::cerr << "Clear Image buffer!" << std::endl;
for (auto & img: buffer) {
std::cerr << "Clear Image buffer!" << std::endl;
if (img != nullptr)
delete(img);
img = nullptr;
}
std::cerr << "Clear Image buffer!" << std::endl;
resize(buffer_size);
std::cerr << "Clear Image buffer! done" << std::endl;
}
size_t ImageBuffer::capacity() {

View File

@ -32,9 +32,8 @@
#endif
PylonRecorder::PylonRecorder(QWidget *parent)
: QMainWindow(parent), imageLabel(new QLabel), scrollArea(new QScrollArea), grabber(nullptr), writer(nullptr), buffer(nullptr), pyloncam(nullptr)
: QMainWindow(parent), imageLabel(new QLabel), scrollArea(new QScrollArea), grabber(nullptr), writer(nullptr), buffer(nullptr), pyloncam(nullptr), dryRun(false), cameraOpened(false)
{
dryRun = false;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
@ -562,7 +561,7 @@ void PylonRecorder::updateActions() {
disconnect_camera_action->setEnabled(deviceList.size() > 0);
connect_camera_action->setEnabled(true);
grab_still_action->setEnabled(deviceList.size() > 0);
//grab_continuous_action->setEnabled(deviceList.size() > 0 && pyloncam->isOpen() && !grabbing);
grab_continuous_action->setEnabled(cameraOpened && !grabbing);
grab_stop_action->setEnabled(grabbing);
}
@ -612,13 +611,14 @@ void PylonRecorder::cameraConfiguration(){
}
void PylonRecorder::camerasetup() {
qDebug() << "Cameras setting " << ((d->result()) ? "Accepted" : "Dicarded");
qDebug() << "Cameras setting " << ((d->result()) ? "Accepted" : "Discarded");
this->layout = d->layout();
delete d;
}
void PylonRecorder::connectCamera() {
this->layout = CameraLayout();
std::cerr << this->layout.rois.size() << " " << this->layout.devices.size() << std::endl;
qDebug() << "connecting camera(s)";
if (deviceList.size() == 0) {
detectCameras();
@ -638,11 +638,13 @@ void PylonRecorder::connectCamera() {
if (success) {
cameraConnectedLabel->setText("connected");
cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: green;}");
cameraOpened = true;
} else {
QMessageBox msgBox;
QString msg = "<p><b>Could not open camera device!</b><p><p>" + QString::fromStdString(message) + "</p>";
msgBox.setText(msg);
msgBox.exec();
cameraOpened = false;
}
statusBar()->showMessage(QString::fromStdString(message));
updateActions();
@ -664,32 +666,73 @@ void PylonRecorder::disconnectCamera() {
qDebug() << "disconnecting cameras done";
}
VideoSpecs PylonRecorder::getVideoSpecs(const ImageSettings &settings) {
VideoSpecs s = VideoSpecs();
if (this->layout.mode == CameraMode::single && this->layout.devices.size() > 0) {
s.fps = framerateSpinner->value();
s.exposureTime = static_cast<double>(exposureSpinner->value());
s.detectorGain = static_cast<double>(gainSpinner->value());
s.width = static_cast<uint32_t>(this->layout.rois[0].width);
s.height = static_cast<uint32_t>(this->layout.rois[0].height);
s.xoffset = static_cast<uint32_t>(this->layout.rois[0].x);
s.yoffset = static_cast<uint32_t>(this->layout.rois[0].y);
s.pixelType = settings.pixelType;
s.orientation = settings.orientation;
s.quality = 95;
} else {
qWarning() << "Dual camera mode not supported yet!";
}
return s;
}
void PylonRecorder::startRecording() {
qDebug() << "start recording!";
std::string filename = createFilename();
fileLabel->setText(QString::fromStdString(filename));
qDebug() << "storing to file " << filename.c_str();
ImageSettings settings = pyloncam->getImageSettings();
qDebug() << "got image settings";
VideoSpecs specs;
specs.fps = framerateSpinner->value();
VideoSpecs specs = getVideoSpecs(settings);
specs.filename = filename;
specs.exposureTime = static_cast<double>(exposureSpinner->value());
specs.detectorGain = static_cast<double>(gainSpinner->value());
specs.width = static_cast<uint32_t>(settings.width);
specs.height= static_cast<uint32_t>(settings.height);
specs.pixelType = settings.pixelType;
specs.orientation = settings.orientation;
specs.quality = 95;
qDebug() << "got video specifications";
if (buffer != nullptr) {
buffer->clear();
delete buffer;
buffer = nullptr;
}
qDebug() << "setting image buffer to size " << buffersizeSpinner->value();
buffer = new ImageBuffer(defaultBufferSize);
if (buffersizeSpinner->value() != static_cast<int>(buffer->capacity())) {
buffer->resize(static_cast<size_t>(buffersizeSpinner->value()));
loadBar->setRange(0, buffersizeSpinner->value());
}
qDebug() << "setting up grabber";
if (grabber != nullptr) {
delete grabber;
grabber = nullptr;
}
grabber = new Grabber(pyloncam, buffer, defaultFrameRate);
if (framerateSpinner->value() != grabber->currentFramerate())
grabber->setFrameRate(framerateSpinner->value());
if (exposureSpinner->value() != int(grabber->currentExposureTime()))
grabber->setExposureTime(static_cast<double>(exposureSpinner->value()));
if (gainSpinner->value() != int(grabber->currentGain()))
grabber->setGain(static_cast<double>(gainSpinner->value()));
qDebug() << "setup writer";
if (writer != nullptr) {
delete writer;
writer = nullptr;
}
writer = new Writer(buffer);
connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone);
writer->setVideoSpecs(specs);
QSettings s;
this->mdata.read(s);

View File

@ -80,6 +80,7 @@ private:
QColor progressColor(int value);
std::string createFilename();
void cameraConfiguration();
VideoSpecs getVideoSpecs(const ImageSettings &settings);
bool saveFile(const QString &fileName);
void setImage(const QImage &newImage);
@ -103,7 +104,7 @@ private:
Grabber *grabber;
Writer *writer;
CameraLayout layout;
bool grabbing, stopRequest, writing, labelSwitch, dryRun;
bool grabbing, stopRequest, writing, labelSwitch, dryRun, cameraOpened;
QPalette progressPalette;
QString activeLabelStyleHigh = "QLabel { font-size: 10pt;font-family: Arial; color : red; }";
QString activeLabelStyleLow = "QLabel { font-size: 10pt;font-family: Arial; color : cmyk(0, 255, 255, 0, 50); }";

View File

@ -13,7 +13,8 @@
struct VideoSpecs {
std::string filename;
uint32_t width, height, quality = 10 ;
uint32_t width, height, quality = 10;
uint32_t xoffset, yoffset = 0;
int fps;
double exposureTime;
double detectorGain;