Add variable support for video condition spinbox controls

This commit is contained in:
WarmUpTill 2023-03-12 22:06:27 +01:00 committed by WarmUpTill
parent 0e4b072650
commit 89db21d734
6 changed files with 103 additions and 57 deletions

View File

@ -7,8 +7,9 @@
void advss::Size::Save(obs_data_t *obj, const char *name) const
{
auto data = obs_data_create();
obs_data_set_int(data, "width", width);
obs_data_set_int(data, "height", height);
width.Save(data, "width");
height.Save(data, "height");
obs_data_set_int(data, "version", 1);
obs_data_set_obj(obj, name, data);
obs_data_release(data);
}
@ -16,8 +17,13 @@ void advss::Size::Save(obs_data_t *obj, const char *name) const
void advss::Size::Load(obs_data_t *obj, const char *name)
{
auto data = obs_data_get_obj(obj, name);
width = obs_data_get_int(data, "width");
height = obs_data_get_int(data, "height");
if (!obs_data_has_user_value(data, "version")) {
width = obs_data_get_int(data, "width");
height = obs_data_get_int(data, "height");
} else {
width.Load(data, "width");
height.Load(data, "height");
}
obs_data_release(data);
}
@ -29,10 +35,11 @@ cv::Size advss::Size::CV()
void advss::Area::Save(obs_data_t *obj, const char *name) const
{
auto data = obs_data_create();
obs_data_set_int(data, "x", x);
obs_data_set_int(data, "y", y);
obs_data_set_int(data, "width", width);
obs_data_set_int(data, "height", height);
x.Save(data, "x");
y.Save(data, "y");
width.Save(data, "width");
height.Save(data, "height");
obs_data_set_int(data, "version", 1);
obs_data_set_obj(obj, name, data);
obs_data_release(data);
}
@ -40,23 +47,32 @@ void advss::Area::Save(obs_data_t *obj, const char *name) const
void advss::Area::Load(obs_data_t *obj, const char *name)
{
auto data = obs_data_get_obj(obj, name);
x = obs_data_get_int(data, "x");
y = obs_data_get_int(data, "y");
width = obs_data_get_int(data, "width");
height = obs_data_get_int(data, "height");
if (!obs_data_has_user_value(data, "version")) {
x = obs_data_get_int(data, "x");
y = obs_data_get_int(data, "y");
width = obs_data_get_int(data, "width");
height = obs_data_get_int(data, "height");
} else {
x.Load(data, "x");
y.Load(data, "y");
width.Load(data, "width");
height.Load(data, "height");
}
obs_data_release(data);
}
SizeSelection::SizeSelection(int min, int max, QWidget *parent)
: QWidget(parent), _x(new QSpinBox), _y(new QSpinBox)
: QWidget(parent), _x(new VariableSpinBox()), _y(new VariableSpinBox())
{
_x->setMinimum(min);
_y->setMinimum(min);
_x->setMaximum(max);
_y->setMaximum(max);
connect(_x, SIGNAL(valueChanged(int)), this, SLOT(XChanged(int)));
connect(_y, SIGNAL(valueChanged(int)), this, SLOT(YChanged(int)));
connect(_x, SIGNAL(NumberVariableChanged(const NumberVariable<int> &)),
this, SLOT(XChanged(const NumberVariable<int> &)));
connect(_y, SIGNAL(NumberVariableChanged(const NumberVariable<int> &)),
this, SLOT(YChanged(const NumberVariable<int> &)));
auto layout = new QHBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
@ -67,23 +83,23 @@ SizeSelection::SizeSelection(int min, int max, QWidget *parent)
void SizeSelection::SetSize(const advss::Size &s)
{
_x->setValue(s.width);
_y->setValue(s.height);
_x->SetValue(s.width);
_y->SetValue(s.height);
}
advss::Size SizeSelection::Size()
{
return advss::Size{_x->value(), _y->value()};
return advss::Size{_x->Value(), _y->Value()};
}
void SizeSelection::XChanged(int value)
void SizeSelection::XChanged(const NumberVariable<int> &value)
{
emit SizeChanged(advss::Size{value, _y->value()});
emit SizeChanged(advss::Size{value, _y->Value()});
}
void SizeSelection::YChanged(int value)
void SizeSelection::YChanged(const NumberVariable<int> &value)
{
emit SizeChanged(advss::Size{_x->value(), value});
emit SizeChanged(advss::Size{_x->Value(), value});
}
AreaSelection::AreaSelection(int min, int max, QWidget *parent)

View File

@ -1,4 +1,6 @@
#pragma once
#include <variable-spinbox.hpp>
#include <QWidget>
#include <QSpinBox>
#include <obs-data.h>
@ -11,18 +13,18 @@ struct Size {
void Load(obs_data_t *obj, const char *name);
cv::Size CV();
int width;
int height;
NumberVariable<int> width;
NumberVariable<int> height;
};
struct Area {
void Save(obs_data_t *obj, const char *name) const;
void Load(obs_data_t *obj, const char *name);
int x;
int y;
int width;
int height;
NumberVariable<int> x;
NumberVariable<int> y;
NumberVariable<int> width;
NumberVariable<int> height;
};
}
@ -36,14 +38,14 @@ public:
advss::Size Size();
private slots:
void XChanged(int);
void YChanged(int);
void XChanged(const NumberVariable<int> &);
void YChanged(const NumberVariable<int> &);
signals:
void SizeChanged(advss::Size value);
private:
QSpinBox *_x;
QSpinBox *_y;
VariableSpinBox *_x;
VariableSpinBox *_y;
friend class AreaSelection;
};

View File

@ -157,7 +157,7 @@ bool MacroConditionVideo::Save(obs_data_t *obj) const
obs_data_set_string(obj, "filePath", _file.c_str());
obs_data_set_bool(obj, "blockUntilScreenshotDone",
_blockUntilScreenshotDone);
obs_data_set_double(obj, "brightness", _brightnessThreshold);
_brightnessThreshold.Save(obj, "brightnessThreshold");
_patternMatchParameters.Save(obj);
_objMatchParameters.Save(obj);
_ocrParamters.Save(obj);
@ -176,7 +176,12 @@ bool MacroConditionVideo::Load(obs_data_t *obj)
_file = obs_data_get_string(obj, "filePath");
_blockUntilScreenshotDone =
obs_data_get_bool(obj, "blockUntilScreenshotDone");
_brightnessThreshold = obs_data_get_double(obj, "brightness");
// TODO: Remove this fallback in a future version
if (obs_data_has_user_value(obj, "brightness")) {
_brightnessThreshold = obs_data_get_double(obj, "brightness");
} else {
_brightnessThreshold.Load(obj, "brightnessThreshold");
}
_patternMatchParameters.Load(obj);
_objMatchParameters.Load(obj);
_ocrParamters.Load(obj);
@ -477,18 +482,27 @@ MacroConditionVideoEdit::MacroConditionVideoEdit(
SLOT(ImageBrowseButtonClicked()));
QWidget::connect(_usePatternForChangedCheck, SIGNAL(stateChanged(int)),
this, SLOT(UsePatternForChangedCheckChanged(int)));
QWidget::connect(_patternThreshold, SIGNAL(DoubleValueChanged(double)),
this, SLOT(PatternThresholdChanged(double)));
QWidget::connect(
_patternThreshold,
SIGNAL(DoubleValueChanged(const NumberVariable<double> &)),
this,
SLOT(PatternThresholdChanged(const NumberVariable<double> &)));
QWidget::connect(_useAlphaAsMask, SIGNAL(stateChanged(int)), this,
SLOT(UseAlphaAsMaskChanged(int)));
QWidget::connect(_patternMatchMode, SIGNAL(currentIndexChanged(int)),
this, SLOT(PatternMatchModeChanged(int)));
QWidget::connect(_brightnessThreshold,
SIGNAL(DoubleValueChanged(double)), this,
SLOT(BrightnessThresholdChanged(double)));
QWidget::connect(_objectScaleThreshold,
SIGNAL(DoubleValueChanged(double)), this,
SLOT(ObjectScaleThresholdChanged(double)));
QWidget::connect(
_brightnessThreshold,
SIGNAL(DoubleValueChanged(const NumberVariable<double> &)),
this,
SLOT(BrightnessThresholdChanged(
const NumberVariable<double> &)));
QWidget::connect(
_objectScaleThreshold,
SIGNAL(DoubleValueChanged(const NumberVariable<double> &)),
this,
SLOT(ObjectScaleThresholdChanged(
const NumberVariable<double> &)));
QWidget::connect(_minNeighbors, SIGNAL(valueChanged(int)), this,
SLOT(MinNeighborsChanged(int)));
QWidget::connect(_minSize, SIGNAL(SizeChanged(advss::Size)), this,
@ -854,7 +868,8 @@ void MacroConditionVideoEdit::UsePatternForChangedCheckChanged(int value)
SetWidgetVisibility();
}
void MacroConditionVideoEdit::PatternThresholdChanged(double value)
void MacroConditionVideoEdit::PatternThresholdChanged(
const NumberVariable<double> &value)
{
if (_loading || !_entryData) {
return;
@ -903,7 +918,8 @@ void MacroConditionVideoEdit::PatternMatchModeChanged(int idx)
_entryData->_patternMatchParameters);
}
void MacroConditionVideoEdit::BrightnessThresholdChanged(double value)
void MacroConditionVideoEdit::BrightnessThresholdChanged(
const NumberVariable<double> &value)
{
if (_loading || !_entryData) {
return;
@ -913,7 +929,8 @@ void MacroConditionVideoEdit::BrightnessThresholdChanged(double value)
_entryData->_brightnessThreshold = value;
}
void MacroConditionVideoEdit::ObjectScaleThresholdChanged(double value)
void MacroConditionVideoEdit::ObjectScaleThresholdChanged(
const NumberVariable<double> &value)
{
if (_loading || !_entryData) {
return;

View File

@ -51,7 +51,7 @@ public:
// checked in the next one.
// If set both operations will happen in the same interval.
bool _blockUntilScreenshotDone = false;
double _brightnessThreshold = 0.5;
NumberVariable<double> _brightnessThreshold = 0.5;
PatternMatchParameters _patternMatchParameters;
ObjDetectParameters _objMatchParameters;
OCRParameters _ocrParamters;
@ -111,14 +111,14 @@ private slots:
void ImageBrowseButtonClicked();
void UsePatternForChangedCheckChanged(int value);
void PatternThresholdChanged(double);
void PatternThresholdChanged(const NumberVariable<double> &);
void UseAlphaAsMaskChanged(int value);
void PatternMatchModeChanged(int value);
void BrightnessThresholdChanged(double);
void BrightnessThresholdChanged(const NumberVariable<double> &);
void ModelPathChanged(const QString &text);
void ObjectScaleThresholdChanged(double);
void ObjectScaleThresholdChanged(const NumberVariable<double> &);
void MinNeighborsChanged(int value);
void MinSizeChanged(advss::Size value);
void MaxSizeChanged(advss::Size value);

View File

@ -4,9 +4,10 @@ bool PatternMatchParameters::Save(obs_data_t *obj) const
{
auto data = obs_data_create();
obs_data_set_bool(data, "useForChangedCheck", useForChangedCheck);
obs_data_set_double(data, "threshold", threshold);
threshold.Save(data, "threshold");
obs_data_set_bool(data, "useAlphaAsMask", useAlphaAsMask);
obs_data_set_int(data, "matchMode", matchMode);
obs_data_set_int(data, "version", 1);
obs_data_set_obj(obj, "patternMatchData", data);
obs_data_release(data);
return true;
@ -24,7 +25,11 @@ bool PatternMatchParameters::Load(obs_data_t *obj)
}
auto data = obs_data_get_obj(obj, "patternMatchData");
useForChangedCheck = obs_data_get_bool(data, "useForChangedCheck");
threshold = obs_data_get_double(data, "threshold");
threshold.Load(data, "threshold");
// TODO: Remove this fallback in a future version
if (!obs_data_has_user_value(data, "version")) {
threshold = obs_data_get_double(data, "threshold");
}
useAlphaAsMask = obs_data_get_bool(data, "useAlphaAsMask");
// TODO: Remove this fallback in a future version
if (!obs_data_has_user_value(obj, "matchMode")) {
@ -41,11 +46,12 @@ bool ObjDetectParameters::Save(obs_data_t *obj) const
{
auto data = obs_data_create();
obs_data_set_string(data, "modelPath", modelPath.c_str());
obs_data_set_double(data, "scaleFactor", scaleFactor);
scaleFactor.Save(data, "scaleFactor");
obs_data_set_int(data, "minNeighbors", minNeighbors);
minSize.Save(data, "minSize");
maxSize.Save(data, "maxSize");
obs_data_set_obj(obj, "objectMatchData", data);
obs_data_set_int(data, "version", 1);
obs_data_release(data);
return true;
}
@ -80,8 +86,12 @@ bool ObjDetectParameters::Load(obs_data_t *obj)
}
auto data = obs_data_get_obj(obj, "objectMatchData");
modelPath = obs_data_get_string(data, "modelPath");
scaleFactor = obs_data_get_double(data, "scaleFactor");
if (!isScaleFactorValid(scaleFactor)) {
scaleFactor.Load(data, "scaleFactor");
// TODO: Remove this fallback in a future version
if (!obs_data_has_user_value(data, "version")) {
scaleFactor = obs_data_get_double(data, "scaleFactor");
}
if (scaleFactor.IsFixedType() && !isScaleFactorValid(scaleFactor)) {
scaleFactor = 1.1;
}
minNeighbors = obs_data_get_int(data, "minNeighbors");

View File

@ -6,6 +6,7 @@
#include <scene-selection.hpp>
#include <regex-config.hpp>
#include <variable-string.hpp>
#include <variable-number.hpp>
#include <obs.hpp>
#include <obs-module.h>
@ -55,7 +56,7 @@ public:
bool useForChangedCheck = false;
bool useAlphaAsMask = false;
cv::TemplateMatchModes matchMode = cv::TM_CCORR_NORMED;
double threshold = 0.8;
NumberVariable<double> threshold = 0.8;
};
class ObjDetectParameters {
@ -68,7 +69,7 @@ public:
std::string(
"/res/cascadeClassifiers/haarcascade_frontalface_alt.xml");
cv::CascadeClassifier cascade;
double scaleFactor = defaultScaleFactor;
NumberVariable<double> scaleFactor = defaultScaleFactor;
int minNeighbors = minMinNeighbors;
advss::Size minSize{0, 0};
advss::Size maxSize{0, 0};
@ -89,7 +90,7 @@ public:
tesseract::PageSegMode GetPageMode() const { return pageSegMode; }
tesseract::TessBaseAPI *GetOCR() const { return ocr.get(); }
VariableString text = obs_module_text("AdvSceneSwitcher.enterText");
StringVariable text = obs_module_text("AdvSceneSwitcher.enterText");
RegexConfig regex = RegexConfig::PartialMatchRegexConfig();
QColor color = Qt::black;