grabbing and display are working again

This commit is contained in:
Jan Grewe 2024-03-08 12:02:27 +01:00
parent 7ad190513a
commit 37db983a2f
5 changed files with 43 additions and 37 deletions

View File

@ -1,4 +1,5 @@
#include "imagebuffer.h" #include "imagebuffer.h"
#include "mylogger.h"
#include <chrono> #include <chrono>
using namespace std::chrono; using namespace std::chrono;
@ -22,12 +23,12 @@ size_t ImageBuffer::capacity() {
return buffer.capacity(); return buffer.capacity();
} }
double ImageBuffer::bufferPreassure() { double ImageBuffer::bufferPressure() {
double preassure; double pressure;
mutex.lock(); mutex.lock();
preassure = static_cast<double>(load)/static_cast<double>(buffer.capacity()); pressure = static_cast<double>(load)/static_cast<double>(buffer.capacity());
mutex.unlock(); mutex.unlock();
return preassure * 100; return pressure * 100;
} }
size_t ImageBuffer::bufferLoad() { size_t ImageBuffer::bufferLoad() {
@ -92,13 +93,14 @@ MyImage* ImageBuffer::pop() {
load -= 1; load -= 1;
} }
mutex.unlock(); mutex.unlock();
// std::cerr << "buffer.pop write: " << current_write_index << " read: " << current_read_index << " load: " << load << std::endl; std::cerr << "buffer.pop write: " << current_write_index << " read: " << current_read_index << " load: " << load << std::endl;
return img; return img;
} }
MyImage* ImageBuffer::readLast() { MyImage* ImageBuffer::readLast() {
MyImage *img; MyImage *img;
img = nullptr;
mutex.lock(); mutex.lock();
if (load > 0) { if (load > 0) {
size_t idx = current_write_index - 1; size_t idx = current_write_index - 1;
@ -107,6 +109,7 @@ MyImage* ImageBuffer::readLast() {
std::cerr << "Bank" << std::endl; std::cerr << "Bank" << std::endl;
idx = buffer_size - 1; idx = buffer_size - 1;
} }
std::cerr << "read form index " << idx << std::endl;
img = buffer[idx]; img = buffer[idx];
} }
mutex.unlock(); mutex.unlock();

View File

@ -20,7 +20,7 @@ public:
MyImage* pop(); MyImage* pop();
MyImage* readLast(); MyImage* readLast();
size_t capacity(); size_t capacity();
double bufferPreassure(); double bufferPressure();
size_t bufferLoad(); size_t bufferLoad();
bool bufferNotEmpty(); bool bufferNotEmpty();

View File

@ -62,18 +62,18 @@ PylonRecorder::PylonRecorder(QWidget *parent)
// } // }
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); pressureTimer = new QTimer(this);
connect(preassureTimer, &QTimer::timeout, this, &PylonRecorder::displayBufferPressure); connect(pressureTimer, &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);
preassureBar = new QProgressBar(this); pressureBar = new QProgressBar(this);
preassureBar->setRange(0, 100); pressureBar->setRange(0, 100);
preassureBar->setTextVisible(true); pressureBar->setTextVisible(true);
preassureBar->setFixedSize(200, 25); pressureBar->setFixedSize(200, 25);
QColor color = progressColor(0); QColor color = progressColor(0);
QPalette progressPalette = preassureBar->palette(); QPalette progressPalette = pressureBar->palette();
progressPalette.setBrush(QPalette::Highlight, QBrush(color)); progressPalette.setBrush(QPalette::Highlight, QBrush(color));
preassureBar->setPalette(progressPalette); pressureBar->setPalette(progressPalette);
QLabel *preassureLabel = new QLabel("Buffer preassure:", this); QLabel *preassureLabel = new QLabel("Buffer preassure:", this);
preassureLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;font-weight: Bold}"); preassureLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;font-weight: Bold}");
loadBar = new QProgressBar(this); loadBar = new QProgressBar(this);
@ -103,7 +103,7 @@ PylonRecorder::PylonRecorder(QWidget *parent)
statusBar()->addWidget(camHeader); statusBar()->addWidget(camHeader);
statusBar()->addWidget(cameraConnectedLabel); statusBar()->addWidget(cameraConnectedLabel);
statusBar()->addWidget(preassureLabel); statusBar()->addWidget(preassureLabel);
statusBar()->addWidget(preassureBar); statusBar()->addWidget(pressureBar);
statusBar()->addWidget(loadLabel); statusBar()->addWidget(loadLabel);
statusBar()->addWidget(loadBar); statusBar()->addWidget(loadBar);
statusBar()->addWidget(statusHeader); statusBar()->addWidget(statusHeader);
@ -241,12 +241,13 @@ void PylonRecorder::setImage(const QImage &newImage) {
scrollArea->setVisible(true); scrollArea->setVisible(true);
printAct->setEnabled(true); printAct->setEnabled(true);
fitToWindowAct->setEnabled(true); fitToWindowAct->setEnabled(true);
updateActions(); //updateActions();
if (!fitToWindowAct->isChecked()) { if (!fitToWindowAct->isChecked()) {
imageLabel->adjustSize(); imageLabel->adjustSize();
applyScaling(); applyScaling();
} }
this->update();
} }
@ -733,8 +734,8 @@ void PylonRecorder::startRecording() {
} }
writer = new Writer(buffer); writer = new Writer(buffer);
connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone); connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone);
writer->setVideoSpecs(specs); writer->setVideoSpecs(specs);
QSettings s; QSettings s;
this->mdata.read(s); this->mdata.read(s);
writer->setProjectMetadata(mdata); writer->setProjectMetadata(mdata);
@ -749,7 +750,7 @@ void PylonRecorder::startRecording() {
grabbing = true; grabbing = true;
stopRequest = false; stopRequest = false;
preassureTimer->start(50); pressureTimer->start(50);
frameTimer->start(50); frameTimer->start(50);
labelTimer->start(650); labelTimer->start(650);
updateActions(); updateActions();
@ -781,8 +782,9 @@ void PylonRecorder::stopRecording() {
void PylonRecorder::writerDone() { void PylonRecorder::writerDone() {
preassureTimer->stop(); std::cerr << "writer is Done!!!" << std::endl;
preassureBar->reset(); pressureTimer->stop();
pressureBar->reset();
loadBar->reset(); loadBar->reset();
labelTimer->stop(); labelTimer->stop();
writingLabel->setStyleSheet(inactiveLabelStyle); writingLabel->setStyleSheet(inactiveLabelStyle);
@ -803,14 +805,18 @@ void PylonRecorder::displayActivity() {
void PylonRecorder::displaySingleFrame() { void PylonRecorder::displaySingleFrame() {
MyImage *img = buffer->readLast(); MyImage *img;
if (img != nullptr){ // if (dryRunCheckBox->isChecked())
QImage qimg(static_cast<uchar *>(img->data()), img->width(), img->height(), // img = buffer->pop();
QImage::Format::Format_Grayscale8); // else {
setImage(qimg); img = buffer->readLast();
}/* else { // }
std::cerr << "Error reading last image" << std::endl; if (img != nullptr){
}*/ QImage qimg(static_cast<uchar *>(img->data()), img->width(), img->height(), QImage::Format::Format_Grayscale8);
setImage(qimg);
}else {
std::cerr << "Error reading last image" << std::endl;
}
} }
@ -841,11 +847,11 @@ std::string PylonRecorder::createFilename(const std::string &extension) {
void PylonRecorder::displayBufferPressure() { void PylonRecorder::displayBufferPressure() {
int value = static_cast<int>(round(buffer->bufferPreassure())); int value = static_cast<int>(round(buffer->bufferPressure()));
preassureBar->setValue(value); pressureBar->setValue(value);
QColor color = progressColor(value); QColor color = progressColor(value);
progressPalette.setBrush(QPalette::Highlight, QBrush(color)); progressPalette.setBrush(QPalette::Highlight, QBrush(color));
preassureBar->setPalette(progressPalette); pressureBar->setPalette(progressPalette);
int load = static_cast<int>(buffer->bufferLoad()); int load = static_cast<int>(buffer->bufferLoad());
loadBar->setValue(load); loadBar->setValue(load);

View File

@ -92,10 +92,10 @@ private:
int defaultBufferSize = 3000, defaultFrameRate = 30, movieCount = 0, defaultExposureTime = 6000, defaultGain=13; int defaultBufferSize = 3000, defaultFrameRate = 30, movieCount = 0, defaultExposureTime = 6000, defaultGain=13;
QSettings *settings = new QSettings; QSettings *settings = new QSettings;
QImage image; QImage image;
QTimer *frameTimer, *preassureTimer, *labelTimer; QTimer *frameTimer, *pressureTimer, *labelTimer;
QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel, *fileLabel; QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel, *fileLabel;
QCheckBox *dryRunCheckBox; QCheckBox *dryRunCheckBox;
QProgressBar *preassureBar; QProgressBar *pressureBar;
QProgressBar *loadBar; QProgressBar *loadBar;
QScrollArea *scrollArea; QScrollArea *scrollArea;
double scaleFactor = 1; double scaleFactor = 1;

View File

@ -107,9 +107,6 @@ void Writer::run() {
std::cerr << "Writer::run: An exception occurred." << std::endl << e.GetDescription() << std::endl; std::cerr << "Writer::run: An exception occurred." << std::endl << e.GetDescription() << std::endl;
} }
} }
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
std::cerr << "wrote binary to file " << duration.count() << std::endl;
if (count < chunksize) { if (count < chunksize) {
stamps_buffer[count] = nix::util::timeToStr(img->timestamp()); stamps_buffer[count] = nix::util::timeToStr(img->timestamp());
ids_buffer[count] = img->index(); ids_buffer[count] = img->index();