Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macOS to the pipeline #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
28 changes: 14 additions & 14 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,33 @@ namespace iris
if (m_luminanceType == LuminanceType::CD)
{
m_luminanceFlashParams = new FlashParams(
jsonFile.GetParam<float>("Luminance", "CdLuminanceFlashThreshold"),
jsonFile.GetParam<float>("FlashDetection", "AreaProportion"),
jsonFile.GetParam<float>("Luminance", "CdDarkLuminanceThreshold"));
jsonFile.GetParam<double>("Luminance", "CdLuminanceFlashThreshold"),
jsonFile.GetParam<double>("FlashDetection", "AreaProportion"),
jsonFile.GetParam<double>("Luminance", "CdDarkLuminanceThreshold"));
}
else
{
m_luminanceFlashParams = new FlashParams(
jsonFile.GetParam<float>("Luminance", "RelativeLuminanceFlashThreshold"),
jsonFile.GetParam<float>("FlashDetection", "AreaProportion"),
jsonFile.GetParam<float>("Luminance", "RelativeDarkLuminanceThreshold"));
jsonFile.GetParam<double>("Luminance", "RelativeLuminanceFlashThreshold"),
jsonFile.GetParam<double>("FlashDetection", "AreaProportion"),
jsonFile.GetParam<double>("Luminance", "RelativeDarkLuminanceThreshold"));
}

//Red Saturation
m_redSaturationFlashParams = new FlashParams(
jsonFile.GetParam<float>("RedSaturation", "FlashThreshold"),
jsonFile.GetParam<float>("FlashDetection", "AreaProportion"),
jsonFile.GetParam<float>("RedSaturation", "RedDarkThreshold"));
jsonFile.GetParam<double>("RedSaturation", "FlashThreshold"),
jsonFile.GetParam<double>("FlashDetection", "AreaProportion"),
jsonFile.GetParam<double>("RedSaturation", "RedDarkThreshold"));

//FrameRgbConverter Params
m_frameSrgbConverterParams = new EA::EACC::Utils::FrameConverterParams(
jsonFile.GetVector<float>("FlashDetection", "sRGBValues"));
jsonFile.GetVector<double>("FlashDetection", "sRGBValues"));

//FrameRgbConverter Params for CD Luminance conversion
if (m_luminanceType == LuminanceType::CD)
{
m_frameCDLuminanceConverterParams = new EA::EACC::Utils::FrameConverterParams(
jsonFile.GetVector<float>("Luminance", "CdLuminanceValues"));
jsonFile.GetVector<double>("Luminance", "CdLuminanceValues"));
}

//Transition Tracker Params
Expand All @@ -107,15 +107,15 @@ namespace iris

//Pattern Detection
int minStripes = jsonFile.GetParam<int>("PatternDetection", "MinStripes");
float darkLumThreshold = 0.0f;
double darkLumThreshold = 0.0f;

if (m_luminanceType == LuminanceType::CD)
{
darkLumThreshold = jsonFile.GetParam<float>("PatternDetection", "CDDarkLuminanceThreshold");
darkLumThreshold = jsonFile.GetParam<double>("PatternDetection", "CDDarkLuminanceThreshold");
}
else
{
darkLumThreshold = jsonFile.GetParam<float>("PatternDetection", "RelativeDarkLuminanceThreshold");
darkLumThreshold = jsonFile.GetParam<double>("PatternDetection", "RelativeDarkLuminanceThreshold");
}

m_patternDetectionParams = new PatternDetectionParams(
Expand Down
12 changes: 6 additions & 6 deletions src/ConfigurationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> sRgbValues) : sRgbValues(sRgbValues) {};
FrameRgbConverterParams(std::vector<double> sRgbValues) : sRgbValues(sRgbValues) {};

std::vector<float> sRgbValues; //The input array containing the decimal values for the sRgb convertion
std::vector<double> sRgbValues; //The input array containing the decimal values for the sRgb convertion
};

struct TransitionTrackerParams
Expand Down
52 changes: 7 additions & 45 deletions src/Flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace iris
return ptrFrameDiff;
}

float Flash::FrameMean()
double Flash::FrameMean()
{
return cv::mean(*currentFrame)[0];
}
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
// }
//}
}
24 changes: 12 additions & 12 deletions src/Flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace iris
struct CheckTransitionResult
{
bool checkResult = false;
float lastAvgDiffAcc = 0;
double lastAvgDiffAcc = 0;

void operator = (const CheckTransitionResult& data)
{
Expand Down Expand Up @@ -61,24 +61,24 @@ namespace iris
/// </summary>
/// <param name="frameDifference">difference of flash values as frame(n) - frame(n-1)</param>
/// <returns>average frame difference</returns>
float CheckSafeArea(cv::Mat* frameDifference);
double CheckSafeArea(cv::Mat* frameDifference);

/// <summary>
/// Accumulates the average difference and returns true if a new transition is detected
/// </summary>
/// <param name="avgDiff">average difference of last two frames</param>
/// <param name="lastAvgDiffAcc">accumulated average difference</param>
/// <returns></returns>
CheckTransitionResult CheckTransition(float avgDiff, float lastAvgDiffAcc);
CheckTransitionResult CheckTransition(double avgDiff, double lastAvgDiffAcc);

/// <summary>
/// Calculates the average frame luminance
/// </summary>
/// <returns>average frame</returns>
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() {
Expand All @@ -91,7 +91,7 @@ namespace iris
/// <param name="value"></param>
/// <param name="prec"></param>
/// <returns></returns>
static float roundoff(float value, unsigned char prec);
static double roundoff(double value, unsigned char prec);

/// <summary>
/// Calculates sRGB values in the log file to later
Expand All @@ -111,7 +111,7 @@ namespace iris
/// </summary>
/// <param name="lastAvgDiffAcc">last accumulated average difference</param>
/// <param name="avgDiffAcc">new accumulated average difference</param>
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;
Expand All @@ -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<float> m_avgDiffInSecond; //all avg diff values in the current second (by increase or decrease)
std::vector<double> 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
};
Expand Down
32 changes: 2 additions & 30 deletions src/RedSaturation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<cv::Vec3f>(CalculateRedSaturation(frame));
cv::Mat* frame = new cv::Mat(sRgbFrame->size(), CV_64FC1, cv::Scalar(0));
sRgbFrame->forEach<cv::Vec3d>(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);
//}
}
19 changes: 3 additions & 16 deletions src/RedSaturation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(position[0])[position[1]] = red;
redSat->ptr<double>(position[0])[position[1]] = red;
}

} //else pixel is not red saturated (default value is already 0)
}
};

/// <summary>
/// Calculates the red saturation in all the pixels of the frame
/// if R / (R + G + B) >= 0.8 => pixel is saturated red
/// </summary>
/// <param name="channels">sRGB frame channel mats</param>
//cv::Mat* RedSaturationValue(cv::Mat channels[]);

/// <summary>
/// Calculates the red saturation coefficient (flash values) of the video frame in sRGB
/// </summary>
/// <param name="channels">sRGB frame channel mats</param>
//void RedSatCoefficient(cv::Mat* frame, cv::Mat channels[], cv::Mat* redMask);

FlashParams* m_params = nullptr; //struct with config params
};
}
Loading
Loading