Skip to content

Commit 486a65b

Browse files
authored
Expose setters for undistortion parameters in Andor device (#756)
* ENH: Add setters for Andor camera undistortion parameters * ENH: Andor camera processed images converted to counts/seconds * BUG: Andor correction images loaded in as uint8 but should be uint16
1 parent 0e36b94 commit 486a65b

2 files changed

Lines changed: 45 additions & 6 deletions

File tree

src/PlusDataCollection/Andor/vtkPlusAndorVideoSource.cxx

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ void vtkPlusAndorVideoSource::ApplyCosmicRayCorrection(int bin, cv::Mat& floatIm
670670
}
671671

672672
// ----------------------------------------------------------------------------
673-
void vtkPlusAndorVideoSource::ApplyFrameCorrections(int binning)
673+
void vtkPlusAndorVideoSource::ApplyFrameCorrections(int binning, float exposureTime)
674674
{
675675
cv::Mat cvIMG(frameSize[0], frameSize[1], CV_16UC1, &rawFrame[0]); // uses rawFrame as buffer
676676
CorrectBadPixels(binning, cvIMG);
@@ -696,6 +696,9 @@ void vtkPlusAndorVideoSource::ApplyFrameCorrections(int binning)
696696
// Divide the image by the 32-bit floating point correction image
697697
cv::divide(result, cvFlatCorrection, result, 1, CV_32FC1);
698698
LOG_INFO("Applied multiplicative flat correction");
699+
700+
// Convert image from count to counts/seconds
701+
cv::divide(result, exposureTime, result, 1, CV_32FC1);
699702
result.convertTo(cvIMG, CV_16UC1);
700703
}
701704

@@ -709,7 +712,7 @@ PlusStatus vtkPlusAndorVideoSource::AcquireBLIFrame(int binning, int vsSpeed, in
709712

710713
if(this->UseFrameCorrections)
711714
{
712-
ApplyFrameCorrections(binning);
715+
ApplyFrameCorrections(binning, exposureTime);
713716
AddFrameToDataSource(BLICorrected);
714717
}
715718

@@ -726,7 +729,7 @@ PlusStatus vtkPlusAndorVideoSource::AcquireGrayscaleFrame(int binning, int vsSpe
726729

727730
if(this->UseFrameCorrections)
728731
{
729-
ApplyFrameCorrections(binning);
732+
ApplyFrameCorrections(binning, exposureTime);
730733
AddFrameToDataSource(GrayCorrected);
731734
}
732735

@@ -775,7 +778,7 @@ PlusStatus vtkPlusAndorVideoSource::SetBiasDarkCorrectionImage(const std::string
775778
{
776779
try
777780
{
778-
cvBiasDarkCorrection = cv::imread(biasDarkFilePath, cv::IMREAD_GRAYSCALE);
781+
cvBiasDarkCorrection = cv::imread(biasDarkFilePath, cv::IMREAD_UNCHANGED);
779782
if(cvBiasDarkCorrection.empty())
780783
{
781784
throw "Bias+dark correction image empty!";
@@ -794,7 +797,7 @@ PlusStatus vtkPlusAndorVideoSource::SetFlatCorrectionImage(std::string flatFileP
794797
{
795798
try
796799
{
797-
cvFlatCorrection = cv::imread(flatFilePath, cv::IMREAD_GRAYSCALE);
800+
cvFlatCorrection = cv::imread(flatFilePath, cv::IMREAD_UNCHANGED);
798801
if(cvFlatCorrection.empty())
799802
{
800803
throw "Flat correction image empty!";
@@ -993,6 +996,36 @@ bool vtkPlusAndorVideoSource::GetUseCosmicRayCorrection()
993996
return this->UseCosmicRayCorrection;
994997
}
995998

999+
// ----------------------------------------------------------------------------
1000+
PlusStatus vtkPlusAndorVideoSource::SetCameraIntrinsics(std::array<double, 9> intrinsics)
1001+
{
1002+
std::copy(std::begin(intrinsics), std::end(intrinsics), this->cameraIntrinsics);
1003+
return PLUS_SUCCESS;
1004+
}
1005+
1006+
// ----------------------------------------------------------------------------
1007+
std::array<double, 9> vtkPlusAndorVideoSource::GetCameraIntrinsics()
1008+
{
1009+
std::array<double, 9> returnIntrinsics;
1010+
std::copy(this->cameraIntrinsics, this->cameraIntrinsics + 9, std::begin(returnIntrinsics));
1011+
return returnIntrinsics;
1012+
}
1013+
1014+
// ----------------------------------------------------------------------------
1015+
PlusStatus vtkPlusAndorVideoSource::SetDistanceCoefficients(std::array<double, 4> coefficients)
1016+
{
1017+
std::copy(std::begin(coefficients), std::end(coefficients), this->distanceCoefficients);
1018+
return PLUS_SUCCESS;
1019+
}
1020+
1021+
// ----------------------------------------------------------------------------
1022+
std::array<double, 4> vtkPlusAndorVideoSource::GetDistanceCoefficients()
1023+
{
1024+
std::array<double, 4> returnCoefficients;
1025+
std::copy(this->distanceCoefficients, this->distanceCoefficients + 4, std::begin(returnCoefficients));
1026+
return returnCoefficients;
1027+
}
1028+
9961029
// ----------------------------------------------------------------------------
9971030
PlusStatus vtkPlusAndorVideoSource::SetRequireCoolTemp(bool requireCoolTemp)
9981031
{

src/PlusDataCollection/Andor/vtkPlusAndorVideoSource.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ class vtkPlusDataCollectionExport vtkPlusAndorVideoSource: public vtkPlusDevice
159159
return flatCorrection;
160160
}
161161

162+
/*! Data for setting undistortion coefficients. */
163+
PlusStatus SetCameraIntrinsics(std::array<double, 9> intrinsics);
164+
std::array<double, 9> GetCameraIntrinsics();
165+
PlusStatus SetDistanceCoefficients(std::array<double, 4> coefficients);
166+
std::array<double, 4> GetDistanceCoefficients();
167+
162168
/*! -1 uses currently active settings. */
163169
PlusStatus AcquireBLIFrame(int binning, int vsSpeed, int hsSpeed, float exposureTime);
164170

@@ -247,7 +253,7 @@ class vtkPlusDataCollectionExport vtkPlusAndorVideoSource: public vtkPlusDevice
247253
void ApplyCosmicRayCorrection(int binning, cv::Mat& floatImage);
248254

249255
/*! Applies bias correction for dark current, flat correction and lens distortion. */
250-
void ApplyFrameCorrections(int binning);
256+
void ApplyFrameCorrections(int binning, float exposureTime);
251257

252258
/*! Flag whether to call ApplyFrameCorrections on the raw acquired frame on acquisition
253259
or to skip frame corrections.

0 commit comments

Comments
 (0)