mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-06-12 11:51:39 -05:00
Adjust video condition temp vars
Some checks are pending
debian-build / build (push) Waiting to run
Check locale / ubuntu64 (push) Waiting to run
Push to master / Check Formatting 🔍 (push) Waiting to run
Push to master / Build Project 🧱 (push) Waiting to run
Push to master / Create Release 🛫 (push) Blocked by required conditions
Some checks are pending
debian-build / build (push) Waiting to run
Check locale / ubuntu64 (push) Waiting to run
Push to master / Check Formatting 🔍 (push) Waiting to run
Push to master / Build Project 🧱 (push) Waiting to run
Push to master / Create Release 🛫 (push) Blocked by required conditions
This commit is contained in:
parent
6309100cc4
commit
29e1ff0754
|
|
@ -2251,6 +2251,8 @@ AdvSceneSwitcher.tempVar.video.text="OCR text"
|
|||
AdvSceneSwitcher.tempVar.video.text.description="The text detected in a given video input frame."
|
||||
AdvSceneSwitcher.tempVar.video.color="Average color"
|
||||
AdvSceneSwitcher.tempVar.video.color.description="The average RGB color in a given video input frame in HexArgb format."
|
||||
AdvSceneSwitcher.tempVar.video.dominantColor="Dominant color"
|
||||
AdvSceneSwitcher.tempVar.video.dominantColor.description="The most dominant RGB color in a given video input frame in HexArgb format.\nDetermined using k-means clustering, which groups similar colors and returns the center of the largest group.\nDue to the nature of the algorithm the result may vary slightly between evaluations."
|
||||
|
||||
AdvSceneSwitcher.tempVar.websocket.message="Received websocket message"
|
||||
AdvSceneSwitcher.tempVar.websocket.message.description="The received websocket message, which matched the given pattern"
|
||||
|
|
|
|||
|
|
@ -377,13 +377,19 @@ bool MacroConditionVideo::CheckColor()
|
|||
_screenshotData.GetImage(), _colorParameters.color,
|
||||
_colorParameters.colorThreshold,
|
||||
_colorParameters.matchThreshold);
|
||||
// Way too slow for now
|
||||
//SetTempVarValue("dominantColor", GetDominantColor(_screenshotData.image, 3)
|
||||
// .name(QColor::HexArgb)
|
||||
// .toStdString());
|
||||
SetTempVarValue("color", GetAverageColor(_screenshotData.GetImage())
|
||||
.name(QColor::HexArgb)
|
||||
.toStdString());
|
||||
|
||||
SetTempVarValue("color", [&]() {
|
||||
return GetAverageColor(_screenshotData.GetImage())
|
||||
.name(QColor::HexArgb)
|
||||
.toStdString();
|
||||
});
|
||||
|
||||
SetTempVarValue("dominantColor", [&]() {
|
||||
return GetDominantColor(_screenshotData.GetImage(), 3)
|
||||
.name(QColor::HexArgb)
|
||||
.toStdString();
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -479,6 +485,12 @@ void MacroConditionVideo::SetupTempVars()
|
|||
obs_module_text("AdvSceneSwitcher.tempVar.video.color"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.video.color.description"));
|
||||
AddTempvar(
|
||||
"dominantColor",
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.video.dominantColor"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.video.dominantColor.description"));
|
||||
break;
|
||||
case VideoCondition::MATCH:
|
||||
case VideoCondition::DIFFER:
|
||||
|
|
|
|||
|
|
@ -286,9 +286,9 @@ QColor GetAverageColor(const QImage &img)
|
|||
|
||||
auto image = QImageToMat(img);
|
||||
cv::Scalar meanColor = cv::mean(image);
|
||||
int averageBlue = cvRound(meanColor[0]);
|
||||
int averageRed = cvRound(meanColor[0]);
|
||||
int averageGreen = cvRound(meanColor[1]);
|
||||
int averageRed = cvRound(meanColor[2]);
|
||||
int averageBlue = cvRound(meanColor[2]);
|
||||
|
||||
return QColor(averageRed, averageGreen, averageBlue);
|
||||
}
|
||||
|
|
@ -309,8 +309,8 @@ QColor GetDominantColor(const QImage &img, int k)
|
|||
cv::TermCriteria criteria(
|
||||
cv::TermCriteria::EPS + cv::TermCriteria::MAX_ITER, 100, 0.2);
|
||||
cv::Mat labels, centers;
|
||||
cv::kmeans(reshapedImage, k, labels, criteria, 1,
|
||||
cv::KMEANS_RANDOM_CENTERS, centers);
|
||||
cv::kmeans(reshapedImage, k, labels, criteria, 3, cv::KMEANS_PP_CENTERS,
|
||||
centers);
|
||||
|
||||
// Find the dominant color
|
||||
// Center of the cluster with the largest number of pixels
|
||||
|
|
@ -321,16 +321,16 @@ QColor GetDominantColor(const QImage &img, int k)
|
|||
|
||||
cv::Point max_loc;
|
||||
cv::minMaxLoc(counts, nullptr, nullptr, nullptr, &max_loc);
|
||||
try {
|
||||
cv::Scalar dominantColor = centers.at<cv::Scalar>(max_loc.y);
|
||||
const int blue = cv::saturate_cast<int>(dominantColor.val[0]);
|
||||
const int green = cv::saturate_cast<int>(dominantColor.val[1]);
|
||||
const int red = cv::saturate_cast<int>(dominantColor.val[2]);
|
||||
const int alpha = cv::saturate_cast<int>(dominantColor.val[3]);
|
||||
return QColor(red, green, blue, alpha);
|
||||
} catch (...) {
|
||||
}
|
||||
return QColor();
|
||||
const int clusterIdx = max_loc.x;
|
||||
const int red =
|
||||
cv::saturate_cast<int>(centers.at<float>(clusterIdx, 0));
|
||||
const int green =
|
||||
cv::saturate_cast<int>(centers.at<float>(clusterIdx, 1));
|
||||
const int blue =
|
||||
cv::saturate_cast<int>(centers.at<float>(clusterIdx, 2));
|
||||
const int alpha =
|
||||
cv::saturate_cast<int>(centers.at<float>(clusterIdx, 3));
|
||||
return QColor(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
// Assumption is that QImage uses Format_RGBA8888.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user