Skip to content

Commit

Permalink
C API: Add a function to init tesseract with traineddata from memory (t…
Browse files Browse the repository at this point in the history
…esseract-ocr#3780)

Fixes tesseract-ocr#3691.

* retrigger checks
  • Loading branch information
nico-abram authored Jun 20, 2022
1 parent cc06ae4 commit 71b045c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/tesseract/capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ TESS_API int TessBaseAPIInit4(TessBaseAPI *handle, const char *datapath,
char **vars_values, size_t vars_vec_size,
BOOL set_only_non_debug_params);

TESS_API int TessBaseAPIInit5(TessBaseAPI *handle, const char *data, int data_size,
const char *language, TessOcrEngineMode mode,
char **configs, int configs_size, char **vars_vec,
char **vars_values, size_t vars_vec_size,
BOOL set_only_non_debug_params);

TESS_API const char *TessBaseAPIGetInitLanguagesAsString(
const TessBaseAPI *handle);
TESS_API char **TessBaseAPIGetLoadedLanguagesAsVector(
Expand Down
16 changes: 16 additions & 0 deletions src/api/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@ int TessBaseAPIInit3(TessBaseAPI *handle, const char *datapath, const char *lang
return handle->Init(datapath, language);
}

int TessBaseAPIInit5(TessBaseAPI *handle, const char *data, int data_size, const char *language,
TessOcrEngineMode mode, char **configs, int configs_size, char **vars_vec,
char **vars_values, size_t vars_vec_size, BOOL set_only_non_debug_params) {
std::vector<std::string> varNames;
std::vector<std::string> varValues;
if (vars_vec != nullptr && vars_values != nullptr) {
for (size_t i = 0; i < vars_vec_size; i++) {
varNames.emplace_back(vars_vec[i]);
varValues.emplace_back(vars_values[i]);
}
}

return handle->Init(data, data_size, language, mode, configs, configs_size, &varNames, &varValues,
set_only_non_debug_params != 0, nullptr);
}

const char *TessBaseAPIGetInitLanguagesAsString(const TessBaseAPI *handle) {
return handle->GetInitLanguagesAsString();
}
Expand Down

0 comments on commit 71b045c

Please sign in to comment.