[grabber] is continuously grabbing

This commit is contained in:
Jan Grewe 2020-03-12 18:19:57 +01:00
parent c41d4ed035
commit 3062db01cc
5 changed files with 42 additions and 33 deletions

View File

@ -1,13 +1,22 @@
#include "grabber.h"
#include <iostream>
#include <pylon/PylonIncludes.h>
void Grabber::run() {
int count = 0;
while (!stop_request) {
std::cerr << "running: " << count << std::endl;
count += 1;
msleep(500);
}
std::cerr << "terminated: " << count << std::endl;
//emit terminated();
if (camera->isOpen()) {
Pylon::CGrabResultPtr frame;
Pylon::CInstantCamera *cam = camera->getCamera();
cam->StartGrabbing();
while (!stop_request) {
camera->frameRate(75);
MyImage img;
cam->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
img.setFrame(frame);
buffer->push(img);
count += 1;
}
cam->StopGrabbing();
std::cerr << "terminated: " << count << std::endl;
}
}

View File

@ -3,18 +3,23 @@
#include <QObject>
#include <QThread>
#include "pylonwrapper.h"
#include "imagebuffer.h"
class Grabber : public QThread
{
Q_OBJECT
public:
Grabber(QObject *parent = nullptr) : QThread(parent) {}
Grabber(PylonWrapper *camera, ImageBuffer*buffer, QObject *parent = nullptr) :
QThread(parent), camera(camera), buffer(buffer) {}
void run() override;
void stop();
private:
bool stop_request = false;
PylonWrapper *camera;
ImageBuffer *buffer;
public slots:
void requestStop() {

View File

@ -46,6 +46,7 @@ void ImageBuffer::push(const MyImage &img) {
if (load < static_cast<int64_t>(buffer.capacity()))
load += 1;
mutex.unlock();
std::cerr << "load: " << bufferLoad() << "\t pressure: " << bufferPreassure() << std::endl;
}
bool ImageBuffer::bufferNotEmpty() {

View File

@ -20,7 +20,6 @@
#include <QToolBar>
#include <iostream>
#include <chrono>
#include "grabber.h"
#if defined(QT_PRINTSUPPORT_LIB)
# include <QtPrintSupport/qtprintsupportglobal.h>
@ -42,6 +41,8 @@ PylonRecorder::PylonRecorder(QWidget *parent)
scrollArea->setVisible(false);
setCentralWidget(scrollArea);
pylon = new PylonWrapper();
buffer = new ImageBuffer();
grabber = new Grabber(pylon, buffer);
createActions();
updateActions();
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
@ -50,6 +51,8 @@ PylonRecorder::PylonRecorder(QWidget *parent)
PylonRecorder::~PylonRecorder(){
delete pylon;
delete buffer;
delete grabber;
}
bool PylonRecorder::loadFile(const QString &fileName) {
@ -290,6 +293,7 @@ void PylonRecorder::createActions() {
grab_still_action->setShortcut(tr("Ctrl+ "));
grab_continuous_action = camera_menu->addAction(tr("&grab continuous"), this, &PylonRecorder::startRecording);
grab_continuous_action->setShortcut(tr("Ctrl+Enter"));
grab_stop_action = camera_menu->addAction(tr("&stop grabbing"), this, &PylonRecorder::stopRecording);
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(tr("&About"), this, &PylonRecorder::about);
@ -301,6 +305,8 @@ void PylonRecorder::createActions() {
toolbar->addAction(disconnect_camera_action);
toolbar->addSeparator();
toolbar->addAction(grab_still_action);
toolbar->addAction(grab_continuous_action);
toolbar->addAction(grab_stop_action);
}
void PylonRecorder::updateActions() {
@ -313,6 +319,7 @@ void PylonRecorder::updateActions() {
connect_camera_action->setEnabled(!pylon->isOpen());
grab_still_action->setEnabled(pylon->isOpen());
grab_continuous_action->setEnabled(pylon->isOpen());
}
void PylonRecorder::scaleImage(double factor) {
@ -357,31 +364,13 @@ void PylonRecorder::disconnectCamera() {
void PylonRecorder::startRecording() {
int framecount = 500;
Grabber grabber;
grabber.start();
Pylon::CGrabResultPtr frame;
if (pylon->isOpen()) {
pylon->frameRate(75);
Pylon::CInstantCamera *cam = pylon->getCamera();
cam->StartGrabbing();
auto start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < framecount; ++i) {
MyImage img;
cam->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
img.setFrame(frame);
buffer.push(img);
std::cerr << i << ": Buffer stats: capacity: " << buffer.capacity() << "\tload: " << buffer.bufferLoad() << "\t pressure: " << buffer.bufferPreassure() << "frameid: " << frame->GetID() << std::endl;
}
auto finish = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = finish - start;
cam->StopGrabbing();
std::cerr << "elapsed time: " << elapsed.count() << " s\n";
}
grabber.requestStop();
grabber.wait(10000);
grabber->start();
}
void PylonRecorder::stopRecording() {}
void PylonRecorder::stopRecording() {
grabber->requestStop();
grabber->wait(10000);
}
void PylonRecorder::grabStillFromPylon() {
if (pylon->isOpen()) {

View File

@ -4,6 +4,8 @@
#include <QMainWindow>
#include "pylonwrapper.h"
#include "imagebuffer.h"
#include "grabber.h"
#include <QImage>
#if defined(QT_PRINTSUPPORT_LIB)
# include <QtPrintSupport/qtprintsupportglobal.h>
@ -66,7 +68,9 @@ private:
QScrollArea *scrollArea;
double scaleFactor = 1;
PylonWrapper *pylon;
ImageBuffer buffer;
ImageBuffer *buffer;
Grabber *grabber;
bool grabbing;
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
QPrinter printer;
@ -81,6 +85,7 @@ private:
QAction *fitToWindowAct;
QAction *grab_still_action;
QAction *grab_continuous_action;
QAction *grab_stop_action;
QAction *connect_camera_action;
QAction *disconnect_camera_action;
};