diff --git a/imagebuffer.cpp b/imagebuffer.cpp new file mode 100644 index 0000000..9c792b5 --- /dev/null +++ b/imagebuffer.cpp @@ -0,0 +1,6 @@ +#include "imagebuffer.h" + +ImageBuffer::ImageBuffer(QObject *parent) : QObject(parent) +{ + +} diff --git a/imagebuffer.h b/imagebuffer.h new file mode 100644 index 0000000..bfc6056 --- /dev/null +++ b/imagebuffer.h @@ -0,0 +1,18 @@ +#ifndef IMAGEBUFFER_H +#define IMAGEBUFFER_H + +#include + + +class ImageBuffer : public QObject +{ + Q_OBJECT +public: + explicit ImageBuffer(QObject *parent = nullptr); + +signals: + +public slots: +}; + +#endif // IMAGEBUFFER_H diff --git a/myimage.cpp b/myimage.cpp new file mode 100644 index 0000000..6c7d4a2 --- /dev/null +++ b/myimage.cpp @@ -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(img_width); +} + +int MyImage::height() { + return static_cast(img_height); +} + +int MyImage::size() { + return static_cast(img_width * img_height); +} + +int64_t MyImage::index() { + return img_index; +} + +void *MyImage::data() { + return &buffer; +} + diff --git a/myimage.h b/myimage.h new file mode 100644 index 0000000..25d856f --- /dev/null +++ b/myimage.h @@ -0,0 +1,28 @@ +#ifndef MYIMAGE_H +#define MYIMAGE_H + +#include + +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 diff --git a/pylonrecorder.cpp b/pylonrecorder.cpp index 44e9d3b..87ed2ff 100644 --- a/pylonrecorder.cpp +++ b/pylonrecorder.cpp @@ -358,14 +358,12 @@ void PylonRecorder::stopRecording() {} void PylonRecorder::grabStillFromPylon() { if (pylon->isOpen()) { - ImageSettings settings = pylon->getImageSettings(); - Pylon::CGrabResultPtr image_ptr = pylon->grabFrame(); - if (image_ptr.IsValid() && image_ptr->GrabSucceeded()) { - size_t stride; - image_ptr->GetStride(stride); - QImage img(static_cast(image_ptr->GetBuffer()), static_cast(settings.width), static_cast(settings.height), + MyImage img; + bool valid = pylon->grabFrame(img); + if (valid) { + QImage qimg(static_cast(img.data()), img.width(), img.height(), QImage::Format::Format_Grayscale8); - setImage(img); + setImage(qimg); } } else { statusBar()->showMessage(tr("Camera is not open! Connect to camera first!")); diff --git a/pylonwrapper.cpp b/pylonwrapper.cpp index e8e8d72..d64ca84 100644 --- a/pylonwrapper.cpp +++ b/pylonwrapper.cpp @@ -34,15 +34,15 @@ ImageSettings PylonWrapper::getImageSettings() { return settings; } -Pylon::CGrabResultPtr PylonWrapper::grabFrame() { - Pylon::CPylonImage img; - Pylon::CGrabResultPtr ptrGrabResult; +bool PylonWrapper::grabFrame(MyImage &img) { + Pylon::CGrabResultPtr frame; if (valid) { camera->StartGrabbing(); - camera->RetrieveResult( 5000, ptrGrabResult, Pylon::TimeoutHandling_ThrowException); + camera->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException); camera->StopGrabbing(); } - return ptrGrabResult; + img.setFrame(frame); + return frame.IsValid(); } bool PylonWrapper::openCamera(std::string &message) { diff --git a/pylonwrapper.h b/pylonwrapper.h index 4daebc3..524cd4e 100644 --- a/pylonwrapper.h +++ b/pylonwrapper.h @@ -3,6 +3,7 @@ #include #include +#include "myimage.h" struct ImageSettings { int64_t width = 0; @@ -20,7 +21,7 @@ public: void terminate(); bool openCamera(std::string &message); void closeCamera(); - Pylon::CGrabResultPtr grabFrame(); + bool grabFrame(MyImage &img); private: Pylon::CInstantCamera *camera; diff --git a/recorder.pro b/recorder.pro index 4beaede..4e19ad5 100644 --- a/recorder.pro +++ b/recorder.pro @@ -3,9 +3,13 @@ requires(qtConfig(filedialog)) qtHaveModule(printsupport): QT += gui printsupport HEADERS = \ + imagebuffer.h \ + myimage.h \ pylonrecorder.h \ pylonwrapper.h SOURCES = \ + imagebuffer.cpp \ + myimage.cpp \ pylonrecorder.cpp \ pylonwrapper.cpp \ main.cpp