implement class to store image, initials of circ buffer
This commit is contained in:
parent
ac9607a915
commit
24bca792e9
6
imagebuffer.cpp
Normal file
6
imagebuffer.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "imagebuffer.h"
|
||||||
|
|
||||||
|
ImageBuffer::ImageBuffer(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
18
imagebuffer.h
Normal file
18
imagebuffer.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef IMAGEBUFFER_H
|
||||||
|
#define IMAGEBUFFER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
class ImageBuffer : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ImageBuffer(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // IMAGEBUFFER_H
|
40
myimage.cpp
Normal file
40
myimage.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include "myimage.h"
|
||||||
|
|
||||||
|
MyImage::MyImage()
|
||||||
|
{}
|
||||||
|
|
||||||
|
MyImage::MyImage(Pylon::CGrabResultPtr ptr) {
|
||||||
|
setFrame(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MyImage::setFrame(Pylon::CGrabResultPtr ptr) {
|
||||||
|
bool valid = ptr.IsValid() && ptr->GetWidth() <= max_width && ptr->GetHeight() <= max_height;
|
||||||
|
if (valid) {
|
||||||
|
img_index = ptr->GetID();
|
||||||
|
img_width = ptr->GetWidth();
|
||||||
|
img_height = ptr->GetHeight();
|
||||||
|
memcpy(&buffer, ptr->GetBuffer(), ptr->GetImageSize());
|
||||||
|
}
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MyImage::width() {
|
||||||
|
return static_cast<int>(img_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
int MyImage::height() {
|
||||||
|
return static_cast<int>(img_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
int MyImage::size() {
|
||||||
|
return static_cast<int>(img_width * img_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t MyImage::index() {
|
||||||
|
return img_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *MyImage::data() {
|
||||||
|
return &buffer;
|
||||||
|
}
|
||||||
|
|
28
myimage.h
Normal file
28
myimage.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef MYIMAGE_H
|
||||||
|
#define MYIMAGE_H
|
||||||
|
|
||||||
|
#include<pylon/PylonIncludes.h>
|
||||||
|
|
||||||
|
class MyImage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyImage();
|
||||||
|
MyImage(Pylon::CGrabResultPtr ptr);
|
||||||
|
|
||||||
|
int width();
|
||||||
|
int height();
|
||||||
|
int size();
|
||||||
|
int64_t index();
|
||||||
|
void* data();
|
||||||
|
bool setFrame(Pylon::CGrabResultPtr ptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t img_width = 0;
|
||||||
|
uint32_t img_height = 0;
|
||||||
|
int64_t img_index = 0;
|
||||||
|
static const int max_width = 2048;
|
||||||
|
static const int max_height = 1536;
|
||||||
|
char buffer[max_width * max_height];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MYIMAGE_H
|
@ -358,14 +358,12 @@ void PylonRecorder::stopRecording() {}
|
|||||||
|
|
||||||
void PylonRecorder::grabStillFromPylon() {
|
void PylonRecorder::grabStillFromPylon() {
|
||||||
if (pylon->isOpen()) {
|
if (pylon->isOpen()) {
|
||||||
ImageSettings settings = pylon->getImageSettings();
|
MyImage img;
|
||||||
Pylon::CGrabResultPtr image_ptr = pylon->grabFrame();
|
bool valid = pylon->grabFrame(img);
|
||||||
if (image_ptr.IsValid() && image_ptr->GrabSucceeded()) {
|
if (valid) {
|
||||||
size_t stride;
|
QImage qimg(static_cast<uchar *>(img.data()), img.width(), img.height(),
|
||||||
image_ptr->GetStride(stride);
|
|
||||||
QImage img(static_cast<uchar *>(image_ptr->GetBuffer()), static_cast<int>(settings.width), static_cast<int>(settings.height),
|
|
||||||
QImage::Format::Format_Grayscale8);
|
QImage::Format::Format_Grayscale8);
|
||||||
setImage(img);
|
setImage(qimg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
statusBar()->showMessage(tr("Camera is not open! Connect to camera first!"));
|
statusBar()->showMessage(tr("Camera is not open! Connect to camera first!"));
|
||||||
|
@ -34,15 +34,15 @@ ImageSettings PylonWrapper::getImageSettings() {
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pylon::CGrabResultPtr PylonWrapper::grabFrame() {
|
bool PylonWrapper::grabFrame(MyImage &img) {
|
||||||
Pylon::CPylonImage img;
|
Pylon::CGrabResultPtr frame;
|
||||||
Pylon::CGrabResultPtr ptrGrabResult;
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
camera->StartGrabbing();
|
camera->StartGrabbing();
|
||||||
camera->RetrieveResult( 5000, ptrGrabResult, Pylon::TimeoutHandling_ThrowException);
|
camera->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
|
||||||
camera->StopGrabbing();
|
camera->StopGrabbing();
|
||||||
}
|
}
|
||||||
return ptrGrabResult;
|
img.setFrame(frame);
|
||||||
|
return frame.IsValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PylonWrapper::openCamera(std::string &message) {
|
bool PylonWrapper::openCamera(std::string &message) {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <pylon/PylonIncludes.h>
|
#include <pylon/PylonIncludes.h>
|
||||||
#include <pylon/BaslerUniversalInstantCamera.h>
|
#include <pylon/BaslerUniversalInstantCamera.h>
|
||||||
|
#include "myimage.h"
|
||||||
|
|
||||||
struct ImageSettings {
|
struct ImageSettings {
|
||||||
int64_t width = 0;
|
int64_t width = 0;
|
||||||
@ -20,7 +21,7 @@ public:
|
|||||||
void terminate();
|
void terminate();
|
||||||
bool openCamera(std::string &message);
|
bool openCamera(std::string &message);
|
||||||
void closeCamera();
|
void closeCamera();
|
||||||
Pylon::CGrabResultPtr grabFrame();
|
bool grabFrame(MyImage &img);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Pylon::CInstantCamera *camera;
|
Pylon::CInstantCamera *camera;
|
||||||
|
@ -3,9 +3,13 @@ requires(qtConfig(filedialog))
|
|||||||
qtHaveModule(printsupport): QT += gui printsupport
|
qtHaveModule(printsupport): QT += gui printsupport
|
||||||
|
|
||||||
HEADERS = \
|
HEADERS = \
|
||||||
|
imagebuffer.h \
|
||||||
|
myimage.h \
|
||||||
pylonrecorder.h \
|
pylonrecorder.h \
|
||||||
pylonwrapper.h
|
pylonwrapper.h
|
||||||
SOURCES = \
|
SOURCES = \
|
||||||
|
imagebuffer.cpp \
|
||||||
|
myimage.cpp \
|
||||||
pylonrecorder.cpp \
|
pylonrecorder.cpp \
|
||||||
pylonwrapper.cpp \
|
pylonwrapper.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
Loading…
Reference in New Issue
Block a user