From dc905995a44914674adc227dfb10f26199c6df66 Mon Sep 17 00:00:00 2001 From: Blanca Macazaga Date: Wed, 9 Oct 2024 16:46:19 +0200 Subject: [PATCH] Add macOS to the pipeline, set floats to doubles --- .github/workflows/c-cpp.yml | 14 +- src/Configuration.cpp | 28 +-- src/ConfigurationParams.h | 12 +- src/Flash.cpp | 52 +---- src/Flash.h | 24 +-- src/RedSaturation.cpp | 32 +-- src/RedSaturation.h | 19 +- src/RelativeLuminance.cpp | 10 +- src/RelativeLuminance.h | 7 +- test/Iris.Tests/include/IrisLibTest.h | 5 + test/Iris.Tests/src/CDLuminanceTest.cpp | 32 +-- test/Iris.Tests/src/FrameRgbConverterTest.cpp | 4 +- test/Iris.Tests/src/RedSaturationTests.cpp | 146 ++++++------- test/Iris.Tests/src/RelativeLuminanceTest.cpp | 194 +++++++++--------- utils/include/utils/FrameConverter.h | 6 +- utils/src/FrameConverter.cpp | 2 +- 16 files changed, 248 insertions(+), 339 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 0ec908f..2304b22 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -11,15 +11,14 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest] - #ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, windows-latest, macos-latest] include: - os: windows-latest triplet: x64-windows - os: ubuntu-latest triplet: x64-linux - # - os: macos-latest - # triplet: x64-osx + - os: macos-latest + triplet: x64-osx continue-on-error: true @@ -103,15 +102,14 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest] - #ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, windows-latest, macos-latest] include: - os: windows-latest triplet: x64-windows - os: ubuntu-latest triplet: x64-linux - # - os: macos-latest - # triplet: x64-osx + - os: macos-latest + triplet: x64-osx continue-on-error: true diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 8cfc521..6a14609 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -68,33 +68,33 @@ namespace iris if (m_luminanceType == LuminanceType::CD) { m_luminanceFlashParams = new FlashParams( - jsonFile.GetParam("Luminance", "CdLuminanceFlashThreshold"), - jsonFile.GetParam("FlashDetection", "AreaProportion"), - jsonFile.GetParam("Luminance", "CdDarkLuminanceThreshold")); + jsonFile.GetParam("Luminance", "CdLuminanceFlashThreshold"), + jsonFile.GetParam("FlashDetection", "AreaProportion"), + jsonFile.GetParam("Luminance", "CdDarkLuminanceThreshold")); } else { m_luminanceFlashParams = new FlashParams( - jsonFile.GetParam("Luminance", "RelativeLuminanceFlashThreshold"), - jsonFile.GetParam("FlashDetection", "AreaProportion"), - jsonFile.GetParam("Luminance", "RelativeDarkLuminanceThreshold")); + jsonFile.GetParam("Luminance", "RelativeLuminanceFlashThreshold"), + jsonFile.GetParam("FlashDetection", "AreaProportion"), + jsonFile.GetParam("Luminance", "RelativeDarkLuminanceThreshold")); } //Red Saturation m_redSaturationFlashParams = new FlashParams( - jsonFile.GetParam("RedSaturation", "FlashThreshold"), - jsonFile.GetParam("FlashDetection", "AreaProportion"), - jsonFile.GetParam("RedSaturation", "RedDarkThreshold")); + jsonFile.GetParam("RedSaturation", "FlashThreshold"), + jsonFile.GetParam("FlashDetection", "AreaProportion"), + jsonFile.GetParam("RedSaturation", "RedDarkThreshold")); //FrameRgbConverter Params m_frameSrgbConverterParams = new EA::EACC::Utils::FrameConverterParams( - jsonFile.GetVector("FlashDetection", "sRGBValues")); + jsonFile.GetVector("FlashDetection", "sRGBValues")); //FrameRgbConverter Params for CD Luminance conversion if (m_luminanceType == LuminanceType::CD) { m_frameCDLuminanceConverterParams = new EA::EACC::Utils::FrameConverterParams( - jsonFile.GetVector("Luminance", "CdLuminanceValues")); + jsonFile.GetVector("Luminance", "CdLuminanceValues")); } //Transition Tracker Params @@ -107,15 +107,15 @@ namespace iris //Pattern Detection int minStripes = jsonFile.GetParam("PatternDetection", "MinStripes"); - float darkLumThreshold = 0.0f; + double darkLumThreshold = 0.0f; if (m_luminanceType == LuminanceType::CD) { - darkLumThreshold = jsonFile.GetParam("PatternDetection", "CDDarkLuminanceThreshold"); + darkLumThreshold = jsonFile.GetParam("PatternDetection", "CDDarkLuminanceThreshold"); } else { - darkLumThreshold = jsonFile.GetParam("PatternDetection", "RelativeDarkLuminanceThreshold"); + darkLumThreshold = jsonFile.GetParam("PatternDetection", "RelativeDarkLuminanceThreshold"); } m_patternDetectionParams = new PatternDetectionParams( diff --git a/src/ConfigurationParams.h b/src/ConfigurationParams.h index 9eb11f3..3ecf0f6 100644 --- a/src/ConfigurationParams.h +++ b/src/ConfigurationParams.h @@ -10,19 +10,19 @@ namespace iris struct FlashParams { - FlashParams(float flashThresh, float areaP, float darkThresh) : flashThreshold(flashThresh), areaProportion(areaP), darkThreshold(darkThresh) {}; + FlashParams(double flashThresh, double areaP, double darkThresh) : flashThreshold(flashThresh), areaProportion(areaP), darkThreshold(darkThresh) {}; //threshold of Red Saturation or Luminace - float flashThreshold; //if flash values overpass threshold, a transition has occurred - float areaProportion; //minimum area of the screen display for a transition to have occurred - float darkThreshold; //if darker image is above this threshold, a transitions has not occurred + double flashThreshold; //if flash values overpass threshold, a transition has occurred + double areaProportion; //minimum area of the screen display for a transition to have occurred + double darkThreshold; //if darker image is above this threshold, a transitions has not occurred }; struct FrameRgbConverterParams { - FrameRgbConverterParams(std::vector sRgbValues) : sRgbValues(sRgbValues) {}; + FrameRgbConverterParams(std::vector sRgbValues) : sRgbValues(sRgbValues) {}; - std::vector sRgbValues; //The input array containing the decimal values for the sRgb convertion + std::vector sRgbValues; //The input array containing the decimal values for the sRgb convertion }; struct TransitionTrackerParams diff --git a/src/Flash.cpp b/src/Flash.cpp index 831276f..e23ddcd 100644 --- a/src/Flash.cpp +++ b/src/Flash.cpp @@ -60,7 +60,7 @@ namespace iris return ptrFrameDiff; } - float Flash::FrameMean() + double Flash::FrameMean() { return cv::mean(*currentFrame)[0]; } @@ -74,7 +74,7 @@ namespace iris m_avgCurrentFrame = FrameMean(); } - float Flash::CheckSafeArea(cv::Mat* frameDifference) + double Flash::CheckSafeArea(cv::Mat* frameDifference) { int variation = cv::countNonZero(*frameDifference); m_flashArea = variation / (float)m_frameSize; @@ -87,10 +87,10 @@ namespace iris return 0; } - bool Flash::IsFlashTransition(const float& lastAvgDiffAcc, const float& avgDiffAcc, const float& threshold) + bool Flash::IsFlashTransition(const double& lastAvgDiffAcc, const double& avgDiffAcc, const double& threshold) { //if the luminance of the darker image is not below 0.8, no transition occurs (not applicable to red saturation) - float darkerDiff = m_avgLastFrame < m_avgCurrentFrame ? m_avgLastFrame : m_avgCurrentFrame; + double darkerDiff = m_avgLastFrame < m_avgCurrentFrame ? m_avgLastFrame : m_avgCurrentFrame; //if tendency hasn't changed, check if last avg was a transition or part of if (SameSign(lastAvgDiffAcc, avgDiffAcc) && std::abs(lastAvgDiffAcc) >= threshold) @@ -104,7 +104,7 @@ namespace iris return false; //no flash } - Flash::CheckTransitionResult Flash::CheckTransition(float avgDiff, float lastAvgDiffAcc) + Flash::CheckTransitionResult Flash::CheckTransition(double avgDiff, double lastAvgDiffAcc) { CheckTransitionResult result; result.lastAvgDiffAcc = lastAvgDiffAcc; @@ -132,9 +132,9 @@ namespace iris return result; } - float Flash::roundoff(float value, unsigned char prec) + double Flash::roundoff(double value, unsigned char prec) { - float pow_10 = std::pow(10.0f, (float)prec); + double pow_10 = std::pow(10.0, (double)prec); return std::round(value * pow_10) / pow_10; } @@ -157,42 +157,4 @@ namespace iris } } - - ///Old calculation - //float Flash::CheckSafeArea(cv::Mat* frameDifference) - //{ - // cv::Mat positiveValues(frameDifference->size(), CV_32FC1); - // cv::Mat negativeValues(frameDifference->size(), CV_32FC1); - - // cv::threshold(*frameDifference, positiveValues, 0, 320, cv::ThresholdTypes::THRESH_TOZERO); - // cv::threshold(*frameDifference, negativeValues, 0, 320, cv::ThresholdTypes::THRESH_TOZERO_INV); - // - // int posVariationArea = cv::countNonZero(positiveValues); - // int negVariationArea = cv::countNonZero(negativeValues); - - // float posVariationAverage = 0; - // float negVariationAverage = 0; - - // if (posVariationArea + negVariationArea >= m_safeArea) //minimum variation size - // { - // if (posVariationArea > 0) - // { - // posVariationAverage = (float)cv::sum(positiveValues)[0] / posVariationArea; - // } - // if (negVariationArea > 0) - // { - // negVariationAverage = (float)cv::sum(negativeValues)[0] / negVariationArea; - // } - // } - - // // Get highest abs average diff to mark tendency - // if (abs(posVariationAverage) > abs(negVariationAverage)) - // { - // return posVariationAverage; - // } - // else - // { - // return negVariationAverage; - // } - //} } diff --git a/src/Flash.h b/src/Flash.h index 45a77a0..dcf2025 100644 --- a/src/Flash.h +++ b/src/Flash.h @@ -31,7 +31,7 @@ namespace iris struct CheckTransitionResult { bool checkResult = false; - float lastAvgDiffAcc = 0; + double lastAvgDiffAcc = 0; void operator = (const CheckTransitionResult& data) { @@ -61,7 +61,7 @@ namespace iris /// /// difference of flash values as frame(n) - frame(n-1) /// average frame difference - float CheckSafeArea(cv::Mat* frameDifference); + double CheckSafeArea(cv::Mat* frameDifference); /// /// Accumulates the average difference and returns true if a new transition is detected @@ -69,16 +69,16 @@ namespace iris /// average difference of last two frames /// accumulated average difference /// - CheckTransitionResult CheckTransition(float avgDiff, float lastAvgDiffAcc); + CheckTransitionResult CheckTransition(double avgDiff, double lastAvgDiffAcc); /// /// Calculates the average frame luminance /// /// average frame - float FrameMean(); - inline float GetFrameMean() { return m_avgCurrentFrame; } + double FrameMean(); + inline double GetFrameMean() { return m_avgCurrentFrame; } - float GetFlashArea() { return m_flashArea; } + double GetFlashArea() { return m_flashArea; } cv::Mat* getCurrentFrame() { @@ -91,7 +91,7 @@ namespace iris /// /// /// - static float roundoff(float value, unsigned char prec); + static double roundoff(double value, unsigned char prec); /// /// Calculates sRGB values in the log file to later @@ -111,7 +111,7 @@ namespace iris /// /// last accumulated average difference /// new accumulated average difference - bool IsFlashTransition(const float& lastAvgDiffAcc, const float& avgDiffAcc, const float& threshold); + bool IsFlashTransition(const double& lastAvgDiffAcc, const double& avgDiffAcc, const double& threshold); cv::Mat* lastFrame = nullptr; cv::Mat* currentFrame = nullptr; @@ -120,18 +120,18 @@ namespace iris /// Returns true if both numbers are positive or negative /// 0 is both positive and negative as it means flash trend has not changed - inline bool SameSign(float num1, float num2) + inline bool SameSign(double num1, double num2) { return (num1 <= 0 && num2 <= 0) || (num1 >= 0 && num2 >= 0); } FlashParams* m_params; - std::vector m_avgDiffInSecond; //all avg diff values in the current second (by increase or decrease) + std::vector m_avgDiffInSecond; //all avg diff values in the current second (by increase or decrease) int m_safeArea = 0; //area size in pixels that, if surpassed, indicates a transition may have occurred static short fps; - float m_avgCurrentFrame = 0; - float m_avgLastFrame = 0; + double m_avgCurrentFrame = 0; + double m_avgLastFrame = 0; float m_flashArea = 0; int m_frameSize = 0; //frame width * frame height }; diff --git a/src/RedSaturation.cpp b/src/RedSaturation.cpp index 2f6a476..01fe435 100644 --- a/src/RedSaturation.cpp +++ b/src/RedSaturation.cpp @@ -21,38 +21,10 @@ namespace iris void RedSaturation::SetCurrentFrame(cv::Mat* sRgbFrame) { - cv::Mat* frame = new cv::Mat(sRgbFrame->size(), CV_32FC1, cv::Scalar(0)); - sRgbFrame->forEach(CalculateRedSaturation(frame)); + cv::Mat* frame = new cv::Mat(sRgbFrame->size(), CV_64FC1, cv::Scalar(0)); + sRgbFrame->forEach(CalculateRedSaturation(frame)); Flash::ReleaseLastFrame(); Flash::SetCurrentFrame(frame); } - - //// if R / (R + G + B) >= 0.8 => pixel is saturated red - //cv::Mat* RedSaturation::RedSaturationValue(cv::Mat channels[]) - //{ - // cv::Mat* redMask = new cv::Mat(); - - // //cv::transform(*sRgbFrame, *redMask, cv::Matx13f(1, 1, 1)); - // cv::add(channels[0], channels[1], *redMask); - // cv::add(channels[2], *redMask, *redMask); - // cv::divide(channels[2], *redMask, *redMask); - - // //if pixel >= 0.8 => pixel = 255 else pixel = 0 - // cv::threshold(*redMask, *redMask, 0.8f, 255, cv::THRESH_BINARY); - // redMask->convertTo(*redMask, CV_8UC1); - - // return redMask; - //} - - //void RedSaturation::RedSatCoefficient(cv::Mat* frame, cv::Mat channels[], cv::Mat* redMask) - //{ - // //if (R - G - B) * 320 > 20 => value to check for new transitions with frame diff - // cv::subtract(channels[2], channels[1], *frame, *redMask); - // cv::subtract(*frame, channels[0], *frame, *redMask); - // cv::multiply(*frame, 320, *frame); - - // //Negative values are set to 0 - // cv::threshold(*frame, *frame, 0, 320, cv::THRESH_TOZERO); - //} } \ No newline at end of file diff --git a/src/RedSaturation.h b/src/RedSaturation.h index e87086f..feaec05 100644 --- a/src/RedSaturation.h +++ b/src/RedSaturation.h @@ -30,37 +30,24 @@ namespace iris CalculateRedSaturation(cv::Mat* redSaturationMat) { redSat = redSaturationMat; }; cv::Mat* redSat = nullptr; - void operator()(cv::Vec3f& pixel, const int* position) const + void operator()(cv::Vec3d& pixel, const int* position) const { //if R / (R + G + B) >= 0.8 = > pixel is saturated red if (pixel[2] / (pixel[2] + pixel[1] + pixel[0]) >= 0.8f) { //if (R - G - B) * 320 > 20 => value to check for new transitions with frame diff - float red = (pixel[2] - pixel[1] - pixel[0]) * 320; + double red = (pixel[2] - pixel[1] - pixel[0]) * 320; //if negative set to 0 (default value is already 0) if (red > 0) { - redSat->ptr(position[0])[position[1]] = red; + redSat->ptr(position[0])[position[1]] = red; } } //else pixel is not red saturated (default value is already 0) } }; - /// - /// Calculates the red saturation in all the pixels of the frame - /// if R / (R + G + B) >= 0.8 => pixel is saturated red - /// - /// sRGB frame channel mats - //cv::Mat* RedSaturationValue(cv::Mat channels[]); - - /// - /// Calculates the red saturation coefficient (flash values) of the video frame in sRGB - /// - /// sRGB frame channel mats - //void RedSatCoefficient(cv::Mat* frame, cv::Mat channels[], cv::Mat* redMask); - FlashParams* m_params = nullptr; //struct with config params }; } diff --git a/src/RelativeLuminance.cpp b/src/RelativeLuminance.cpp index 30257b3..430fb99 100644 --- a/src/RelativeLuminance.cpp +++ b/src/RelativeLuminance.cpp @@ -13,7 +13,7 @@ Abstract class for Flash detection namespace iris { - cv::Scalar RelativeLuminance::rgbValues(0.0722f, 0.7152f, 0.2126f); + cv::Scalar RelativeLuminance::rgbValues(0.0722, 0.7152, 0.2126); RelativeLuminance::RelativeLuminance(short fps, const cv::Size& frameSize, FlashParams* params) : Flash(fps, frameSize, params) @@ -33,8 +33,8 @@ namespace iris /// void RelativeLuminance::SetCurrentFrame(const IrisFrame& irisFrame) { - cv::Mat* frame = new cv::Mat(irisFrame.sRgbFrame->size(), CV_32FC1); - irisFrame.sRgbFrame->forEach(ConvertToRelativeLuminance(frame)); + cv::Mat* frame = new cv::Mat(irisFrame.sRgbFrame->size(), CV_64FC1); + irisFrame.sRgbFrame->forEach(ConvertToRelativeLuminance(frame)); ReleaseLastFrame(); Flash::SetCurrentFrame(frame); @@ -42,8 +42,8 @@ namespace iris void RelativeLuminance::SetCurrentFrame(cv::Mat* bgrFrame) { - cv::Mat* frame = new cv::Mat(bgrFrame->size(), CV_32FC1); - bgrFrame->forEach(ConvertToRelativeLuminance(frame)); + cv::Mat* frame = new cv::Mat(bgrFrame->size(), CV_64FC1); + bgrFrame->forEach(ConvertToRelativeLuminance(frame)); ReleaseLastFrame(); Flash::SetCurrentFrame(frame); diff --git a/src/RelativeLuminance.h b/src/RelativeLuminance.h index bb6d435..7b2adfd 100644 --- a/src/RelativeLuminance.h +++ b/src/RelativeLuminance.h @@ -30,20 +30,21 @@ namespace iris ~RelativeLuminance(); protected: - static cv::Scalar rgbValues; struct ConvertToRelativeLuminance { ConvertToRelativeLuminance(cv::Mat* luminanceMat) { luminance = luminanceMat; }; cv::Mat* luminance = nullptr; - void operator()(cv::Vec3f& pixel, const int* position) const + void operator()(cv::Vec3d& pixel, const int* position) const { //Y = 0.0722 * B + 0.7152 * G + 0.2126 * R where B, G and R - luminance->ptr(position[0])[position[1]] = 0.0722f * pixel[0] + 0.7152f * pixel[1] + 0.2126f * pixel[2]; + luminance->ptr(position[0])[position[1]] = rgbValues[0] * pixel[0] + rgbValues[1] * pixel[1] + rgbValues[2] * pixel[2]; } }; private: + static cv::Scalar rgbValues; + }; } \ No newline at end of file diff --git a/test/Iris.Tests/include/IrisLibTest.h b/test/Iris.Tests/include/IrisLibTest.h index bafdea9..cf5b614 100644 --- a/test/Iris.Tests/include/IrisLibTest.h +++ b/test/Iris.Tests/include/IrisLibTest.h @@ -70,6 +70,11 @@ namespace iris::Tests return fabs(a - b) <= errorMargin; } + static bool CompareDouble(const double& a, const double& b, const double& errorMargin = 0.0001f) + { + return abs(a - b) <= errorMargin; + } + class IrisLibTest : public ::testing::Test { protected: Configuration configuration; diff --git a/test/Iris.Tests/src/CDLuminanceTest.cpp b/test/Iris.Tests/src/CDLuminanceTest.cpp index 1c3102b..d91b3d1 100644 --- a/test/Iris.Tests/src/CDLuminanceTest.cpp +++ b/test/Iris.Tests/src/CDLuminanceTest.cpp @@ -30,7 +30,7 @@ namespace iris::Tests cdLuminance.SetCurrentFrame(&imageBgr); cv::Mat* luminance = cdLuminance.getCurrentFrame(); - float testLum = luminance->at(0, 0); + double testLum = luminance->at(0, 0); EXPECT_EQ(200, testLum); imageBgr.release(); @@ -44,8 +44,8 @@ namespace iris::Tests cdLuminance.SetCurrentFrame(&imageBgr); cv::Mat* luminance = cdLuminance.getCurrentFrame(); - float testLum = luminance->at(0, 0); - EXPECT_EQ(0.07f, testLum); + double testLum = luminance->at(0, 0); + EXPECT_EQ(0.07, testLum); } TEST_F(CDLuminanceTest, Luminance_When_GrayFrame_Test) @@ -56,8 +56,8 @@ namespace iris::Tests cdLuminance.SetCurrentFrame(&imageBgr); cv::Mat* luminance = cdLuminance.getCurrentFrame(); - float testLum = luminance->at(0, 0); - EXPECT_EQ(46.48f, testLum); + double testLum = luminance->at(0, 0); + EXPECT_EQ(46.48, testLum); imageBgr.release(); } @@ -70,8 +70,8 @@ namespace iris::Tests cdLuminance.SetCurrentFrame(&imageBgr); cv::Mat* luminance = cdLuminance.getCurrentFrame(); - float testLum = luminance->at(0, 0); - EXPECT_EQ(2.53f, testLum); + double testLum = luminance->at(0, 0); + EXPECT_EQ(2.53, testLum); imageBgr.release(); } @@ -86,10 +86,10 @@ namespace iris::Tests cdLuminance.SetCurrentFrame(&imageBgr); cv::Mat* frameDiff = cdLuminance.FrameDifference(); - float avgDifference = cdLuminance.CheckSafeArea(frameDiff); + double avgDifference = cdLuminance.CheckSafeArea(frameDiff); EXPECT_EQ(0, avgDifference); - float flashAreaProportion = cdLuminance.GetFlashArea(); + double flashAreaProportion = cdLuminance.GetFlashArea(); EXPECT_EQ(0, flashAreaProportion); delete frameDiff; @@ -99,7 +99,7 @@ namespace iris::Tests { cv::Size size(5, 5); - float frameDiffArray[5][5] = { + double frameDiffArray[5][5] = { { 200, 200, 200, 0, 0 }, { 200, 200, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, @@ -116,11 +116,11 @@ namespace iris::Tests cv::Mat imageBgr2(size, CV_8UC3, white); cdLuminance.SetCurrentFrame(&imageBgr2); - float avgDifference = cdLuminance.CheckSafeArea(&frameDiff); + double avgDifference = cdLuminance.CheckSafeArea(&frameDiff); EXPECT_EQ(0, avgDifference); - float flashAreaProportion = cdLuminance.GetFlashArea(); - EXPECT_TRUE(CompareFloat(0.2, flashAreaProportion)); + double flashAreaProportion = cdLuminance.GetFlashArea(); + EXPECT_TRUE(CompareDouble(0.2, flashAreaProportion)); } TEST_F(CDLuminanceTest, SafeArea_100_Percent_Change_Threshold) @@ -135,10 +135,10 @@ namespace iris::Tests cdLuminance.SetCurrentFrame(&imageBgr2); cv::Mat* frameDiff = cdLuminance.FrameDifference(); - float avgDifference = cdLuminance.CheckSafeArea(frameDiff); - EXPECT_TRUE(CompareFloat(197.47, avgDifference)); + double avgDifference = cdLuminance.CheckSafeArea(frameDiff); + EXPECT_TRUE(CompareDouble(197.47, avgDifference)); - float flashAreaProportion = cdLuminance.GetFlashArea(); + double flashAreaProportion = cdLuminance.GetFlashArea(); EXPECT_EQ(1, flashAreaProportion); delete frameDiff; diff --git a/test/Iris.Tests/src/FrameRgbConverterTest.cpp b/test/Iris.Tests/src/FrameRgbConverterTest.cpp index a7e27e2..c89213e 100644 --- a/test/Iris.Tests/src/FrameRgbConverterTest.cpp +++ b/test/Iris.Tests/src/FrameRgbConverterTest.cpp @@ -26,8 +26,8 @@ namespace iris::Tests for (int y = 0; y < sRgbMat->cols; y++) { int vSource = (int)testArr[x][y]; cv::Mat* m = converter->GetTable(); - float fTarget = m->at(vSource, 0); - float fCurrent = sRgbMat->at(x, y); + double fTarget = m->at(vSource, 0); + double fCurrent = sRgbMat->at(x, y); EXPECT_EQ(fCurrent, fTarget); } } diff --git a/test/Iris.Tests/src/RedSaturationTests.cpp b/test/Iris.Tests/src/RedSaturationTests.cpp index 2102fb9..7c04fc0 100644 --- a/test/Iris.Tests/src/RedSaturationTests.cpp +++ b/test/Iris.Tests/src/RedSaturationTests.cpp @@ -21,13 +21,13 @@ namespace iris::Tests } }; - TEST_F(RedSaturationTests, Positive_FrameDifference) - { + TEST_F(RedSaturationTests, Positive_FrameDifference) + { cv::Size size(100, 100); RedSaturation redSaturation(0, size, configuration.GetRedSaturationFlashParams()); cv::Mat redImageBgr(size, CV_8UC3, red); cv::Mat* pRedSrgb = frameRgbConverter->Convert(redImageBgr); - + cv::Mat blackImageBgr(size, CV_8UC3, black); cv::Mat* pBlackSrgb = frameRgbConverter->Convert(blackImageBgr); @@ -36,21 +36,21 @@ namespace iris::Tests cv::Mat* matDiff = redSaturation.FrameDifference(); - float testChangeValues = matDiff->at(0, 0); + double testChangeValues = matDiff->at(0, 0); EXPECT_EQ(320, testChangeValues); if (matDiff != nullptr) { - matDiff->release(); - delete matDiff; + matDiff->release(); + delete matDiff; } delete pRedSrgb; delete pBlackSrgb; - } + } - TEST_F(RedSaturationTests, Negative_FrameDifference) - { + TEST_F(RedSaturationTests, Negative_FrameDifference) + { cv::Size size(2000, 2000); RedSaturation redSaturation(0, size, configuration.GetRedSaturationFlashParams()); cv::Mat redImageBgr(size, CV_8UC3, red); @@ -64,21 +64,21 @@ namespace iris::Tests cv::Mat* matDiff = redSaturation.FrameDifference(); - float testChangeValues = matDiff->at(0, 0); + double testChangeValues = matDiff->at(0, 0); EXPECT_EQ(-320, testChangeValues); if (matDiff != nullptr) { - matDiff->release(); - delete matDiff; + matDiff->release(); + delete matDiff; } delete pRedSrgb; delete pBlackSrgb; - } + } - TEST_F(RedSaturationTests, Positive_FrameDifference_PartialRed) - { + TEST_F(RedSaturationTests, Positive_FrameDifference_PartialRed) + { cv::Size size(100, 100); RedSaturation redSaturation(0, size, configuration.GetRedSaturationFlashParams()); @@ -94,20 +94,20 @@ namespace iris::Tests cv::Mat* matDiff = redSaturation.FrameDifference(); - float testChangeValues = matDiff->at(21, 21); - float testNullChangeValues = matDiff->at(0, 0); + double testChangeValues = matDiff->at(21, 21); + double testNullChangeValues = matDiff->at(0, 0); EXPECT_EQ(320, testChangeValues); EXPECT_EQ(0, testNullChangeValues); if (matDiff != nullptr) { - matDiff->release(); - delete matDiff; + matDiff->release(); + delete matDiff; } delete pRedSrgb; delete pBlackSrgb; - } + } TEST_F(RedSaturationTests, Negative_FrameDifference_PartialRed) { @@ -127,8 +127,8 @@ namespace iris::Tests cv::Mat* matDiff = redSaturation.FrameDifference(); - float testChangeValues = matDiff->at(21, 21); - float testNullChangeValues = matDiff->at(0, 0); + double testChangeValues = matDiff->at(21, 21); + double testNullChangeValues = matDiff->at(0, 0); EXPECT_EQ(-320, testChangeValues); EXPECT_EQ(0, testNullChangeValues); @@ -146,13 +146,12 @@ namespace iris::Tests { RedSaturation redSaturation (5, cv::Size(), configuration.GetRedSaturationFlashParams()); - float testLastAvg = 5.2f; - + double testLastAvg = 5.2; + //SameSign (positive) 0 case && !newTransition - Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(0, testLastAvg); - EXPECT_EQ(5.2f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(5.2, transitionResult.lastAvgDiffAcc); EXPECT_FALSE(transitionResult.checkResult); } @@ -160,14 +159,12 @@ namespace iris::Tests { RedSaturation redSaturation(5, cv::Size(), configuration.GetRedSaturationFlashParams()); - - float testLastAvg = 5.2f; + double testLastAvg = 5.2; //SameSign (positive) && !newTransition + Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(10.0, testLastAvg); - Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(10.0f, testLastAvg); - - EXPECT_EQ(15.2f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(15.2, transitionResult.lastAvgDiffAcc); EXPECT_FALSE(transitionResult.checkResult); } @@ -175,14 +172,12 @@ namespace iris::Tests { RedSaturation redSaturation(5, cv::Size(), configuration.GetRedSaturationFlashParams()); - - float testLastAvg = 15.2f; + double testLastAvg = 15.2; //SameSign (positive) && newTransition + Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(5.0, testLastAvg); - Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(5.0f, testLastAvg); - - EXPECT_EQ(20.2f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(20.2, transitionResult.lastAvgDiffAcc); EXPECT_TRUE(transitionResult.checkResult); } @@ -190,14 +185,12 @@ namespace iris::Tests { RedSaturation redSaturation(5, cv::Size(), configuration.GetRedSaturationFlashParams()); - - float testLastAvg = 20.2f; + double testLastAvg = 20.2; //SameSign (positive) && !newTransition (last was a transition) + Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(10.3, testLastAvg); - Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(10.3f, testLastAvg); - - EXPECT_EQ(30.5f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(30.5, transitionResult.lastAvgDiffAcc); EXPECT_FALSE(transitionResult.checkResult); } @@ -205,14 +198,12 @@ namespace iris::Tests { RedSaturation redSaturation(5, cv::Size(), configuration.GetRedSaturationFlashParams()); - - float testLastAvg = 30.5f; + double testLastAvg = 30.5; //!SameSign (negative) && newTransition + Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(-20.0, testLastAvg); - Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(-20.0f, testLastAvg); - - EXPECT_EQ(-20.0f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(-20.0, transitionResult.lastAvgDiffAcc); EXPECT_TRUE(transitionResult.checkResult); } @@ -220,14 +211,12 @@ namespace iris::Tests { RedSaturation redSaturation(5, cv::Size(), configuration.GetRedSaturationFlashParams()); - - float testLastAvg = -20.0f; + double testLastAvg = -20.0; //SameSign (positive) && !newTransition (last was a transition) + Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(25.0, testLastAvg); - Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(25.0f, testLastAvg); - - EXPECT_EQ(25.0f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(25.0, transitionResult.lastAvgDiffAcc); EXPECT_TRUE(transitionResult.checkResult); } @@ -235,29 +224,25 @@ namespace iris::Tests { RedSaturation redSaturation(5, cv::Size(), configuration.GetRedSaturationFlashParams()); - - float testLastAvg = 25.0f; + double testLastAvg = 25.0; //!SameSign (negative) && !newTransition + Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(-10.0, testLastAvg); - Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(-10.0f, testLastAvg); - - EXPECT_EQ(-10.0f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(-10.0, transitionResult.lastAvgDiffAcc); EXPECT_FALSE(transitionResult.checkResult); } TEST_F(RedSaturationTests, CheckTransition_Negative_Value_To_Zero) { RedSaturation redSaturation(5, cv::Size(), configuration.GetRedSaturationFlashParams()); - - float testLastAvg = -10.0f; + double testLastAvg = -10.0; //SameSign (negative) 0 case && !newTransition + Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(0.0, testLastAvg); - Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(0.0f, testLastAvg); - - EXPECT_EQ(-10.0f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(-10.0, transitionResult.lastAvgDiffAcc); EXPECT_FALSE(transitionResult.checkResult); } @@ -265,12 +250,12 @@ namespace iris::Tests { RedSaturation redSaturation(5, cv::Size(), configuration.GetRedSaturationFlashParams()); - float testLastAvg = -10.0f; + double testLastAvg = -10.0; //SameSign (negative) && newTransition - Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(-15.0f, testLastAvg); + Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(-15.0, testLastAvg); - EXPECT_EQ(-25.0f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(-25.0, transitionResult.lastAvgDiffAcc); EXPECT_TRUE(transitionResult.checkResult); } @@ -279,13 +264,13 @@ namespace iris::Tests RedSaturation redSaturation(5, cv::Size(), configuration.GetRedSaturationFlashParams()); - float testLastAvg = -25.0f; + double testLastAvg = -25.0; //SameSign (negative) && !newTransition (last was a transition) - Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(-30.6f, testLastAvg); + Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(-30.6, testLastAvg); - EXPECT_EQ(-55.6f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(-55.6, transitionResult.lastAvgDiffAcc); EXPECT_FALSE(transitionResult.checkResult); } @@ -293,15 +278,14 @@ namespace iris::Tests { RedSaturation redSaturation(2, cv::Size(), configuration.GetRedSaturationFlashParams()); - float testLastAvg = 0.0f; + double testLastAvg = 0.0; //SameSign (negative) && !newTransition (last was a transition) + Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(-25.6, testLastAvg); + transitionResult = redSaturation.CheckTransition(-30.6, transitionResult.lastAvgDiffAcc); + transitionResult = redSaturation.CheckTransition(-10.6, transitionResult.lastAvgDiffAcc); - Flash::CheckTransitionResult transitionResult = redSaturation.CheckTransition(-25.6f, testLastAvg); - transitionResult = redSaturation.CheckTransition(-30.6f, transitionResult.lastAvgDiffAcc); - transitionResult = redSaturation.CheckTransition(-10.6f, transitionResult.lastAvgDiffAcc); - - EXPECT_EQ(-41.2f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(-41.2, transitionResult.lastAvgDiffAcc); EXPECT_FALSE(transitionResult.checkResult); } @@ -317,10 +301,10 @@ namespace iris::Tests redSaturation.SetCurrentFrame(imageSbgr); cv::Mat* frameDiff = redSaturation.FrameDifference(); - float avgDifference = redSaturation.CheckSafeArea(frameDiff); + double avgDifference = redSaturation.CheckSafeArea(frameDiff); EXPECT_EQ(0, avgDifference); - float flashAreaProportion = redSaturation.GetFlashArea(); + double flashAreaProportion = redSaturation.GetFlashArea(); EXPECT_EQ(0, flashAreaProportion); delete imageSbgr; @@ -331,7 +315,7 @@ namespace iris::Tests { cv::Size size(5, 5); - float frameDiffArray[5][5] = { + double frameDiffArray[5][5] = { { 200, 200, 200, 0, 0 }, { 200, 200, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, @@ -350,11 +334,11 @@ namespace iris::Tests cv::Mat* imageSbgr2 = frameRgbConverter->Convert(imageBgr2); redSaturation.SetCurrentFrame(imageSbgr2); - float avgDifference = redSaturation.CheckSafeArea(&frameDiff); + double avgDifference = redSaturation.CheckSafeArea(&frameDiff); EXPECT_EQ(0, avgDifference); - float flashAreaProportion = redSaturation.GetFlashArea(); - EXPECT_TRUE(CompareFloat(0.2, flashAreaProportion)); + double flashAreaProportion = redSaturation.GetFlashArea(); + EXPECT_TRUE(CompareDouble(0.2, flashAreaProportion)); delete imageSbgr; delete imageSbgr2; @@ -374,10 +358,10 @@ namespace iris::Tests redSaturation.SetCurrentFrame(imageSbgr2); cv::Mat* frameDiff = redSaturation.FrameDifference(); - float avgDifference = redSaturation.CheckSafeArea(frameDiff); + double avgDifference = redSaturation.CheckSafeArea(frameDiff); EXPECT_EQ(320, avgDifference); - float flashAreaProportion = redSaturation.GetFlashArea(); + double flashAreaProportion = redSaturation.GetFlashArea(); EXPECT_EQ(1, flashAreaProportion); delete imageSbgr; diff --git a/test/Iris.Tests/src/RelativeLuminanceTest.cpp b/test/Iris.Tests/src/RelativeLuminanceTest.cpp index 2a7a710..272fb4d 100644 --- a/test/Iris.Tests/src/RelativeLuminanceTest.cpp +++ b/test/Iris.Tests/src/RelativeLuminanceTest.cpp @@ -34,7 +34,7 @@ namespace iris::Tests relativeLuminance.SetCurrentFrame(imagesRgb); cv::Mat* luminance = relativeLuminance.getCurrentFrame(); - float testLum = luminance->at(0, 0); + double testLum = luminance->at(0, 0); EXPECT_EQ(1, testLum); imagesRgb.Release(); @@ -51,7 +51,7 @@ namespace iris::Tests relativeLuminance.SetCurrentFrame(imagesRgb); cv::Mat* luminance = relativeLuminance.getCurrentFrame(); - float testLum = luminance->at(0, 0); + double testLum = luminance->at(0, 0); EXPECT_EQ(0, testLum); imagesRgb.Release(); @@ -68,9 +68,9 @@ namespace iris::Tests relativeLuminance.SetCurrentFrame(imagesRgb); cv::Mat* luminance = relativeLuminance.getCurrentFrame(); - float testLum = luminance->at(0, 0); + double testLum = luminance->at(0, 0); testLum = RelativeLuminance::roundoff(testLum, 3); - EXPECT_EQ(0.216f, testLum); + EXPECT_EQ(0.216, testLum); imagesRgb.Release(); } @@ -86,9 +86,9 @@ namespace iris::Tests relativeLuminance.SetCurrentFrame(imagesRgb); cv::Mat* luminance = relativeLuminance.getCurrentFrame(); - float testLum = luminance->at(0, 0); + double testLum = luminance->at(0, 0); testLum = RelativeLuminance::roundoff(testLum, 3); - EXPECT_EQ(0.072f, testLum); + EXPECT_EQ(0.072, testLum); imagesRgb.Release(); } @@ -107,7 +107,7 @@ namespace iris::Tests relativeLuminance.SetCurrentFrame(pImagesBlackRgb); relativeLuminance.SetCurrentFrame(pImageWhitesRgb); cv::Mat* diff = relativeLuminance.FrameDifference(); - float testLum = diff->at(0, 0); + double testLum = diff->at(0, 0); EXPECT_EQ(1, testLum); delete diff; @@ -129,7 +129,7 @@ namespace iris::Tests relativeLuminance.SetCurrentFrame(pImageWhitesRgb); relativeLuminance.SetCurrentFrame(pImagesBlackRgb); cv::Mat* diff = relativeLuminance.FrameDifference(); - float testLum = diff->at(0, 0); + double testLum = diff->at(0, 0); EXPECT_EQ(-1, testLum); delete diff; @@ -152,7 +152,7 @@ namespace iris::Tests relativeLuminance.SetCurrentFrame(pImagesBlackRgb); relativeLuminance.SetCurrentFrame(pImagesBlackRgb); cv::Mat* diff = relativeLuminance.FrameDifference(); - float testLum = diff->at(0, 0); + double testLum = diff->at(0, 0); EXPECT_EQ(0, testLum); delete diff; @@ -163,138 +163,138 @@ namespace iris::Tests TEST_F(RelativeLuminanceTest,CheckTransition_WhenFalse_From_value_to_zero_Test) { RelativeLuminance relativeLuminance(5, cv::Size(), configuration.GetLuminanceFlashParams()); - float testLastAvg = 0.02f; + double testLastAvg = 0.02; //SameSign (positive) 0 case && !newTransition Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(0, testLastAvg); EXPECT_FALSE(transitionResult.checkResult); - EXPECT_EQ(0.02f, transitionResult.lastAvgDiffAcc); + EXPECT_EQ(0.02, transitionResult.lastAvgDiffAcc); } TEST_F(RelativeLuminanceTest, CheckTransition_WhenFalse_From_value_to_value_Test) { RelativeLuminance relativeLuminance(5, cv::Size(), configuration.GetLuminanceFlashParams()); - float testLastAvg = 0.02f; + double testLastAvg = 0.02; //SameSign (positive) 0 case && !newTransition Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(0.05f, testLastAvg); EXPECT_FALSE(transitionResult.checkResult); - EXPECT_EQ(0.07f, transitionResult.lastAvgDiffAcc); + EXPECT_TRUE(CompareDouble(0.07, transitionResult.lastAvgDiffAcc)); } TEST_F(RelativeLuminanceTest, CheckTransition_WhenTrue_From_value_to_value_Test) { RelativeLuminance relativeLuminance(5, cv::Size(), configuration.GetLuminanceFlashParams()); - float testLastAvg = 0.07f; + double testLastAvg = 0.07; //SameSign (positive) 0 case && !newTransition - Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(0.03f, testLastAvg); + Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(0.03, testLastAvg); EXPECT_TRUE(transitionResult.checkResult); - EXPECT_EQ(0.1f, transitionResult.lastAvgDiffAcc); + EXPECT_TRUE(CompareDouble(0.1, transitionResult.lastAvgDiffAcc)); } - TEST_F(RelativeLuminanceTest, CheckTransition_WhenFalse_From_threshold_value_to_value_Test) - { + TEST_F(RelativeLuminanceTest, CheckTransition_WhenFalse_From_threshold_value_to_value_Test) + { RelativeLuminance relativeLuminance(5, cv::Size(), configuration.GetLuminanceFlashParams()); - float testLastAvg = 0.1f; + double testLastAvg = 0.1; //SameSign (positive) 0 case && !newTransition - Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(0.1f, testLastAvg); + Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(0.1, testLastAvg); EXPECT_FALSE(transitionResult.checkResult); - EXPECT_EQ(0.2f, transitionResult.lastAvgDiffAcc); - } + EXPECT_TRUE(CompareDouble(0.2, transitionResult.lastAvgDiffAcc)); + } - TEST_F(RelativeLuminanceTest, CheckTransition_WhenTrue_From_value_to_negative_value_Test) - { + TEST_F(RelativeLuminanceTest, CheckTransition_WhenTrue_From_value_to_negative_value_Test) + { RelativeLuminance relativeLuminance(5, cv::Size(), configuration.GetLuminanceFlashParams()); - float testLastAvg = 0.2f; + double testLastAvg = 0.2; //SameSign (positive) 0 case && !newTransition - Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(-0.1f, testLastAvg); + Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(-0.1, testLastAvg); EXPECT_TRUE(transitionResult.checkResult); - EXPECT_EQ(-0.1f, transitionResult.lastAvgDiffAcc); - } + EXPECT_TRUE(CompareDouble(- 0.1, transitionResult.lastAvgDiffAcc)); + } - TEST_F(RelativeLuminanceTest, CheckTransition_WhenTrue_From_negative_value_to_value_Test) - { + TEST_F(RelativeLuminanceTest, CheckTransition_WhenTrue_From_negative_value_to_value_Test) + { RelativeLuminance relativeLuminance(5, cv::Size(), configuration.GetLuminanceFlashParams()); - float testLastAvg = -0.1f; + double testLastAvg = -0.1; //SameSign (positive) 0 case && !newTransition - Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(0.1f, testLastAvg); + Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(0.1, testLastAvg); EXPECT_TRUE(transitionResult.checkResult); - EXPECT_EQ(0.1f, transitionResult.lastAvgDiffAcc); - } + EXPECT_TRUE(CompareDouble(0.1, transitionResult.lastAvgDiffAcc)); + } - TEST_F(RelativeLuminanceTest, CheckTransition_WhenFalse_From_value_to_negative_value_Test) - { + TEST_F(RelativeLuminanceTest, CheckTransition_WhenFalse_From_value_to_negative_value_Test) + { RelativeLuminance relativeLuminance(5, cv::Size(), configuration.GetLuminanceFlashParams()); - float testLastAvg = 0.1f; + double testLastAvg = 0.1; //SameSign (positive) 0 case && !newTransition - Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(-0.05f, testLastAvg); + Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(-0.05, testLastAvg); EXPECT_FALSE(transitionResult.checkResult); - EXPECT_EQ(-0.05f, transitionResult.lastAvgDiffAcc); - } + EXPECT_EQ(-0.05, transitionResult.lastAvgDiffAcc); + } - TEST_F(RelativeLuminanceTest, CheckTransition_WhenFalse_From_negative_value_to_zero_Test) - { + TEST_F(RelativeLuminanceTest, CheckTransition_WhenFalse_From_negative_value_to_zero_Test) + { RelativeLuminance relativeLuminance(5, cv::Size(), configuration.GetLuminanceFlashParams()); - float testLastAvg = -0.05f; + double testLastAvg = -0.05; //SameSign (positive) 0 case && !newTransition Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(0, testLastAvg); EXPECT_FALSE(transitionResult.checkResult); - EXPECT_EQ(-0.05f, transitionResult.lastAvgDiffAcc); - } + EXPECT_EQ(-0.05, transitionResult.lastAvgDiffAcc); + } - TEST_F(RelativeLuminanceTest, CheckTransition_WhenTrue_From_negative_value_to_negative_value_Test) - { + TEST_F(RelativeLuminanceTest, CheckTransition_WhenTrue_From_negative_value_to_negative_value_Test) + { RelativeLuminance relativeLuminance(5, cv::Size(), configuration.GetLuminanceFlashParams()); - float testLastAvg = -0.05f; + double testLastAvg = -0.05; //SameSign (positive) 0 case && !newTransition - Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(-0.06f, testLastAvg); + Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(-0.06, testLastAvg); EXPECT_TRUE(transitionResult.checkResult); - EXPECT_EQ(-0.11f, transitionResult.lastAvgDiffAcc); - } + EXPECT_EQ(-0.11, transitionResult.lastAvgDiffAcc); + } - TEST_F(RelativeLuminanceTest, CheckTransition_WhenFalse_From_negative_threshold_value_to_negative_value_Test) - { + TEST_F(RelativeLuminanceTest, CheckTransition_WhenFalse_From_negative_threshold_value_to_negative_value_Test) + { RelativeLuminance relativeLuminance(5, cv::Size(), configuration.GetLuminanceFlashParams()); - float testLastAvg = -0.11f; + double testLastAvg = -0.11; //SameSign (positive) 0 case && !newTransition - Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(-0.1f, testLastAvg); + Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(-0.1, testLastAvg); EXPECT_FALSE(transitionResult.checkResult); - EXPECT_EQ(-0.21f, Flash::roundoff(transitionResult.lastAvgDiffAcc, 2)); - } + EXPECT_EQ(-0.21, Flash::roundoff(transitionResult.lastAvgDiffAcc, 2)); + } - TEST_F(RelativeLuminanceTest, CheckTransition_WhenFalse_From_zero_to_negative_threshold_value_to_negative_threshold_value_Test) - { + TEST_F(RelativeLuminanceTest, CheckTransition_WhenFalse_From_zero_to_negative_threshold_value_to_negative_threshold_value_Test) + { RelativeLuminance relativeLuminance(2, cv::Size(), configuration.GetLuminanceFlashParams()); - float testLastAvg = 0; + double testLastAvg = 0; //SameSign (positive) 0 case && !newTransition - Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(-0.11f, testLastAvg); + Flash::CheckTransitionResult transitionResult = relativeLuminance.CheckTransition(-0.11, testLastAvg); testLastAvg = transitionResult.lastAvgDiffAcc; - transitionResult = relativeLuminance.CheckTransition(-0.1f, testLastAvg); + transitionResult = relativeLuminance.CheckTransition(-0.1, testLastAvg); testLastAvg = transitionResult.lastAvgDiffAcc; - transitionResult = relativeLuminance.CheckTransition(-0.1f, testLastAvg); + transitionResult = relativeLuminance.CheckTransition(-0.1, testLastAvg); EXPECT_FALSE(transitionResult.checkResult); - EXPECT_EQ(-0.2f, Flash::roundoff(transitionResult.lastAvgDiffAcc, 2)); - } + EXPECT_EQ(-0.2, Flash::roundoff(transitionResult.lastAvgDiffAcc, 2)); + } TEST_F(RelativeLuminanceTest, AverageLuminanca_WhenWhite_Test) { @@ -304,39 +304,39 @@ namespace iris::Tests pImageWhitesRgb.sRgbFrame = frameRgbConverter->Convert(imageWhiteBgr); relativeLuminance.SetCurrentFrame(pImageWhitesRgb); - float avgLum = relativeLuminance.FrameMean(); + double avgLum = relativeLuminance.FrameMean(); EXPECT_EQ(1, avgLum); pImageWhitesRgb.Release(); } - TEST_F(RelativeLuminanceTest, AverageLuminanca_WhenGray_Test) - { - RelativeLuminance relativeLuminance(3, cv::Size(), configuration.GetLuminanceFlashParams()); - cv::Mat imageWhiteBgr(1280, 720, CV_8UC3, gray); - IrisFrame pImageWhitesRgb; - pImageWhitesRgb.sRgbFrame = frameRgbConverter->Convert(imageWhiteBgr); + TEST_F(RelativeLuminanceTest, AverageLuminanca_WhenGray_Test) + { + RelativeLuminance relativeLuminance(3, cv::Size(), configuration.GetLuminanceFlashParams()); + cv::Mat imageWhiteBgr(1280, 720, CV_8UC3, gray); + IrisFrame pImageWhitesRgb; + pImageWhitesRgb.sRgbFrame = frameRgbConverter->Convert(imageWhiteBgr); - relativeLuminance.SetCurrentFrame(pImageWhitesRgb); - float avgLum = relativeLuminance.roundoff(relativeLuminance.FrameMean(), 2); - EXPECT_EQ(0.22f, avgLum); + relativeLuminance.SetCurrentFrame(pImageWhitesRgb); + double avgLum = relativeLuminance.roundoff(relativeLuminance.FrameMean(), 2); + EXPECT_EQ(0.22, avgLum); - pImageWhitesRgb.Release(); - } + pImageWhitesRgb.Release(); + } - TEST_F(RelativeLuminanceTest, AverageLuminanca_WhenRealFrame_Test) - { - RelativeLuminance relativeLuminance(3, cv::Size(), configuration.GetLuminanceFlashParams()); - cv::Mat frameBgr = cv::imread("data/TestImages/frames/FrameForTest.jpg"); - IrisFrame pFramesRgb; - pFramesRgb.sRgbFrame = frameRgbConverter->Convert(frameBgr); + TEST_F(RelativeLuminanceTest, AverageLuminanca_WhenRealFrame_Test) + { + RelativeLuminance relativeLuminance(3, cv::Size(), configuration.GetLuminanceFlashParams()); + cv::Mat frameBgr = cv::imread("data/TestImages/frames/FrameForTest.jpg"); + IrisFrame pFramesRgb; + pFramesRgb.sRgbFrame = frameRgbConverter->Convert(frameBgr); - relativeLuminance.SetCurrentFrame(pFramesRgb); - float avgLum = relativeLuminance.roundoff(relativeLuminance.FrameMean(), 2); - EXPECT_EQ(0.33f, avgLum); + relativeLuminance.SetCurrentFrame(pFramesRgb); + double avgLum = relativeLuminance.roundoff(relativeLuminance.FrameMean(), 2); + EXPECT_EQ(0.33, avgLum); - pFramesRgb.Release(); - } + pFramesRgb.Release(); + } TEST_F(RelativeLuminanceTest, SafeArea_No_Change_Threshold) { @@ -350,10 +350,10 @@ namespace iris::Tests luminance.SetCurrentFrame(imageSbgr); cv::Mat* frameDiff = luminance.FrameDifference(); - float avgDifference = luminance.CheckSafeArea(frameDiff); + double avgDifference = luminance.CheckSafeArea(frameDiff); EXPECT_EQ(0, avgDifference); - float flashAreaProportion = luminance.GetFlashArea(); + double flashAreaProportion = luminance.GetFlashArea(); EXPECT_EQ(0, flashAreaProportion); delete imageSbgr; @@ -364,7 +364,7 @@ namespace iris::Tests { cv::Size size(5, 5); - float frameDiffArray[5][5] = { + double frameDiffArray[5][5] = { { 200, 200, 200, 0, 0 }, { 200, 200, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, @@ -383,11 +383,11 @@ namespace iris::Tests cv::Mat* imageSbgr2 = frameRgbConverter->Convert(imageBgr2); luminance.SetCurrentFrame(imageSbgr2); - float avgDifference = luminance.CheckSafeArea(&frameDiff); + double avgDifference = luminance.CheckSafeArea(&frameDiff); EXPECT_EQ(0, avgDifference); - float flashAreaProportion = luminance.GetFlashArea(); - EXPECT_TRUE(CompareFloat(0.2, flashAreaProportion)); + double flashAreaProportion = luminance.GetFlashArea(); + EXPECT_TRUE(CompareDouble(0.2, flashAreaProportion)); delete imageSbgr; delete imageSbgr2; @@ -407,10 +407,10 @@ namespace iris::Tests luminance.SetCurrentFrame(imageSbgr2); cv::Mat* frameDiff = luminance.FrameDifference(); - float avgDifference = luminance.CheckSafeArea(frameDiff); - EXPECT_TRUE(CompareFloat(0.9278, avgDifference)); + double avgDifference = luminance.CheckSafeArea(frameDiff); + EXPECT_TRUE(CompareDouble(0.9278, avgDifference)); - float flashAreaProportion = luminance.GetFlashArea(); + double flashAreaProportion = luminance.GetFlashArea(); EXPECT_EQ(1, flashAreaProportion); delete imageSbgr; diff --git a/utils/include/utils/FrameConverter.h b/utils/include/utils/FrameConverter.h index ffb0f9d..1c113fd 100644 --- a/utils/include/utils/FrameConverter.h +++ b/utils/include/utils/FrameConverter.h @@ -15,8 +15,8 @@ namespace EA::EACC::Utils { struct FrameConverterParams { - FrameConverterParams(std::vector values) : values(values) {}; - std::vector values; //The input array containing the values for the convertion + FrameConverterParams(std::vector values) : values(values) {}; + std::vector values; //The input array containing the values for the convertion }; class FrameConverter @@ -26,7 +26,7 @@ namespace EA::EACC::Utils /// Create an instance of the Rgb converter /// /// The array of decimal values for Bgr to sRgb convertion - FrameConverter(std::vector& c); + FrameConverter(std::vector& c); /// /// Create an instance of the Rgb converter diff --git a/utils/src/FrameConverter.cpp b/utils/src/FrameConverter.cpp index 3ac6b3c..743d1df 100644 --- a/utils/src/FrameConverter.cpp +++ b/utils/src/FrameConverter.cpp @@ -5,7 +5,7 @@ namespace EA::EACC::Utils { - FrameConverter::FrameConverter(std::vector& sRgbValues) + FrameConverter::FrameConverter(std::vector& sRgbValues) { m_pMatValues = new cv::Mat(sRgbValues, true); }