tesseract
5.0.0-alpha-619-ge9db
|
Go to the documentation of this file.
20 #include "allheaders.h"
44 const STRING& output_basename,
45 BLOCK_LIST *block_list) {
46 STRING lstmf_name = output_basename +
".lstmf";
51 tprintf(
"Failed to read training data from %s!\n", lstmf_name.
c_str());
61 tprintf(
"Failed to read boxes from %s\n", input_imagename.
c_str());
66 tprintf(
"Failed to read pages from %s\n", input_imagename.
c_str());
71 tprintf(
"Failed to write training data to %s!\n", lstmf_name.
c_str());
82 BLOCK_LIST *block_list,
84 int box_count = boxes.
size();
89 while (end_box < texts.
size() && texts[end_box] ==
"\t") ++end_box;
90 for (
int start_box = end_box; start_box < box_count; start_box = end_box) {
92 TBOX line_box = boxes[start_box];
93 STRING line_str = texts[start_box];
94 for (end_box = start_box + 1; end_box < box_count && texts[end_box] !=
"\t";
96 line_box += boxes[end_box];
97 line_str += texts[end_box];
100 BLOCK* best_block =
nullptr;
101 int best_overlap = 0;
102 BLOCK_IT b_it(block_list);
103 for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
104 BLOCK* block = b_it.data();
111 if (overlap_box.
area() > best_overlap) {
112 best_overlap = overlap_box.
area();
118 if (best_block ==
nullptr) {
119 tprintf(
"No block overlapping textline: %s\n", line_str.
c_str());
121 imagedata =
GetLineData(line_box, boxes, texts, start_box, end_box,
124 if (imagedata !=
nullptr)
128 while (end_box < texts.
size() && texts[end_box] ==
"\t") ++end_box;
138 int start_box,
int end_box,
139 const BLOCK& block) {
143 if (image_data ==
nullptr)
return nullptr;
150 for (
int b = start_box; b < end_box; ++b) {
152 box.
rotate(block_rotation);
159 image_data->
AddBoxes(line_boxes, line_texts, page_numbers);
170 int padding,
TBOX* revised_box)
const {
172 wbox.
pad(padding, padding);
176 int num_rotations = 0;
190 int width = pixGetWidth(pix);
191 int height = pixGetHeight(pix);
192 TBOX image_box(0, 0, width, height);
194 *revised_box &= image_box;
195 if (revised_box->
null_box())
return nullptr;
196 Box* clip_box = boxCreate(revised_box->
left(), height - revised_box->
top(),
198 Pix* box_pix = pixClipRectangle(pix, clip_box,
nullptr);
199 if (box_pix ==
nullptr)
return nullptr;
200 boxDestroy(&clip_box);
201 if (num_rotations > 0) {
202 Pix* rot_pix = pixRotateOrth(box_pix, num_rotations);
203 pixDestroy(&box_pix);
207 int depth = pixGetDepth(box_pix);
210 grey = pixConvertTo8(box_pix,
false);
211 pixDestroy(&box_pix);
214 bool vertical_text =
false;
215 if (num_rotations > 0) {
218 revised_box->
rotate(rotation);
219 if (num_rotations != 2)
220 vertical_text =
true;
222 return new ImageData(vertical_text, box_pix);
225 #ifndef ANDROID_BUILD
245 if (im_data ==
nullptr)
return;
264 const Dict* stopper_dict = lstm_recognizer_->
GetDict();
265 if (stopper_dict ==
nullptr) stopper_dict = &
getDict();
266 bool any_nonspace_delimited =
false;
267 for (
int w = 0; w < words->
size(); ++w) {
271 any_nonspace_delimited =
true;
275 for (
int w = 0; w < words->
size(); ++w) {
296 tprintf(
"Best choice certainty=%g, space=%g, scaled=%g, final=%g\n",
309 #endif // ANDROID_BUILD
void move(const ICOORD vec)
TBOX intersection(const TBOX &box) const
float base_line(float xpos) const
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
void initialise(int16_t length)
TBOX bounding_box() const
void set_certainty(float new_val)
const float kCertaintyScale
void AddBoxes(const GenericVector< TBOX > &boxes, const GenericVector< STRING > &texts, const GenericVector< int > &box_pages)
int tessedit_pageseg_mode
GenericVector< int > best_state
void LSTMRecognizeWord(const BLOCK &block, ROW *row, WERD_RES *word, PointerVector< WERD_RES > *words)
int state(int index) const
const UNICHARSET & GetUnicharset() const
void rotate(const FCOORD &vec)
Treat the image as a single word.
int lstm_choice_iterations
bool AcceptableResult(WERD_RES *word) const
bool SaveDocument(const char *filename, FileWriter writer)
void RecognizeLine(const ImageData &image_data, bool invert, bool debug, double worst_dict_cert, const TBOX &line_box, PointerVector< WERD_RES > *words, int lstm_choice_mode=0, int lstm_choice_amount=5)
PDBLK pdblk
Page Description Block.
WERD_CHOICE * best_choice
ImageData * GetRectImage(const TBOX &box, const BLOCK &block, int padding, TBOX *revised_box) const
const char * c_str() const
POLY_BLOCK * poly_block() const
const float kWorstDictCertainty
Dict & getDict() override
bool ContainsAnyNonSpaceDelimited() const
void AddPageToDocument(ImageData *page)
const ICOORD & botleft() const
bool LoadDocument(const char *filename, int start_page, int64_t max_memory, FileReader reader)
bool ReadAllBoxes(int target_page, bool skip_blanks, const STRING &filename, GenericVector< TBOX > *boxes, GenericVector< STRING > *texts, GenericVector< STRING > *box_texts, GenericVector< int > *pages)
void TrainFromBoxes(const GenericVector< TBOX > &boxes, const GenericVector< STRING > &texts, BLOCK_LIST *block_list, DocumentData *training_data)
bool TrainLineRecognizer(const STRING &input_imagename, const STRING &output_basename, BLOCK_LIST *block_list)
void SetupFake(const UNICHARSET &uch)
void pad(int xpad, int ypad)
tesseract::Tesseract * tesseract
bool major_overlap(const TBOX &box) const
void init_to_size(int size, const T &t)
void set_page_number(int num)
DLLSYM void tprintf(const char *format,...)
const Dict * GetDict() const
void SearchWords(PointerVector< WERD_RES > *words)
ImageData * GetLineData(const TBOX &line_box, const GenericVector< TBOX > &boxes, const GenericVector< STRING > &texts, int start_box, int end_box, const BLOCK &block)
FCOORD re_rotation() const