mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-13 04:37:14 -05:00
Switch to VariableColorButton for OCR and color match
Some checks failed
debian-build / build (push) Has been cancelled
Check locale / ubuntu64 (push) Has been cancelled
Push to master / Check Formatting 🔍 (push) Has been cancelled
Push to master / Build Project 🧱 (push) Has been cancelled
Push to master / Create Release 🛫 (push) Has been cancelled
Some checks failed
debian-build / build (push) Has been cancelled
Check locale / ubuntu64 (push) Has been cancelled
Push to master / Check Formatting 🔍 (push) Has been cancelled
Push to master / Build Project 🧱 (push) Has been cancelled
Push to master / Create Release 🛫 (push) Has been cancelled
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
#include <macro-condition-edit.hpp>
|
||||
#include <plugin-state-helpers.hpp>
|
||||
#include <QBuffer>
|
||||
#include <QColorDialog>
|
||||
#include <QDesktopServices>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
@@ -409,7 +408,8 @@ bool MacroConditionVideo::CheckOCR()
|
||||
}
|
||||
|
||||
auto text = RunOCR(ocr, _screenshotData.GetImage(),
|
||||
_ocrParameters.color, _ocrParameters.colorThreshold);
|
||||
_ocrParameters.color.GetValue(),
|
||||
_ocrParameters.colorThreshold);
|
||||
if (!text) {
|
||||
return false;
|
||||
}
|
||||
@@ -425,7 +425,7 @@ bool MacroConditionVideo::CheckOCR()
|
||||
bool MacroConditionVideo::CheckColor()
|
||||
{
|
||||
const bool ret = ContainsPixelsInColorRange(
|
||||
_screenshotData.GetImage(), _colorParameters.color,
|
||||
_screenshotData.GetImage(), _colorParameters.color.GetValue(),
|
||||
_colorParameters.colorThreshold,
|
||||
_colorParameters.matchThreshold);
|
||||
|
||||
@@ -677,9 +677,10 @@ OCREdit::OCREdit(QWidget *parent, PreviewDialog *previewDialog,
|
||||
: QWidget(parent),
|
||||
_matchText(new VariableTextEdit(this)),
|
||||
_regex(new RegexConfigWidget(this)),
|
||||
_textColor(new QLabel),
|
||||
_selectColor(new QPushButton(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.video.selectColor"))),
|
||||
_colorButton(new VariableColorButton(
|
||||
this,
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.condition.video.selectColor"))),
|
||||
_colorThreshold(new SliderSpinBox(
|
||||
0., 1.,
|
||||
obs_module_text(
|
||||
@@ -709,8 +710,9 @@ OCREdit::OCREdit(QWidget *parent, PreviewDialog *previewDialog,
|
||||
_reloadConfig->setToolTip(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.video.ocrConfigReload"));
|
||||
|
||||
QWidget::connect(_selectColor, SIGNAL(clicked()), this,
|
||||
SLOT(SelectColorClicked()));
|
||||
QWidget::connect(_colorButton,
|
||||
SIGNAL(ColorVariableChanged(const ColorVariable &)),
|
||||
this, SLOT(ColorChanged(const ColorVariable &)));
|
||||
QWidget::connect(
|
||||
_colorThreshold,
|
||||
SIGNAL(DoubleValueChanged(const NumberVariable<double> &)),
|
||||
@@ -754,8 +756,7 @@ OCREdit::OCREdit(QWidget *parent, PreviewDialog *previewDialog,
|
||||
"AdvSceneSwitcher.condition.video.ocrConfigHint"));
|
||||
|
||||
const std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{textColor}}", _textColor},
|
||||
{"{{selectColor}}", _selectColor},
|
||||
{"{{color}}", _colorButton},
|
||||
{"{{textType}}", _pageSegMode},
|
||||
{"{{tesseractBaseDir}}", _tesseractBaseDir},
|
||||
{"{{languageCode}}", _languageCode},
|
||||
@@ -807,7 +808,7 @@ OCREdit::OCREdit(QWidget *parent, PreviewDialog *previewDialog,
|
||||
|
||||
_matchText->setPlainText(_entryData->_ocrParameters.text);
|
||||
_regex->SetRegexConfig(_entryData->_ocrParameters.regex);
|
||||
SetupColorLabel(_entryData->_ocrParameters.color);
|
||||
_colorButton->SetValue(_entryData->_ocrParameters.color);
|
||||
_colorThreshold->SetDoubleValue(
|
||||
_entryData->_ocrParameters.colorThreshold);
|
||||
_pageSegMode->setCurrentIndex(_pageSegMode->findData(
|
||||
@@ -823,31 +824,10 @@ OCREdit::OCREdit(QWidget *parent, PreviewDialog *previewDialog,
|
||||
_loading = false;
|
||||
}
|
||||
|
||||
void OCREdit::SetupColorLabel(const QColor &color)
|
||||
void OCREdit::ColorChanged(const ColorVariable &value)
|
||||
{
|
||||
_textColor->setText(color.name());
|
||||
_textColor->setPalette(QPalette(color));
|
||||
_textColor->setAutoFillBackground(true);
|
||||
}
|
||||
|
||||
void OCREdit::SelectColorClicked()
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QColor color = QColorDialog::getColor(
|
||||
_entryData->_ocrParameters.color, this,
|
||||
obs_module_text("AdvSceneSwitcher.condition.video.selectColor"),
|
||||
QColorDialog::ColorDialogOption());
|
||||
|
||||
if (!color.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetupColorLabel(color);
|
||||
auto lock = LockContext();
|
||||
_entryData->_ocrParameters.color = color;
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_ocrParameters.color = value;
|
||||
|
||||
_previewDialog->OCRParametersChanged(_entryData->_ocrParameters);
|
||||
}
|
||||
@@ -1106,13 +1086,15 @@ ColorEdit::ColorEdit(QWidget *parent,
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.condition.video.colorDeviationThresholdDescription"),
|
||||
true)),
|
||||
_color(new QLabel),
|
||||
_selectColor(new QPushButton(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.video.selectColor"))),
|
||||
_colorButton(new VariableColorButton(
|
||||
this,
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.condition.video.selectColor"))),
|
||||
_entryData(data)
|
||||
{
|
||||
QWidget::connect(_selectColor, SIGNAL(clicked()), this,
|
||||
SLOT(SelectColorClicked()));
|
||||
QWidget::connect(_colorButton,
|
||||
SIGNAL(ColorVariableChanged(const ColorVariable &)),
|
||||
this, SLOT(ColorChanged(const ColorVariable &)));
|
||||
QWidget::connect(
|
||||
_matchThreshold,
|
||||
SIGNAL(DoubleValueChanged(const NumberVariable<double> &)),
|
||||
@@ -1125,8 +1107,7 @@ ColorEdit::ColorEdit(QWidget *parent,
|
||||
SLOT(ColorThresholdChanged(const NumberVariable<double> &)));
|
||||
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{color}}", _color},
|
||||
{"{{selectColor}}", _selectColor},
|
||||
{"{{color}}", _colorButton},
|
||||
};
|
||||
|
||||
auto colorLayout = new QHBoxLayout;
|
||||
@@ -1145,15 +1126,14 @@ ColorEdit::ColorEdit(QWidget *parent,
|
||||
_entryData->_colorParameters.matchThreshold);
|
||||
_colorThreshold->SetDoubleValue(
|
||||
_entryData->_colorParameters.colorThreshold);
|
||||
SetupColorLabel(_entryData->_colorParameters.color);
|
||||
_colorButton->SetValue(_entryData->_colorParameters.color);
|
||||
_loading = false;
|
||||
}
|
||||
|
||||
void ColorEdit::SetupColorLabel(const QColor &color)
|
||||
void ColorEdit::ColorChanged(const ColorVariable &value)
|
||||
{
|
||||
_color->setText(color.name());
|
||||
_color->setPalette(QPalette(color));
|
||||
_color->setAutoFillBackground(true);
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_colorParameters.color = value;
|
||||
}
|
||||
|
||||
void ColorEdit::MatchThresholdChanged(const DoubleVariable &value)
|
||||
@@ -1168,26 +1148,6 @@ void ColorEdit::ColorThresholdChanged(const DoubleVariable &value)
|
||||
_entryData->_colorParameters.colorThreshold = value;
|
||||
}
|
||||
|
||||
void ColorEdit::SelectColorClicked()
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QColor color = QColorDialog::getColor(
|
||||
_entryData->_colorParameters.color, this,
|
||||
obs_module_text("AdvSceneSwitcher.condition.video.selectColor"),
|
||||
QColorDialog::ColorDialogOption());
|
||||
|
||||
if (!color.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetupColorLabel(color);
|
||||
auto lock = LockContext();
|
||||
_entryData->_colorParameters.color = color;
|
||||
}
|
||||
|
||||
AreaEdit::AreaEdit(QWidget *parent, PreviewDialog *previewDialog,
|
||||
const std::shared_ptr<MacroConditionVideo> &data)
|
||||
: QWidget(parent),
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <screenshot-helper.hpp>
|
||||
#include <slider-spinbox.hpp>
|
||||
#include <source-helpers.hpp>
|
||||
#include <variable-color-button.hpp>
|
||||
#include <variable-line-edit.hpp>
|
||||
#include <variable-text-edit.hpp>
|
||||
|
||||
@@ -143,7 +144,7 @@ public:
|
||||
const std::shared_ptr<MacroConditionVideo> &);
|
||||
|
||||
private slots:
|
||||
void SelectColorClicked();
|
||||
void ColorChanged(const ColorVariable &);
|
||||
void ColorThresholdChanged(const NumberVariable<double> &);
|
||||
void MatchTextChanged();
|
||||
void RegexChanged(const RegexConfig &conf);
|
||||
@@ -154,12 +155,9 @@ private slots:
|
||||
void ConfigFileChanged(const QString &);
|
||||
|
||||
private:
|
||||
void SetupColorLabel(const QColor &);
|
||||
|
||||
VariableTextEdit *_matchText;
|
||||
RegexConfigWidget *_regex;
|
||||
QLabel *_textColor;
|
||||
QPushButton *_selectColor;
|
||||
VariableColorButton *_colorButton;
|
||||
SliderSpinBox *_colorThreshold;
|
||||
QComboBox *_pageSegMode;
|
||||
FileSelection *_tesseractBaseDir;
|
||||
@@ -212,17 +210,14 @@ public:
|
||||
const std::shared_ptr<MacroConditionVideo> &);
|
||||
|
||||
private slots:
|
||||
void SelectColorClicked();
|
||||
void ColorChanged(const ColorVariable &);
|
||||
void MatchThresholdChanged(const NumberVariable<double> &);
|
||||
void ColorThresholdChanged(const NumberVariable<double> &);
|
||||
|
||||
private:
|
||||
void SetupColorLabel(const QColor &);
|
||||
|
||||
SliderSpinBox *_matchThreshold;
|
||||
SliderSpinBox *_colorThreshold;
|
||||
QLabel *_color;
|
||||
QPushButton *_selectColor;
|
||||
VariableColorButton *_colorButton;
|
||||
|
||||
std::shared_ptr<MacroConditionVideo> _entryData;
|
||||
bool _loading = true;
|
||||
|
||||
@@ -273,27 +273,6 @@ OBSWeakSource VideoInput::GetVideo() const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void SaveColor(obs_data_t *obj, const char *name, const QColor &color)
|
||||
{
|
||||
auto data = obs_data_create();
|
||||
obs_data_set_int(data, "red", color.red());
|
||||
obs_data_set_int(data, "green", color.green());
|
||||
obs_data_set_int(data, "blue", color.blue());
|
||||
obs_data_set_obj(obj, name, data);
|
||||
obs_data_release(data);
|
||||
}
|
||||
|
||||
static QColor LoadColor(obs_data_t *obj, const char *name)
|
||||
{
|
||||
QColor color = Qt::black;
|
||||
auto data = obs_data_get_obj(obj, name);
|
||||
color.setRed(obs_data_get_int(data, "red"));
|
||||
color.setGreen(obs_data_get_int(data, "green"));
|
||||
color.setBlue(obs_data_get_int(data, "blue"));
|
||||
obs_data_release(data);
|
||||
return color;
|
||||
}
|
||||
|
||||
OCRParameters::OCRParameters()
|
||||
{
|
||||
Setup();
|
||||
@@ -344,7 +323,7 @@ bool OCRParameters::Save(obs_data_t *obj) const
|
||||
languageCode.Save(data, "language");
|
||||
obs_data_set_bool(data, "useConfig", useConfig);
|
||||
obs_data_set_string(data, "configFile", configFile.c_str());
|
||||
SaveColor(data, "textColor", color);
|
||||
color.Save(data, "textColor");
|
||||
colorThreshold.Save(data, "colorThreshold");
|
||||
obs_data_set_int(data, "pageSegMode", static_cast<int>(pageSegMode));
|
||||
obs_data_set_int(data, "version", 3);
|
||||
@@ -387,7 +366,7 @@ bool OCRParameters::Load(obs_data_t *obj)
|
||||
useConfig = obs_data_get_bool(data, "useConfig");
|
||||
configFile = obs_data_get_string(data, "configFile");
|
||||
|
||||
color = LoadColor(data, "textColor");
|
||||
color.Load(data, "textColor");
|
||||
if (obs_data_has_user_value(data, "version")) {
|
||||
colorThreshold.Load(data, "colorThreshold");
|
||||
}
|
||||
@@ -516,7 +495,7 @@ void OCRParameters::Setup()
|
||||
bool ColorParameters::Save(obs_data_t *obj) const
|
||||
{
|
||||
auto data = obs_data_create();
|
||||
SaveColor(data, "color", color);
|
||||
color.Save(data, "color");
|
||||
colorThreshold.Save(data, "colorThreshold");
|
||||
matchThreshold.Save(data, "matchThreshold");
|
||||
obs_data_set_obj(obj, "colorData", data);
|
||||
@@ -527,7 +506,7 @@ bool ColorParameters::Save(obs_data_t *obj) const
|
||||
bool ColorParameters::Load(obs_data_t *obj)
|
||||
{
|
||||
auto data = obs_data_get_obj(obj, "colorData");
|
||||
color = LoadColor(data, "color");
|
||||
color.Load(data, "color");
|
||||
colorThreshold.Load(data, "colorThreshold");
|
||||
matchThreshold.Load(data, "matchThreshold");
|
||||
obs_data_release(data);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <source-selection.hpp>
|
||||
#include <scene-selection.hpp>
|
||||
#include <regex-config.hpp>
|
||||
#include <variable-color.hpp>
|
||||
#include <variable-string.hpp>
|
||||
#include <variable-number.hpp>
|
||||
#include <obs.hpp>
|
||||
@@ -112,7 +113,7 @@ public:
|
||||
|
||||
StringVariable text = obs_module_text("AdvSceneSwitcher.enterText");
|
||||
RegexConfig regex = RegexConfig::PartialMatchRegexConfig();
|
||||
QColor color = Qt::black;
|
||||
ColorVariable color;
|
||||
DoubleVariable colorThreshold = 0.3;
|
||||
|
||||
private:
|
||||
@@ -134,7 +135,7 @@ public:
|
||||
bool Save(obs_data_t *obj) const;
|
||||
bool Load(obs_data_t *obj);
|
||||
|
||||
QColor color = Qt::black;
|
||||
ColorVariable color;
|
||||
DoubleVariable colorThreshold = 0.1;
|
||||
DoubleVariable matchThreshold = 0.8;
|
||||
};
|
||||
|
||||
@@ -385,7 +385,8 @@ void PreviewImage::MarkOCRMatch(QImage &screenshot,
|
||||
"AdvSceneSwitcher.condition.video.ocrMatchFail"));
|
||||
return;
|
||||
}
|
||||
auto text = RunOCR(ocrParams->GetOCR(), screenshot, ocrParams->color,
|
||||
auto text = RunOCR(ocrParams->GetOCR(), screenshot,
|
||||
ocrParams->color.GetValue(),
|
||||
ocrParams->colorThreshold);
|
||||
|
||||
if (!text) {
|
||||
|
||||
Reference in New Issue
Block a user