Fix freeze when choosing invalid OCR model

This commit is contained in:
WarmUpTill 2026-05-28 16:33:09 +02:00
parent 4fe3c3181d
commit 57c698ffd9
3 changed files with 17 additions and 16 deletions

View File

@ -403,11 +403,12 @@ bool MacroConditionVideo::CheckBrightnessThreshold()
bool MacroConditionVideo::CheckOCR()
{
if (!_ocrParameters.Initialized()) {
auto *ocr = _ocrParameters.GetOCR();
if (!ocr) {
return false;
}
auto text = RunOCR(_ocrParameters.GetOCR(), _screenshotData.GetImage(),
auto text = RunOCR(ocr, _screenshotData.GetImage(),
_ocrParameters.color, _ocrParameters.colorThreshold);
if (!text) {
return false;

View File

@ -318,9 +318,6 @@ OCRParameters::OCRParameters(const OCRParameters &other)
useConfig(other.useConfig),
configFile(other.configFile)
{
if (!initDone) {
Setup();
}
}
OCRParameters &OCRParameters::operator=(const OCRParameters &other)
@ -334,9 +331,7 @@ OCRParameters &OCRParameters::operator=(const OCRParameters &other)
languageCode = other.languageCode;
useConfig = other.useConfig;
configFile = other.configFile;
if (!initDone) {
Setup();
}
initDone = false;
return *this;
}
@ -412,6 +407,14 @@ void OCRParameters::SetPageMode(tesseract::PageSegMode mode)
}
}
tesseract::TessBaseAPI *OCRParameters::GetOCR()
{
if (!initDone) {
Setup();
}
return initDone ? ocr.get() : nullptr;
}
bool OCRParameters::SetLanguageCode(const std::string &value)
{
const auto dataPath = QString::fromStdString(tesseractBasePath) + "/" +
@ -421,7 +424,7 @@ bool OCRParameters::SetLanguageCode(const std::string &value)
return false;
}
languageCode = value;
Setup();
initDone = false;
return true;
}
@ -440,7 +443,7 @@ bool OCRParameters::SetTesseractBasePath(const std::string &value)
return false;
}
tesseractBasePath = value;
Setup();
initDone = false;
return true;
}
@ -452,13 +455,13 @@ std::string OCRParameters::GetTesseractBasePath() const
void OCRParameters::EnableCustomConfig(bool enable)
{
useConfig = enable;
Setup();
initDone = false;
}
void OCRParameters::SetCustomConfigFile(const std::string &filename)
{
configFile = filename;
Setup();
initDone = false;
}
void OCRParameters::Setup()

View File

@ -108,10 +108,7 @@ public:
void SetCustomConfigFile(const std::string &);
std::string GetCustomConfigFile() const { return configFile; }
tesseract::PageSegMode GetPageMode() const { return pageSegMode; }
tesseract::TessBaseAPI *GetOCR() const
{
return initDone ? ocr.get() : nullptr;
}
tesseract::TessBaseAPI *GetOCR();
StringVariable text = obs_module_text("AdvSceneSwitcher.enterText");
RegexConfig regex = RegexConfig::PartialMatchRegexConfig();