From 33f4a79407cfb950e121d01dc5011458837523ed Mon Sep 17 00:00:00 2001 From: MPIBR-kretschmerf Date: Thu, 1 Jun 2017 12:21:09 +0200 Subject: [PATCH] Added exposure, colormodes and fixed destructor --- SpinnakerCapture.cpp | 52 ++++++++++++++++++++------------------------ SpinnakerCapture.h | 2 ++ 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/SpinnakerCapture.cpp b/SpinnakerCapture.cpp index 12b0af7..ae9b492 100644 --- a/SpinnakerCapture.cpp +++ b/SpinnakerCapture.cpp @@ -45,6 +45,8 @@ SpinnakerCapture::SpinnakerCapture(QObject *parent) width = ptrWidth->GetValue(); CIntegerPtr ptrHeight = nodeMap->GetNode("Height"); height = ptrHeight->GetValue(); + CFloatPtr ptrExposureTime = nodeMap->GetNode("ExposureTime"); + exposureTime = ptrExposureTime->GetValue(); qDebug()<< "Initialized Spinnaker compatible camera (" << width << "x" << height << ")"; isInitialized = true; @@ -127,7 +129,7 @@ int SpinnakerCapture::configureExposure(double exposureTimeToSet) return result; } -// This function acquires and saves 10 images from a device. +// This function acquires images from a device. int SpinnakerCapture::acquireImages(unsigned int nImagesToCapture) { int result = 0; @@ -135,28 +137,8 @@ int SpinnakerCapture::acquireImages(unsigned int nImagesToCapture) qDebug() << "*** IMAGE ACQUISITION ***"; try{ - // // Set acquisition mode to continuous - // - // *** NOTES *** - // Because the example acquires and saves 10 images, setting acquisition - // mode to continuous lets the example finish. ifset to single frame - // or multiframe (at a lower number of images), the example would just - // hang. This would happen because the example has been written to - // acquire 10 images while the camera would have been programmed to - // retrieve less than that. - // - // Setting the value of an enumeration node is slightly more complicated - // than other node types. Two nodes must be retrieved: first, the - // enumeration node is retrieved from the nodemap; and second, the entry - // node is retrieved from the enumeration node. The integer value of the - // entry node is then set as the new value of the enumeration node. - // - // Notice that both the enumeration and the entry nodes are checked for - // availability and readability/writability. Enumeration nodes are - // generally readable and writable whereas their entry nodes are only - // ever readable. - // + // Retrieve enumeration node from nodemap CEnumerationPtr ptrAcquisitionMode = nodeMap->GetNode("AcquisitionMode"); if(!IsAvailable(ptrAcquisitionMode) || !IsWritable(ptrAcquisitionMode)){ @@ -197,7 +179,7 @@ int SpinnakerCapture::acquireImages(unsigned int nImagesToCapture) // name a few. // - ImagePtr convertedImage = pResultImage->Convert(PixelFormat_BGR8, NEAREST_NEIGHBOR); + ImagePtr convertedImage = pResultImage->Convert(pixelFormat, NEAREST_NEIGHBOR); unsigned int XPadding = convertedImage->GetXPadding(); unsigned int YPadding = convertedImage->GetYPadding(); @@ -205,10 +187,22 @@ int SpinnakerCapture::acquireImages(unsigned int nImagesToCapture) unsigned int colsize = convertedImage->GetHeight(); //image data contains padding. When allocating Mat container size, you need to account for the X,Y image data padding. - cv::Mat cvMat = cv::Mat(colsize + YPadding, rowsize + XPadding, CV_8UC3, convertedImage->GetData(), convertedImage->GetStride()); - emit(sendFrame(cvMat.clone())); + int cvFormat; + switch(pixelFormat){ + case PixelFormat_BGR8: + cvFormat = CV_8UC3; + break; + case PixelFormat_Mono16: + cvFormat = CV_16U; + break; + default: + cvFormat = CV_8UC3; + } + + cv::Mat cvMat = cv::Mat(colsize + YPadding, rowsize + XPadding, cvFormat, convertedImage->GetData(), convertedImage->GetStride()); + emit(sendFrame(cvMat.clone())); } // Images retrieved directly from the camera (i.e. non-converted @@ -278,11 +272,11 @@ SpinnakerCapture::~SpinnakerCapture() { // Deinitialize camera pCam->DeInit(); - delete nodeMapTLDevice; - delete nodeMap; + pCam = NULL; + nodeMapTLDevice = NULL; + nodeMap = NULL; // Clear camera list before releasing system camList.Clear(); - // // Release system + // Release system system->ReleaseInstance(); } - diff --git a/SpinnakerCapture.h b/SpinnakerCapture.h index 87ef6da..5452e59 100644 --- a/SpinnakerCapture.h +++ b/SpinnakerCapture.h @@ -20,6 +20,8 @@ class SpinnakerCapture : public QObject bool isInitialized = false; unsigned int width = 0; unsigned int height = 0; + float exposureTime = 0; + PixelFormatEnums pixelFormat = PixelFormat_Mono16; //PixelFormat_BGR8 ~SpinnakerCapture(); private: CameraPtr pCam;