| 292 | } |
| 293 | |
| 294 | bool 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 | |
| 349 | bool MacroConditionVideo::FileInputIsUpToDate() const |
| 350 | { |
nothing calls this directly
no test coverage detected