grabbing and display are working again
This commit is contained in:
parent
7ad190513a
commit
37db983a2f
@ -1,4 +1,5 @@
|
||||
#include "imagebuffer.h"
|
||||
#include "mylogger.h"
|
||||
#include <chrono>
|
||||
using namespace std::chrono;
|
||||
|
||||
@ -22,12 +23,12 @@ size_t ImageBuffer::capacity() {
|
||||
return buffer.capacity();
|
||||
}
|
||||
|
||||
double ImageBuffer::bufferPreassure() {
|
||||
double preassure;
|
||||
double ImageBuffer::bufferPressure() {
|
||||
double pressure;
|
||||
mutex.lock();
|
||||
preassure = static_cast<double>(load)/static_cast<double>(buffer.capacity());
|
||||
pressure = static_cast<double>(load)/static_cast<double>(buffer.capacity());
|
||||
mutex.unlock();
|
||||
return preassure * 100;
|
||||
return pressure * 100;
|
||||
}
|
||||
|
||||
size_t ImageBuffer::bufferLoad() {
|
||||
@ -92,13 +93,14 @@ MyImage* ImageBuffer::pop() {
|
||||
load -= 1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
MyImage* ImageBuffer::readLast() {
|
||||
MyImage *img;
|
||||
img = nullptr;
|
||||
mutex.lock();
|
||||
if (load > 0) {
|
||||
size_t idx = current_write_index - 1;
|
||||
@ -107,6 +109,7 @@ MyImage* ImageBuffer::readLast() {
|
||||
std::cerr << "Bank" << std::endl;
|
||||
idx = buffer_size - 1;
|
||||
}
|
||||
std::cerr << "read form index " << idx << std::endl;
|
||||
img = buffer[idx];
|
||||
}
|
||||
mutex.unlock();
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
MyImage* pop();
|
||||
MyImage* readLast();
|
||||
size_t capacity();
|
||||
double bufferPreassure();
|
||||
double bufferPressure();
|
||||
size_t bufferLoad();
|
||||
bool bufferNotEmpty();
|
||||
|
||||
|
@ -62,18 +62,18 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
||||
// }
|
||||
frameTimer = new QTimer(this);
|
||||
connect(frameTimer, &QTimer::timeout, this, &PylonRecorder::displaySingleFrame);
|
||||
preassureTimer = new QTimer(this);
|
||||
connect(preassureTimer, &QTimer::timeout, this, &PylonRecorder::displayBufferPressure);
|
||||
pressureTimer = new QTimer(this);
|
||||
connect(pressureTimer, &QTimer::timeout, this, &PylonRecorder::displayBufferPressure);
|
||||
labelTimer = new QTimer(this);
|
||||
connect(labelTimer, &QTimer::timeout, this, &PylonRecorder::displayActivity);
|
||||
preassureBar = new QProgressBar(this);
|
||||
preassureBar->setRange(0, 100);
|
||||
preassureBar->setTextVisible(true);
|
||||
preassureBar->setFixedSize(200, 25);
|
||||
pressureBar = new QProgressBar(this);
|
||||
pressureBar->setRange(0, 100);
|
||||
pressureBar->setTextVisible(true);
|
||||
pressureBar->setFixedSize(200, 25);
|
||||
QColor color = progressColor(0);
|
||||
QPalette progressPalette = preassureBar->palette();
|
||||
QPalette progressPalette = pressureBar->palette();
|
||||
progressPalette.setBrush(QPalette::Highlight, QBrush(color));
|
||||
preassureBar->setPalette(progressPalette);
|
||||
pressureBar->setPalette(progressPalette);
|
||||
QLabel *preassureLabel = new QLabel("Buffer preassure:", this);
|
||||
preassureLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;font-weight: Bold}");
|
||||
loadBar = new QProgressBar(this);
|
||||
@ -103,7 +103,7 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
||||
statusBar()->addWidget(camHeader);
|
||||
statusBar()->addWidget(cameraConnectedLabel);
|
||||
statusBar()->addWidget(preassureLabel);
|
||||
statusBar()->addWidget(preassureBar);
|
||||
statusBar()->addWidget(pressureBar);
|
||||
statusBar()->addWidget(loadLabel);
|
||||
statusBar()->addWidget(loadBar);
|
||||
statusBar()->addWidget(statusHeader);
|
||||
@ -241,12 +241,13 @@ void PylonRecorder::setImage(const QImage &newImage) {
|
||||
scrollArea->setVisible(true);
|
||||
printAct->setEnabled(true);
|
||||
fitToWindowAct->setEnabled(true);
|
||||
updateActions();
|
||||
//updateActions();
|
||||
|
||||
if (!fitToWindowAct->isChecked()) {
|
||||
imageLabel->adjustSize();
|
||||
applyScaling();
|
||||
}
|
||||
this->update();
|
||||
}
|
||||
|
||||
|
||||
@ -718,7 +719,7 @@ void PylonRecorder::startRecording() {
|
||||
grabber = nullptr;
|
||||
}
|
||||
grabber = new Grabber(pyloncam, buffer, defaultFrameRate);
|
||||
|
||||
|
||||
if (framerateSpinner->value() != grabber->currentFramerate())
|
||||
grabber->setFrameRate(framerateSpinner->value());
|
||||
if (exposureSpinner->value() != int(grabber->currentExposureTime()))
|
||||
@ -733,8 +734,8 @@ void PylonRecorder::startRecording() {
|
||||
}
|
||||
writer = new Writer(buffer);
|
||||
connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone);
|
||||
|
||||
writer->setVideoSpecs(specs);
|
||||
|
||||
QSettings s;
|
||||
this->mdata.read(s);
|
||||
writer->setProjectMetadata(mdata);
|
||||
@ -749,7 +750,7 @@ void PylonRecorder::startRecording() {
|
||||
grabbing = true;
|
||||
stopRequest = false;
|
||||
|
||||
preassureTimer->start(50);
|
||||
pressureTimer->start(50);
|
||||
frameTimer->start(50);
|
||||
labelTimer->start(650);
|
||||
updateActions();
|
||||
@ -781,8 +782,9 @@ void PylonRecorder::stopRecording() {
|
||||
|
||||
|
||||
void PylonRecorder::writerDone() {
|
||||
preassureTimer->stop();
|
||||
preassureBar->reset();
|
||||
std::cerr << "writer is Done!!!" << std::endl;
|
||||
pressureTimer->stop();
|
||||
pressureBar->reset();
|
||||
loadBar->reset();
|
||||
labelTimer->stop();
|
||||
writingLabel->setStyleSheet(inactiveLabelStyle);
|
||||
@ -803,14 +805,18 @@ void PylonRecorder::displayActivity() {
|
||||
|
||||
|
||||
void PylonRecorder::displaySingleFrame() {
|
||||
MyImage *img = buffer->readLast();
|
||||
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;
|
||||
}*/
|
||||
MyImage *img;
|
||||
// if (dryRunCheckBox->isChecked())
|
||||
// img = buffer->pop();
|
||||
// else {
|
||||
img = buffer->readLast();
|
||||
// }
|
||||
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() {
|
||||
int value = static_cast<int>(round(buffer->bufferPreassure()));
|
||||
preassureBar->setValue(value);
|
||||
int value = static_cast<int>(round(buffer->bufferPressure()));
|
||||
pressureBar->setValue(value);
|
||||
QColor color = progressColor(value);
|
||||
progressPalette.setBrush(QPalette::Highlight, QBrush(color));
|
||||
preassureBar->setPalette(progressPalette);
|
||||
pressureBar->setPalette(progressPalette);
|
||||
|
||||
int load = static_cast<int>(buffer->bufferLoad());
|
||||
loadBar->setValue(load);
|
||||
|
@ -92,10 +92,10 @@ private:
|
||||
int defaultBufferSize = 3000, defaultFrameRate = 30, movieCount = 0, defaultExposureTime = 6000, defaultGain=13;
|
||||
QSettings *settings = new QSettings;
|
||||
QImage image;
|
||||
QTimer *frameTimer, *preassureTimer, *labelTimer;
|
||||
QTimer *frameTimer, *pressureTimer, *labelTimer;
|
||||
QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel, *fileLabel;
|
||||
QCheckBox *dryRunCheckBox;
|
||||
QProgressBar *preassureBar;
|
||||
QProgressBar *pressureBar;
|
||||
QProgressBar *loadBar;
|
||||
QScrollArea *scrollArea;
|
||||
double scaleFactor = 1;
|
||||
|
@ -107,9 +107,6 @@ void Writer::run() {
|
||||
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) {
|
||||
stamps_buffer[count] = nix::util::timeToStr(img->timestamp());
|
||||
ids_buffer[count] = img->index();
|
||||
|
Loading…
Reference in New Issue
Block a user