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

Method ScreenshotContainsPattern

plugins/video/macro-condition-video.cpp:294–347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

292}
293
294bool MacroConditionVideo::ScreenshotContainsPattern()
295{
296 cv::Mat result;
297 double bestMatchValue =
298 MatchPattern(_screenshotData.GetImage(), _patternImageData,
299 _patternMatchParameters.threshold, result,
300 _patternMatchParameters.useAlphaAsMask,
301 _patternMatchParameters.matchMode);
302
303 if (result.total() == 0) {
304 SetTempVarValue("similarity", std::to_string(bestMatchValue));
305 SetTempVarValue("patternCount", "0");
306 SetTempVarValue("matchX", "-1");
307 SetTempVarValue("matchY", "-1");
308 SetTempVarValue("matchWidth", "0");
309 SetTempVarValue("matchHeight", "0");
310 return false;
311 }
312
313 SetTempVarValue("similarity", std::to_string(bestMatchValue));
314 SetTempVarValue("matchWidth",
315 std::to_string(_patternImageData.rgbaPattern.cols));
316 SetTempVarValue("matchHeight",
317 std::to_string(_patternImageData.rgbaPattern.rows));
318
319 if (IsTempVarInUse("matchX") || IsTempVarInUse("matchY")) {
320 double maxVal;
321 cv::Point maxLoc;
322 cv::minMaxLoc(result, nullptr, &maxVal, nullptr, &maxLoc);
323 if (maxVal > 0.0) {
324 int matchX = maxLoc.x;
325 int matchY = maxLoc.y;
326 if (_areaParameters.enable) {
327 matchX += _areaParameters.area.x;
328 matchY += _areaParameters.area.y;
329 }
330 SetTempVarValue("matchX", std::to_string(matchX));
331 SetTempVarValue("matchY", std::to_string(matchY));
332 } else {
333 SetTempVarValue("matchX", "-1");
334 SetTempVarValue("matchY", "-1");
335 }
336 }
337
338 if (IsTempVarInUse("patternCount")) {
339 const auto count = CountPatternMatches(
340 result, {_patternImageData.rgbaPattern.cols,
341 _patternImageData.rgbaPattern.rows});
342 SetTempVarValue("patternCount", std::to_string(count));
343 return count > 0;
344 }
345
346 return countNonZero(result) > 0;
347}
348
349bool MacroConditionVideo::FileInputIsUpToDate() const
350{

Callers

nothing calls this directly

Calls 5

MatchPatternFunction · 0.85
SetTempVarValueFunction · 0.85
to_stringFunction · 0.85
CountPatternMatchesFunction · 0.85
totalMethod · 0.45

Tested by

no test coverage detected