mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-06-07 09:52:40 +08:00
simplify datadir tests and use stream output
This commit is contained in:
parent
ddc32a42d0
commit
1ea0ef29a4
@ -146,10 +146,9 @@ static void ExtractFontName(const char* filename, std::string* fontname) {
|
||||
*/
|
||||
static void addAvailableLanguages(const std::string &datadir,
|
||||
std::vector<std::string> *langs) {
|
||||
if (!std::filesystem::exists(datadir) ||
|
||||
!std::filesystem::is_directory(datadir)) {
|
||||
if (!std::filesystem::is_directory(datadir))
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& entry :
|
||||
std::filesystem::recursive_directory_iterator(datadir,
|
||||
std::filesystem::directory_options::follow_directory_symlink |
|
||||
@ -400,7 +399,7 @@ void TessBaseAPI::GetLoadedLanguagesAsVector(std::vector<std::string> *langs) co
|
||||
void TessBaseAPI::GetAvailableLanguagesAsVector(std::vector<std::string> *langs) const {
|
||||
langs->clear();
|
||||
if (tesseract_ != nullptr) {
|
||||
addAvailableLanguages(tesseract_->datadir.string().c_str(), langs);
|
||||
addAvailableLanguages(tesseract_->datadir.string(), langs);
|
||||
std::sort(langs->begin(), langs->end());
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ bool Tesseract::init_tesseract_lang_data(const std::string &arg0,
|
||||
|
||||
// Initialize TessdataManager.
|
||||
if (!mgr->is_loaded() && !mgr->Init(tessdata_path.string().c_str())) {
|
||||
tprintf("Error opening data file %s\n", tessdata_path.string().c_str());
|
||||
tprintf("Error opening data file %s\n", tessdata_path.string());
|
||||
tprintf(
|
||||
"Please make sure the TESSDATA_PREFIX environment variable is set"
|
||||
" to your \"tessdata\" directory.\n");
|
||||
@ -184,8 +184,7 @@ bool Tesseract::init_tesseract_lang_data(const std::string &arg0,
|
||||
else if (!mgr->GetComponent(TESSDATA_UNICHARSET, &fp) || !unicharset.load_from_file(&fp, false)) {
|
||||
tprintf(
|
||||
"Error: Tesseract (legacy) engine requested, but components are "
|
||||
"not present in %s!!\n",
|
||||
tessdata_path.string().c_str());
|
||||
"not present in %s!!\n", tessdata_path.string());
|
||||
return false;
|
||||
}
|
||||
#endif // ndef DISABLED_LEGACY_ENGINE
|
||||
|
@ -50,10 +50,9 @@ std::filesystem::path find_data_path(const std::string &argv0) {
|
||||
// If argv0 is set, always use it even if it is not a valid directory
|
||||
if (!argv0.empty()) {
|
||||
std::filesystem::path path(argv0);
|
||||
if (!std::filesystem::exists(path) ||
|
||||
!std::filesystem::is_directory(path)) {
|
||||
if (!std::filesystem::is_directory(path)) {
|
||||
tprintf("Warning (tessdata): '%s' is not a valid directory.\n",
|
||||
argv0.c_str());
|
||||
argv0);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user