Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved support for image formats
  • Loading branch information
MPIBR-kretschmerf committed Jun 1, 2017
1 parent 33f4a79 commit 6706ff2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
43 changes: 27 additions & 16 deletions SpinnakerCapture.cpp
Expand Up @@ -41,14 +41,16 @@ SpinnakerCapture::SpinnakerCapture(QObject *parent)
// Retrieve GenICam nodemap
nodeMap = &pCam->GetNodeMap();

CIntegerPtr ptrWidth = nodeMap->GetNode("Width");
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 << ")";
width = pCam->Width.GetValue();
height = pCam->Height.GetValue();
exposureTime = pCam->ExposureTime.GetValue();
pixelFormat = pCam->PixelFormat.GetValue();
qDebug() <<"Initialized Spinnaker compatible camera ("
<< width << "x" << height
<< pCam->PixelFormat.GetCurrentEntry()->GetSymbolic()
<< ")";

isInitialized = true;
}
catch (Spinnaker::Exception &e){
Expand Down Expand Up @@ -179,27 +181,36 @@ int SpinnakerCapture::acquireImages(unsigned int nImagesToCapture)
// name a few.
//

ImagePtr convertedImage = pResultImage->Convert(pixelFormat, NEAREST_NEIGHBOR);

unsigned int XPadding = convertedImage->GetXPadding();
unsigned int YPadding = convertedImage->GetYPadding();
unsigned int rowsize = convertedImage->GetWidth();
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.

int cvFormat;
ImagePtr convertedImage;
switch(pixelFormat){
case PixelFormat_BGR8:
//we could also convert the format:
//convertedImage = pResultImage->Convert(Spinnaker::PixelFormatEnums(pixelFormat), NEAREST_NEIGHBOR);
convertedImage = pResultImage;
cvFormat = CV_8UC3;
break;
case PixelFormat_Mono8:
convertedImage = pResultImage;
cvFormat = CV_8UC1;
break;
case PixelFormat_Mono16:
cvFormat = CV_16U;
convertedImage = pResultImage;
cvFormat = CV_16UC1;
break;
default:
convertedImage = pResultImage;
cvFormat = CV_8UC3;
}

unsigned int XPadding = convertedImage->GetXPadding();
unsigned int YPadding = convertedImage->GetYPadding();
unsigned int rowsize = convertedImage->GetWidth();
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, cvFormat, convertedImage->GetData(), convertedImage->GetStride());

emit(sendFrame(cvMat.clone()));
Expand Down
2 changes: 1 addition & 1 deletion SpinnakerCapture.h
Expand Up @@ -21,7 +21,7 @@ class SpinnakerCapture : public QObject
unsigned int width = 0;
unsigned int height = 0;
float exposureTime = 0;
PixelFormatEnums pixelFormat = PixelFormat_Mono16; //PixelFormat_BGR8
int64_t pixelFormat; //PixelFormat_BGR8
~SpinnakerCapture();
private:
CameraPtr pCam;
Expand Down

0 comments on commit 6706ff2

Please sign in to comment.