Add temp vars indicating OCR match location

This commit is contained in:
WarmUpTill 2026-05-09 16:37:54 +02:00 committed by WarmUpTill
parent 37fc204f3d
commit 529bc8ad8b
2 changed files with 60 additions and 0 deletions

View File

@ -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"

View File

@ -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(