#include <tessdatamanager.h>
|
| TessdataManager () |
|
| TessdataManager (FileReader reader) |
|
| ~TessdataManager () |
|
bool | swap () const |
|
bool | is_loaded () const |
|
void | LoadFileLater (const char *data_file_name) |
|
bool | Init (const char *data_file_name) |
|
bool | LoadMemBuffer (const char *name, const char *data, int size) |
|
void | OverwriteEntry (TessdataType type, const char *data, int size) |
|
bool | SaveFile (const STRING &filename, FileWriter writer) const |
|
void | Serialize (GenericVector< char > *data) const |
|
void | Clear () |
|
void | Directory () const |
|
bool | IsComponentAvailable (TessdataType type) const |
|
bool | GetComponent (TessdataType type, TFile *fp) |
|
bool | GetComponent (TessdataType type, TFile *fp) const |
|
string | VersionString () const |
|
void | SetVersionString (const string &v_str) |
|
bool | IsBaseAvailable () const |
|
bool | IsLSTMAvailable () const |
|
const STRING & | GetDataFileName () const |
|
bool | CombineDataFiles (const char *language_data_path_prefix, const char *output_filename) |
|
bool | OverwriteComponents (const char *new_traineddata_filename, char **component_filenames, int num_new_components) |
|
bool | ExtractToFile (const char *filename) |
|
Definition at line 131 of file tessdatamanager.h.
◆ TessdataManager() [1/2]
tesseract::TessdataManager::TessdataManager |
( |
| ) |
|
|
inline |
Definition at line 133 of file tessdatamanager.h.
133 : reader_(
nullptr), is_loaded_(
false), swap_(
false) {
#define TESSERACT_VERSION_STR
void SetVersionString(const string &v_str)
◆ TessdataManager() [2/2]
tesseract::TessdataManager::TessdataManager |
( |
FileReader |
reader | ) |
|
|
inlineexplicit |
Definition at line 136 of file tessdatamanager.h.
137 : reader_(reader), is_loaded_(
false), swap_(
false) {
#define TESSERACT_VERSION_STR
void SetVersionString(const string &v_str)
◆ ~TessdataManager()
tesseract::TessdataManager::~TessdataManager |
( |
| ) |
|
|
inline |
◆ Clear()
void tesseract::TessdataManager::Clear |
( |
| ) |
|
◆ CombineDataFiles()
bool tesseract::TessdataManager::CombineDataFiles |
( |
const char * |
language_data_path_prefix, |
|
|
const char * |
output_filename |
|
) |
| |
Reads all the standard tesseract config and data files for a language at the given path and bundles them up into one binary data file. Returns true if the combined traineddata file was successfully written.
Definition at line 186 of file tessdatamanager.cpp.
194 filename += kTessdataFileSuffixes[i];
195 FILE *fp = fopen(filename.
string(),
"rb");
209 "Error: traineddata file must contain at least (a unicharset file" 210 "and inttemp) OR an lstm file.\n");
214 return SaveFile(output_filename,
nullptr);
static bool TessdataTypeFromFileSuffix(const char *suffix, TessdataType *type)
bool SaveFile(const STRING &filename, FileWriter writer) const
bool IsLSTMAvailable() const
const char * string() const
bool LoadDataFromFile(const char *filename, GenericVector< char > *data)
bool IsBaseAvailable() const
◆ Directory()
void tesseract::TessdataManager::Directory |
( |
| ) |
const |
Definition at line 144 of file tessdatamanager.cpp.
148 if (!entries_[i].empty()) {
149 tprintf(
"%d:%s:size=%d, offset=%d\n", i, kTessdataFileSuffixes[i],
150 entries_[i].size(), offset);
151 offset += entries_[i].
size();
string VersionString() const
◆ ExtractToFile()
bool tesseract::TessdataManager::ExtractToFile |
( |
const char * |
filename | ) |
|
Extracts tessdata component implied by the name of the input file from the combined traineddata loaded into TessdataManager. Writes the extracted component to the file indicated by the file name. E.g. if the filename given is somepath/somelang.unicharset, unicharset will be extracted from the data loaded into the TessdataManager and will be written to somepath/somelang.unicharset.
- Returns
- true if the component was successfully extracted, false if the component was not present in the traineddata loaded into TessdataManager.
Definition at line 236 of file tessdatamanager.cpp.
240 if (entries_[type].empty())
return false;
static bool TessdataTypeFromFileName(const char *filename, TessdataType *type)
bool SaveDataToFile(const GenericVector< char > &data, const STRING &filename)
◆ GetComponent() [1/2]
Definition at line 158 of file tessdatamanager.cpp.
159 if (!is_loaded_ && !
Init(data_file_name_.
string()))
return false;
161 return const_this->GetComponent(type, fp);
const char * string() const
bool Init(const char *data_file_name)
◆ GetComponent() [2/2]
bool tesseract::TessdataManager::GetComponent |
( |
TessdataType |
type, |
|
|
TFile * |
fp |
|
) |
| const |
Definition at line 166 of file tessdatamanager.cpp.
168 if (entries_[type].empty())
return false;
169 fp->Open(&entries_[type][0], entries_[type].size());
◆ GetDataFileName()
const STRING& tesseract::TessdataManager::GetDataFileName |
( |
| ) |
const |
|
inline |
◆ Init()
bool tesseract::TessdataManager::Init |
( |
const char * |
data_file_name | ) |
|
Opens and reads the given data file right now.
- Returns
- true on success.
Definition at line 43 of file tessdatamanager.cpp.
45 if (reader_ ==
nullptr) {
48 if (!(*reader_)(data_file_name, &data))
return false;
bool LoadMemBuffer(const char *name, const char *data, int size)
bool LoadDataFromFile(const char *filename, GenericVector< char > *data)
◆ is_loaded()
bool tesseract::TessdataManager::is_loaded |
( |
| ) |
const |
|
inline |
◆ IsBaseAvailable()
bool tesseract::TessdataManager::IsBaseAvailable |
( |
| ) |
const |
|
inline |
◆ IsComponentAvailable()
bool tesseract::TessdataManager::IsComponentAvailable |
( |
TessdataType |
type | ) |
const |
|
inline |
◆ IsLSTMAvailable()
bool tesseract::TessdataManager::IsLSTMAvailable |
( |
| ) |
const |
|
inline |
◆ LoadFileLater()
void tesseract::TessdataManager::LoadFileLater |
( |
const char * |
data_file_name | ) |
|
◆ LoadMemBuffer()
bool tesseract::TessdataManager::LoadMemBuffer |
( |
const char * |
name, |
|
|
const char * |
data, |
|
|
int |
size |
|
) |
| |
Definition at line 54 of file tessdatamanager.cpp.
57 data_file_name_ = name;
61 if (fp.FRead(&num_entries,
sizeof(num_entries), 1) != 1)
return false;
62 swap_ = num_entries > kMaxNumTessdataEntries || num_entries < 0;
64 if (swap_)
ReverseN(&num_entries,
sizeof(num_entries));
65 if (num_entries > kMaxNumTessdataEntries || num_entries < 0)
return false;
68 if (fp.FReadEndian(&offset_table[0],
sizeof(offset_table[0]), num_entries) !=
72 if (offset_table[i] >= 0) {
73 inT64 entry_size = size - offset_table[i];
75 while (j < num_entries && offset_table[j] == -1) ++j;
76 if (j < num_entries) entry_size = offset_table[j] - offset_table[i];
78 if (fp.FRead(&entries_[i][0], 1, entry_size) != entry_size)
return false;
void resize_no_init(int size)
void ReverseN(void *ptr, int num_bytes)
void SetVersionString(const string &v_str)
◆ OverwriteComponents()
bool tesseract::TessdataManager::OverwriteComponents |
( |
const char * |
new_traineddata_filename, |
|
|
char ** |
component_filenames, |
|
|
int |
num_new_components |
|
) |
| |
Gets the individual components from the data_file_ with which the class was initialized. Overwrites the components specified by component_filenames. Writes the updated traineddata file to new_traineddata_filename.
Definition at line 217 of file tessdatamanager.cpp.
222 for (
int i = 0; i < num_new_components; ++i) {
226 tprintf(
"Failed to read component file:%s\n", component_filenames[i]);
233 return SaveFile(new_traineddata_filename,
nullptr);
static bool TessdataTypeFromFileName(const char *filename, TessdataType *type)
bool SaveFile(const STRING &filename, FileWriter writer) const
bool LoadDataFromFile(const char *filename, GenericVector< char > *data)
◆ OverwriteEntry()
void tesseract::TessdataManager::OverwriteEntry |
( |
TessdataType |
type, |
|
|
const char * |
data, |
|
|
int |
size |
|
) |
| |
Definition at line 89 of file tessdatamanager.cpp.
93 memcpy(&entries_[type][0], data, size);
void resize_no_init(int size)
◆ SaveFile()
bool tesseract::TessdataManager::SaveFile |
( |
const STRING & |
filename, |
|
|
FileWriter |
writer |
|
) |
| const |
Definition at line 97 of file tessdatamanager.cpp.
102 if (writer ==
nullptr)
void Serialize(GenericVector< char > *data) const
bool SaveDataToFile(const GenericVector< char > &data, const STRING &filename)
◆ Serialize()
void tesseract::TessdataManager::Serialize |
( |
GenericVector< char > * |
data | ) |
const |
Definition at line 109 of file tessdatamanager.cpp.
113 inT64 offset =
sizeof(
inT32) +
sizeof(offset_table);
115 if (entries_[i].empty()) {
116 offset_table[i] = -1;
118 offset_table[i] = offset;
119 offset += entries_[i].
size();
126 fp.FWrite(&num_entries,
sizeof(num_entries), 1);
127 fp.FWrite(offset_table,
sizeof(offset_table), 1);
129 if (!entries_[i].empty()) {
130 fp.FWrite(&entries_[i][0], entries_[i].size(), 1);
void init_to_size(int size, T t)
◆ SetVersionString()
void tesseract::TessdataManager::SetVersionString |
( |
const string & |
v_str | ) |
|
◆ swap()
bool tesseract::TessdataManager::swap |
( |
| ) |
const |
|
inline |
◆ TessdataTypeFromFileName()
bool tesseract::TessdataManager::TessdataTypeFromFileName |
( |
const char * |
filename, |
|
|
TessdataType * |
type |
|
) |
| |
|
static |
Tries to determine tessdata component file suffix from filename, returns true on success.
Definition at line 257 of file tessdatamanager.cpp.
260 const char *suffix = strrchr(
filename,
'.');
261 if (suffix ==
nullptr || *(++suffix) ==
'\0')
return false;
static bool TessdataTypeFromFileSuffix(const char *suffix, TessdataType *type)
◆ TessdataTypeFromFileSuffix()
bool tesseract::TessdataManager::TessdataTypeFromFileSuffix |
( |
const char * |
suffix, |
|
|
TessdataType * |
type |
|
) |
| |
|
static |
Fills type with TessdataType of the tessdata component represented by the given file name. E.g. tessdata/eng.unicharset -> TESSDATA_UNICHARSET.
- Returns
- true if the tessdata component type could be determined from the given file name.
Definition at line 244 of file tessdatamanager.cpp.
247 if (strcmp(kTessdataFileSuffixes[i], suffix) == 0) {
252 tprintf(
"TessdataManager can't determine which tessdata" 253 " component is represented by %s\n", suffix);
◆ VersionString()
string tesseract::TessdataManager::VersionString |
( |
| ) |
const |
The documentation for this class was generated from the following files: