mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Rework pattern count temp var
This commit is contained in:
parent
e76de98234
commit
dcb8a727a3
|
|
@ -283,10 +283,18 @@ bool MacroConditionVideo::ScreenshotContainsPattern()
|
|||
SetTempVarValue("patternCount", "0");
|
||||
return false;
|
||||
}
|
||||
const auto count = countNonZero(result);
|
||||
|
||||
SetTempVarValue("similarity", std::to_string(bestMatchValue));
|
||||
SetTempVarValue("patternCount", std::to_string(count));
|
||||
return count > 0;
|
||||
|
||||
if (IsTempVarInUse("patternCount")) {
|
||||
const auto count = CountPatternMatches(
|
||||
result, {_patternImageData.rgbaPattern.cols,
|
||||
_patternImageData.rgbaPattern.rows});
|
||||
SetTempVarValue("patternCount", std::to_string(count));
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
return countNonZero(result) > 0;
|
||||
}
|
||||
|
||||
bool MacroConditionVideo::FileInputIsUpToDate() const
|
||||
|
|
|
|||
|
|
@ -97,6 +97,35 @@ double MatchPattern(QImage &img, const PatternImageData &patternData,
|
|||
return bestFitValue;
|
||||
}
|
||||
|
||||
int CountPatternMatches(const cv::Mat &result, const cv::Size &patternSize)
|
||||
{
|
||||
if (result.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
cv::Mat work = result.clone();
|
||||
int count = 0;
|
||||
|
||||
while (true) {
|
||||
double maxVal;
|
||||
cv::Point maxLoc;
|
||||
cv::minMaxLoc(work, nullptr, &maxVal, nullptr, &maxLoc);
|
||||
if (maxVal <= 0.0) {
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
// Suppress the template-sized region around this match so
|
||||
// overlapping high-scoring positions are not counted separately
|
||||
int x = std::max(0, maxLoc.x - patternSize.width / 2);
|
||||
int y = std::max(0, maxLoc.y - patternSize.height / 2);
|
||||
int w = std::min(patternSize.width, work.cols - x);
|
||||
int h = std::min(patternSize.height, work.rows - y);
|
||||
work(cv::Rect(x, y, w, h)) = 0.0f;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
double MatchPattern(QImage &img, QImage &pattern, double threshold,
|
||||
cv::Mat &result, bool useAlphaAsMask,
|
||||
cv::TemplateMatchModes matchColor)
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ double MatchPattern(QImage &img, const PatternImageData &patternData,
|
|||
double MatchPattern(QImage &img, QImage &pattern, double threshold,
|
||||
cv::Mat &result, bool useAlphaAsMask,
|
||||
cv::TemplateMatchModes matchMode);
|
||||
int CountPatternMatches(const cv::Mat &result, const cv::Size &patternSize);
|
||||
std::vector<cv::Rect> MatchObject(QImage &img, cv::CascadeClassifier &cascade,
|
||||
double scaleFactor, int minNeighbors,
|
||||
const cv::Size &minSize,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user