Expose "Similarity Rating" as temp var when pattern matching

This commit is contained in:
WarmUpTill
2026-02-21 21:37:27 +01:00
committed by WarmUpTill
parent f35ef558ee
commit d6ea815b85
6 changed files with 58 additions and 39 deletions

View File

@@ -48,20 +48,18 @@ static void preprocessPatternMatchResult(cv::Mat &mat, bool invert)
}
}
void MatchPattern(QImage &img, const PatternImageData &patternData,
double threshold, cv::Mat &result, double *pBestFitValue,
bool useAlphaAsMask, cv::TemplateMatchModes matchMode)
double MatchPattern(QImage &img, const PatternImageData &patternData,
double threshold, cv::Mat &result, bool useAlphaAsMask,
cv::TemplateMatchModes matchMode)
{
double bestFitValue = std::numeric_limits<double>::signaling_NaN();
result = cv::Mat(0, 0, CV_32F);
if (pBestFitValue) {
*pBestFitValue = std::numeric_limits<double>::signaling_NaN();
}
if (img.isNull() || patternData.rgbaPattern.empty()) {
return;
return bestFitValue;
}
if (img.height() < patternData.rgbaPattern.rows ||
img.width() < patternData.rgbaPattern.cols) {
return;
return bestFitValue;
}
auto input = QImageToMat(img);
@@ -94,20 +92,18 @@ void MatchPattern(QImage &img, const PatternImageData &patternData,
// -> Invert TM_SQDIFF_NORMED in the preprocess step
preprocessPatternMatchResult(result, matchMode == cv::TM_SQDIFF_NORMED);
if (pBestFitValue) {
cv::minMaxLoc(result, nullptr, pBestFitValue);
}
cv::minMaxLoc(result, nullptr, &bestFitValue);
cv::threshold(result, result, threshold, 0.0, cv::THRESH_TOZERO);
return bestFitValue;
}
void MatchPattern(QImage &img, QImage &pattern, double threshold,
cv::Mat &result, double *pBestFitValue, bool useAlphaAsMask,
cv::TemplateMatchModes matchColor)
double MatchPattern(QImage &img, QImage &pattern, double threshold,
cv::Mat &result, bool useAlphaAsMask,
cv::TemplateMatchModes matchColor)
{
auto data = CreatePatternData(pattern);
MatchPattern(img, data, threshold, result, pBestFitValue,
useAlphaAsMask, matchColor);
return MatchPattern(img, data, threshold, result, useAlphaAsMask,
matchColor);
}
std::vector<cv::Rect> MatchObject(QImage &img, cv::CascadeClassifier &cascade,