From 529bc8ad8b47bb4078652fa8781a0ad559cf862e Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Sat, 9 May 2026 16:37:54 +0200 Subject: [PATCH] Add temp vars indicating OCR match location --- data/locale/en-US.ini | 8 ++++ plugins/video/macro-condition-video.cpp | 52 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 6e76b07c..321caa61 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -2352,6 +2352,14 @@ AdvSceneSwitcher.tempVar.video.similarity="Similarity Rating" AdvSceneSwitcher.tempVar.video.similarity.description="Values range from 0 to 1, where 0 means dissimilar and 1 means highly similar." AdvSceneSwitcher.tempVar.video.patternCount="Pattern count" AdvSceneSwitcher.tempVar.video.patternCount.description="The number of times the given pattern has been found in a given video input frame." +AdvSceneSwitcher.tempVar.video.matchX="Match X coordinate" +AdvSceneSwitcher.tempVar.video.matchX.description="The X coordinate of the top-left corner of the best pattern match.\nIf the 'check area' option is enabled, the coordinate is relative to the video source, not the area.\nSet to -1 if no match was found." +AdvSceneSwitcher.tempVar.video.matchY="Match Y coordinate" +AdvSceneSwitcher.tempVar.video.matchY.description="The Y coordinate of the top-left corner of the best pattern match.\nIf the 'check area' option is enabled, the coordinate is relative to the video source, not the area.\nSet to -1 if no match was found." +AdvSceneSwitcher.tempVar.video.matchWidth="Match width" +AdvSceneSwitcher.tempVar.video.matchWidth.description="The width of the matched pattern in pixels." +AdvSceneSwitcher.tempVar.video.matchHeight="Match height" +AdvSceneSwitcher.tempVar.video.matchHeight.description="The height of the matched pattern in pixels." AdvSceneSwitcher.tempVar.video.objectCount="Object count" AdvSceneSwitcher.tempVar.video.objectCount.description="The number of objects the given model has identified in a given video input frame." AdvSceneSwitcher.tempVar.video.brightness="Average brightness" diff --git a/plugins/video/macro-condition-video.cpp b/plugins/video/macro-condition-video.cpp index 749f3bcd..359cee01 100644 --- a/plugins/video/macro-condition-video.cpp +++ b/plugins/video/macro-condition-video.cpp @@ -296,13 +296,41 @@ bool MacroConditionVideo::ScreenshotContainsPattern() _patternMatchParameters.threshold, result, _patternMatchParameters.useAlphaAsMask, _patternMatchParameters.matchMode); + if (result.total() == 0) { SetTempVarValue("similarity", std::to_string(bestMatchValue)); SetTempVarValue("patternCount", "0"); + SetTempVarValue("matchX", "-1"); + SetTempVarValue("matchY", "-1"); + SetTempVarValue("matchWidth", "0"); + SetTempVarValue("matchHeight", "0"); return false; } SetTempVarValue("similarity", std::to_string(bestMatchValue)); + SetTempVarValue("matchWidth", + std::to_string(_patternImageData.rgbaPattern.cols)); + SetTempVarValue("matchHeight", + std::to_string(_patternImageData.rgbaPattern.rows)); + + if (IsTempVarInUse("matchX") || IsTempVarInUse("matchY")) { + double maxVal; + cv::Point maxLoc; + cv::minMaxLoc(result, nullptr, &maxVal, nullptr, &maxLoc); + if (maxVal > 0.0) { + int matchX = maxLoc.x; + int matchY = maxLoc.y; + if (_areaParameters.enable) { + matchX += _areaParameters.area.x; + matchY += _areaParameters.area.y; + } + SetTempVarValue("matchX", std::to_string(matchX)); + SetTempVarValue("matchY", std::to_string(matchY)); + } else { + SetTempVarValue("matchX", "-1"); + SetTempVarValue("matchY", "-1"); + } + } if (IsTempVarInUse("patternCount")) { const auto count = CountPatternMatches( @@ -473,6 +501,30 @@ void MacroConditionVideo::SetupTempVars() "AdvSceneSwitcher.tempVar.video.patternCount"), obs_module_text( "AdvSceneSwitcher.tempVar.video.patternCount.description")); + AddTempvar( + "matchX", + obs_module_text( + "AdvSceneSwitcher.tempVar.video.matchX"), + obs_module_text( + "AdvSceneSwitcher.tempVar.video.matchX.description")); + AddTempvar( + "matchY", + obs_module_text( + "AdvSceneSwitcher.tempVar.video.matchY"), + obs_module_text( + "AdvSceneSwitcher.tempVar.video.matchY.description")); + AddTempvar( + "matchWidth", + obs_module_text( + "AdvSceneSwitcher.tempVar.video.matchWidth"), + obs_module_text( + "AdvSceneSwitcher.tempVar.video.matchWidth.description")); + AddTempvar( + "matchHeight", + obs_module_text( + "AdvSceneSwitcher.tempVar.video.matchHeight"), + obs_module_text( + "AdvSceneSwitcher.tempVar.video.matchHeight.description")); break; case VideoCondition::OBJECT: AddTempvar(