MCPcopy Create free account
hub / github.com/WarmUpTill/SceneSwitcher / preprocessPatternMatchResult

Function preprocessPatternMatchResult

plugins/video/opencv-helpers.cpp:25–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25static void preprocessPatternMatchResult(cv::Mat &mat, bool invert)
26{
27 // Not finite values are not handled well by the cv::threshold method.
28 // These occur when the image is completely black, the denominator in all
29 // normalized algorithms approaches 0 in these cases if the alpha channel is
30 // used as mask.
31 //
32 // So we are clamping the values here to 0.0..1.0 and dismiss not-finite
33 // values.
34 // Invertion mode is for the TM_SQDIFF_NORMED method.
35 float value;
36 for (int r = 0; r < mat.rows; r++) {
37 for (int c = 0; c < mat.cols; c++) {
38 value = mat.at<float>(r, c);
39 if (invert) {
40 value = 1.0f - value;
41 }
42 if (!std::isfinite(value)) {
43 value = 0.0f;
44 }
45 mat.at<float>(r, c) =
46 std::fmaxf(0.0f, std::fminf(1.0f, value));
47 }
48 }
49}
50
51double MatchPattern(QImage &img, const PatternImageData &patternData,
52 double threshold, cv::Mat &result, bool useAlphaAsMask,

Callers 1

MatchPatternFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected