tesseract  5.0.0-alpha-619-ge9db
osdetect.cpp
Go to the documentation of this file.
1 // File: osdetect.cpp
3 // Description: Orientation and script detection.
4 // Author: Samuel Charron
5 // Ranjith Unnikrishnan
6 //
7 // (C) Copyright 2008, Google Inc.
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
19 
20 #include <algorithm>
21 #include <cmath> // for std::fabs
22 #include <memory>
23 
24 #include <tesseract/osdetect.h>
25 
26 #include "blobbox.h"
27 #include "blread.h"
28 #include "colfind.h"
29 #include "fontinfo.h"
30 #include "imagefind.h"
31 #include "linefind.h"
32 #include "oldlist.h"
33 #include "qrsequence.h"
34 #include "ratngs.h"
35 #include <tesseract/strngs.h>
36 #include "tabvector.h"
37 #include "tesseractclass.h"
38 #include "textord.h"
39 
40 const float kSizeRatioToReject = 2.0;
41 const int kMinAcceptableBlobHeight = 10;
42 
43 const float kScriptAcceptRatio = 1.3;
44 
45 const float kHanRatioInKorean = 0.7;
46 const float kHanRatioInJapanese = 0.3;
47 
48 const float kNonAmbiguousMargin = 1.0;
49 
50 // General scripts
51 static const char* han_script = "Han";
52 static const char* latin_script = "Latin";
53 static const char* katakana_script = "Katakana";
54 static const char* hiragana_script = "Hiragana";
55 static const char* hangul_script = "Hangul";
56 
57 // Pseudo-scripts Name
58 const char* ScriptDetector::korean_script_ = "Korean";
59 const char* ScriptDetector::japanese_script_ = "Japanese";
60 const char* ScriptDetector::fraktur_script_ = "Fraktur";
61 
63  float first = orientations[0];
64  float second = orientations[1];
66  if (orientations[0] < orientations[1]) {
67  first = orientations[1];
68  second = orientations[0];
70  }
71  for (int i = 2; i < 4; ++i) {
72  if (orientations[i] > first) {
73  second = first;
74  first = orientations[i];
76  } else if (orientations[i] > second) {
77  second = orientations[i];
78  }
79  }
80  // Store difference of top two orientation scores.
81  best_result.oconfidence = first - second;
82 }
83 
84 void OSResults::set_best_orientation(int orientation_id) {
85  best_result.orientation_id = orientation_id;
87 }
88 
89 void OSResults::update_best_script(int orientation) {
90  // We skip index 0 to ignore the "Common" script.
91  float first = scripts_na[orientation][1];
92  float second = scripts_na[orientation][2];
94  if (scripts_na[orientation][1] < scripts_na[orientation][2]) {
95  first = scripts_na[orientation][2];
96  second = scripts_na[orientation][1];
98  }
99  for (int i = 3; i < kMaxNumberOfScripts; ++i) {
100  if (scripts_na[orientation][i] > first) {
102  second = first;
103  first = scripts_na[orientation][i];
104  } else if (scripts_na[orientation][i] > second) {
105  second = scripts_na[orientation][i];
106  }
107  }
108  best_result.sconfidence = (second == 0.0f) ? 2.0f :
109  (first / second - 1.0) / (kScriptAcceptRatio - 1.0);
110 }
111 
112 int OSResults::get_best_script(int orientation_id) const {
113  int max_id = -1;
114  for (int j = 0; j < kMaxNumberOfScripts; ++j) {
115  const char *script = unicharset->get_script_from_script_id(j);
116  if (strcmp(script, "Common") && strcmp(script, "NULL")) {
117  if (max_id == -1 ||
118  scripts_na[orientation_id][j] > scripts_na[orientation_id][max_id])
119  max_id = j;
120  }
121  }
122  return max_id;
123 }
124 
125 // Print the script scores for all possible orientations.
126 void OSResults::print_scores(void) const {
127  for (int i = 0; i < 4; ++i) {
128  tprintf("Orientation id #%d", i);
129  print_scores(i);
130  }
131 }
132 
133 // Print the script scores for the given candidate orientation.
134 void OSResults::print_scores(int orientation_id) const {
135  for (int j = 0; j < kMaxNumberOfScripts; ++j) {
136  if (scripts_na[orientation_id][j]) {
137  tprintf("%12s\t: %f\n", unicharset->get_script_from_script_id(j),
138  scripts_na[orientation_id][j]);
139  }
140  }
141 }
142 
143 // Accumulate scores with given OSResults instance and update the best script.
145  for (int i = 0; i < 4; ++i) {
146  orientations[i] += osr.orientations[i];
147  for (int j = 0; j < kMaxNumberOfScripts; ++j)
148  scripts_na[i][j] += osr.scripts_na[i][j];
149  }
150  unicharset = osr.unicharset;
153 }
154 
155 // Detect and erase horizontal/vertical lines and picture regions from the
156 // image, so that non-text blobs are removed from consideration.
157 static void remove_nontext_regions(tesseract::Tesseract *tess,
158  BLOCK_LIST *blocks,
159  TO_BLOCK_LIST *to_blocks) {
160  Pix *pix = tess->pix_binary();
161  ASSERT_HOST(pix != nullptr);
162  int vertical_x = 0;
163  int vertical_y = 1;
164  tesseract::TabVector_LIST v_lines;
165  tesseract::TabVector_LIST h_lines;
166  int resolution;
167  if (kMinCredibleResolution > pixGetXRes(pix)) {
168  resolution = kMinCredibleResolution;
169  tprintf("Warning. Invalid resolution %d dpi. Using %d instead.\n",
170  pixGetXRes(pix), resolution);
171  } else {
172  resolution = pixGetXRes(pix);
173  }
174 
175  tesseract::LineFinder::FindAndRemoveLines(resolution, false, pix,
176  &vertical_x, &vertical_y,
177  nullptr, &v_lines, &h_lines);
178  Pix* im_pix = tesseract::ImageFind::FindImages(pix, nullptr);
179  if (im_pix != nullptr) {
180  pixSubtract(pix, pix, im_pix);
181  pixDestroy(&im_pix);
182  }
183  tess->mutable_textord()->find_components(tess->pix_binary(),
184  blocks, to_blocks);
185 }
186 
187 // Find connected components in the page and process a subset until finished or
188 // a stopping criterion is met.
189 // Returns the number of blobs used in making the estimate. 0 implies failure.
191  OSResults* osr,
192  tesseract::Tesseract* tess) {
193  STRING name = filename; //truncated name
194  const char *lastdot; //of name
195  TBOX page_box;
196 
197  lastdot = strrchr(name.c_str(), '.');
198  if (lastdot != nullptr)
199  name[lastdot-name.c_str()] = '\0';
200 
201  ASSERT_HOST(tess->pix_binary() != nullptr);
202  int width = pixGetWidth(tess->pix_binary());
203  int height = pixGetHeight(tess->pix_binary());
204 
205  BLOCK_LIST blocks;
206  if (!read_unlv_file(name, width, height, &blocks))
207  FullPageBlock(width, height, &blocks);
208 
209  // Try to remove non-text regions from consideration.
210  TO_BLOCK_LIST land_blocks, port_blocks;
211  remove_nontext_regions(tess, &blocks, &port_blocks);
212 
213  if (port_blocks.empty()) {
214  // page segmentation did not succeed, so we need to find_components first.
215  tess->mutable_textord()->find_components(tess->pix_binary(),
216  &blocks, &port_blocks);
217  } else {
218  page_box.set_left(0);
219  page_box.set_bottom(0);
220  page_box.set_right(width);
221  page_box.set_top(height);
222  // Filter_blobs sets up the TO_BLOCKs the same as find_components does.
223  tess->mutable_textord()->filter_blobs(page_box.topright(),
224  &port_blocks, true);
225  }
226 
227  return os_detect(&port_blocks, osr, tess);
228 }
229 
230 // Filter and sample the blobs.
231 // Returns a non-zero number of blobs if the page was successfully processed, or
232 // zero if the page had too few characters to be reliable
233 int os_detect(TO_BLOCK_LIST* port_blocks, OSResults* osr,
234  tesseract::Tesseract* tess) {
235  int blobs_total = 0;
236  TO_BLOCK_IT block_it;
237  block_it.set_to_list(port_blocks);
238 
239  BLOBNBOX_CLIST filtered_list;
240  BLOBNBOX_C_IT filtered_it(&filtered_list);
241 
242  for (block_it.mark_cycle_pt(); !block_it.cycled_list();
243  block_it.forward ()) {
244  TO_BLOCK* to_block = block_it.data();
245  if (to_block->block->pdblk.poly_block() &&
246  !to_block->block->pdblk.poly_block()->IsText()) continue;
247  BLOBNBOX_IT bbox_it;
248  bbox_it.set_to_list(&to_block->blobs);
249  for (bbox_it.mark_cycle_pt (); !bbox_it.cycled_list ();
250  bbox_it.forward ()) {
251  BLOBNBOX* bbox = bbox_it.data();
252  C_BLOB* blob = bbox->cblob();
253  TBOX box = blob->bounding_box();
254  ++blobs_total;
255 
256  // Catch illegal value of box width and avoid division by zero.
257  if (box.width() == 0) continue;
258  // TODO: Can height and width be negative? If not, remove fabs.
259  float y_x = std::fabs((box.height() * 1.0f) / box.width());
260  float x_y = 1.0f / y_x;
261  // Select a >= 1.0 ratio
262  float ratio = x_y > y_x ? x_y : y_x;
263  // Blob is ambiguous
264  if (ratio > kSizeRatioToReject) continue;
265  if (box.height() < kMinAcceptableBlobHeight) continue;
266  filtered_it.add_to_end(bbox);
267  }
268  }
269  return os_detect_blobs(nullptr, &filtered_list, osr, tess);
270 }
271 
272 // Detect orientation and script from a list of blobs.
273 // Returns a non-zero number of blobs if the list was successfully processed, or
274 // zero if the list had too few characters to be reliable.
275 // If allowed_scripts is non-null and non-empty, it is a list of scripts that
276 // constrains both orientation and script detection to consider only scripts
277 // from the list.
278 int os_detect_blobs(const GenericVector<int>* allowed_scripts,
279  BLOBNBOX_CLIST* blob_list, OSResults* osr,
280  tesseract::Tesseract* tess) {
281  OSResults osr_;
282  int minCharactersToTry = tess->min_characters_to_try;
283  int maxCharactersToTry = 5 * minCharactersToTry;
284  if (osr == nullptr)
285  osr = &osr_;
286 
287  osr->unicharset = &tess->unicharset;
288  OrientationDetector o(allowed_scripts, osr);
289  ScriptDetector s(allowed_scripts, osr, tess);
290 
291  BLOBNBOX_C_IT filtered_it(blob_list);
292  int real_max = std::min(filtered_it.length(), maxCharactersToTry);
293  // tprintf("Total blobs found = %d\n", blobs_total);
294  // tprintf("Number of blobs post-filtering = %d\n", filtered_it.length());
295  // tprintf("Number of blobs to try = %d\n", real_max);
296 
297  // If there are too few characters, skip this page entirely.
298  if (real_max < minCharactersToTry / 2) {
299  tprintf("Too few characters. Skipping this page\n");
300  return 0;
301  }
302 
303  auto** blobs = new BLOBNBOX*[filtered_it.length()];
304  int number_of_blobs = 0;
305  for (filtered_it.mark_cycle_pt (); !filtered_it.cycled_list ();
306  filtered_it.forward ()) {
307  blobs[number_of_blobs++] = filtered_it.data();
308  }
309  QRSequenceGenerator sequence(number_of_blobs);
310  int num_blobs_evaluated = 0;
311  for (int i = 0; i < real_max; ++i) {
312  if (os_detect_blob(blobs[sequence.GetVal()], &o, &s, osr, tess)
313  && i > minCharactersToTry) {
314  break;
315  }
316  ++num_blobs_evaluated;
317  }
318  delete [] blobs;
319 
320  // Make sure the best_result is up-to-date
321  int orientation = o.get_orientation();
322  osr->update_best_script(orientation);
323  return num_blobs_evaluated;
324 }
325 
326 // Processes a single blob to estimate script and orientation.
327 // Return true if estimate of orientation and script satisfies stopping
328 // criteria.
330  ScriptDetector* s, OSResults* osr,
331  tesseract::Tesseract* tess) {
332  tess->tess_cn_matching.set_value(true); // turn it on
333  tess->tess_bn_matching.set_value(false);
334  C_BLOB* blob = bbox->cblob();
335  TBLOB* tblob = TBLOB::PolygonalCopy(tess->poly_allow_detailed_fx, blob);
336  TBOX box = tblob->bounding_box();
337  FCOORD current_rotation(1.0f, 0.0f);
338  FCOORD rotation90(0.0f, 1.0f);
339  BLOB_CHOICE_LIST ratings[4];
340  // Test the 4 orientations
341  for (int i = 0; i < 4; ++i) {
342  // Normalize the blob. Set the origin to the place we want to be the
343  // bottom-middle after rotation.
344  // Scaling is to make the rotated height the x-height.
345  float scaling = static_cast<float>(kBlnXHeight) / box.height();
346  float x_origin = (box.left() + box.right()) / 2.0f;
347  float y_origin = (box.bottom() + box.top()) / 2.0f;
348  if (i == 0 || i == 2) {
349  // Rotation is 0 or 180.
350  y_origin = i == 0 ? box.bottom() : box.top();
351  } else {
352  // Rotation is 90 or 270.
353  scaling = static_cast<float>(kBlnXHeight) / box.width();
354  x_origin = i == 1 ? box.left() : box.right();
355  }
356  std::unique_ptr<TBLOB> rotated_blob(new TBLOB(*tblob));
357  rotated_blob->Normalize(nullptr, &current_rotation, nullptr,
358  x_origin, y_origin, scaling, scaling,
359  0.0f, static_cast<float>(kBlnBaselineOffset),
360  false, nullptr);
361  tess->AdaptiveClassifier(rotated_blob.get(), ratings + i);
362  current_rotation.rotate(rotation90);
363  }
364  delete tblob;
365 
366  bool stop = o->detect_blob(ratings);
367  s->detect_blob(ratings);
368  int orientation = o->get_orientation();
369  stop = s->must_stop(orientation) && stop;
370  return stop;
371 }
372 
373 
375  const GenericVector<int>* allowed_scripts, OSResults* osr) {
376  osr_ = osr;
377  allowed_scripts_ = allowed_scripts;
378 }
379 
380 // Score the given blob and return true if it is now sure of the orientation
381 // after adding this block.
382 bool OrientationDetector::detect_blob(BLOB_CHOICE_LIST* scores) {
383  float blob_o_score[4] = {0.0f, 0.0f, 0.0f, 0.0f};
384  float total_blob_o_score = 0.0f;
385 
386  for (int i = 0; i < 4; ++i) {
387  BLOB_CHOICE_IT choice_it(scores + i);
388  if (!choice_it.empty()) {
389  BLOB_CHOICE* choice = nullptr;
390  if (allowed_scripts_ != nullptr && !allowed_scripts_->empty()) {
391  // Find the top choice in an allowed script.
392  for (choice_it.mark_cycle_pt(); !choice_it.cycled_list() &&
393  choice == nullptr; choice_it.forward()) {
394  int choice_script = choice_it.data()->script_id();
395  int s = 0;
396  for (s = 0; s < allowed_scripts_->size(); ++s) {
397  if ((*allowed_scripts_)[s] == choice_script) {
398  choice = choice_it.data();
399  break;
400  }
401  }
402  }
403  } else {
404  choice = choice_it.data();
405  }
406  if (choice != nullptr) {
407  // The certainty score ranges between [-20,0]. This is converted here to
408  // [0,1], with 1 indicating best match.
409  blob_o_score[i] = 1 + 0.05 * choice->certainty();
410  total_blob_o_score += blob_o_score[i];
411  }
412  }
413  }
414  if (total_blob_o_score == 0.0) return false;
415  // Fill in any blanks with the worst score of the others. This is better than
416  // picking an arbitrary probability for it and way better than -inf.
417  float worst_score = 0.0f;
418  int num_good_scores = 0;
419  for (float f : blob_o_score) {
420  if (f > 0.0f) {
421  ++num_good_scores;
422  if (worst_score == 0.0f || f < worst_score)
423  worst_score = f;
424  }
425  }
426  if (num_good_scores == 1) {
427  // Lower worst if there is only one.
428  worst_score /= 2.0f;
429  }
430  for (float& f : blob_o_score) {
431  if (f == 0.0f) {
432  f = worst_score;
433  total_blob_o_score += worst_score;
434  }
435  }
436  // Normalize the orientation scores for the blob and use them to
437  // update the aggregated orientation score.
438  for (int i = 0; total_blob_o_score != 0 && i < 4; ++i) {
439  osr_->orientations[i] += log(blob_o_score[i] / total_blob_o_score);
440  }
441 
442  // TODO(ranjith) Add an early exit test, based on min_orientation_margin,
443  // as used in pagesegmain.cpp.
444  return false;
445 }
446 
448  osr_->update_best_orientation();
449  return osr_->best_result.orientation_id;
450 }
451 
452 
454  OSResults* osr, tesseract::Tesseract* tess) {
455  osr_ = osr;
456  tess_ = tess;
457  allowed_scripts_ = allowed_scripts;
458  katakana_id_ = tess_->unicharset.add_script(katakana_script);
459  hiragana_id_ = tess_->unicharset.add_script(hiragana_script);
460  han_id_ = tess_->unicharset.add_script(han_script);
461  hangul_id_ = tess_->unicharset.add_script(hangul_script);
462  japanese_id_ = tess_->unicharset.add_script(japanese_script_);
463  korean_id_ = tess_->unicharset.add_script(korean_script_);
464  latin_id_ = tess_->unicharset.add_script(latin_script);
465  fraktur_id_ = tess_->unicharset.add_script(fraktur_script_);
466 }
467 
468 
469 // Score the given blob and return true if it is now sure of the script after
470 // adding this blob.
471 void ScriptDetector::detect_blob(BLOB_CHOICE_LIST* scores) {
472  for (int i = 0; i < 4; ++i) {
473  bool done[kMaxNumberOfScripts] = { false };
474 
475  BLOB_CHOICE_IT choice_it;
476  choice_it.set_to_list(scores + i);
477 
478  float prev_score = -1;
479  int script_count = 0;
480  int prev_id = -1;
481  int prev_fontinfo_id = -1;
482  const char* prev_unichar = "";
483  const char* unichar = "";
484 
485  for (choice_it.mark_cycle_pt(); !choice_it.cycled_list();
486  choice_it.forward()) {
487  BLOB_CHOICE* choice = choice_it.data();
488  int id = choice->script_id();
489  if (allowed_scripts_ != nullptr && !allowed_scripts_->empty()) {
490  // Check that the choice is in an allowed script.
491  int s = 0;
492  for (s = 0; s < allowed_scripts_->size(); ++s) {
493  if ((*allowed_scripts_)[s] == id) break;
494  }
495  if (s == allowed_scripts_->size()) continue; // Not found in list.
496  }
497  // Script already processed before.
498  if (done[id]) continue;
499  done[id] = true;
500 
501  unichar = tess_->unicharset.id_to_unichar(choice->unichar_id());
502  // Save data from the first match
503  if (prev_score < 0) {
504  prev_score = -choice->certainty();
505  script_count = 1;
506  prev_id = id;
507  prev_unichar = unichar;
508  prev_fontinfo_id = choice->fontinfo_id();
509  } else if (-choice->certainty() < prev_score + kNonAmbiguousMargin) {
510  ++script_count;
511  }
512 
513  if (strlen(prev_unichar) == 1)
514  if (unichar[0] >= '0' && unichar[0] <= '9')
515  break;
516 
517  // if script_count is >= 2, character is ambiguous, skip other matches
518  // since they are useless.
519  if (script_count >= 2)
520  break;
521  }
522  // Character is non ambiguous
523  if (script_count == 1) {
524  // Update the score of the winning script
525  osr_->scripts_na[i][prev_id] += 1.0;
526 
527  // Workaround for Fraktur
528  if (prev_id == latin_id_) {
529  if (prev_fontinfo_id >= 0) {
530  const tesseract::FontInfo &fi =
531  tess_->get_fontinfo_table().get(prev_fontinfo_id);
532  //printf("Font: %s i:%i b:%i f:%i s:%i k:%i (%s)\n", fi.name,
533  // fi.is_italic(), fi.is_bold(), fi.is_fixed_pitch(),
534  // fi.is_serif(), fi.is_fraktur(),
535  // prev_unichar);
536  if (fi.is_fraktur()) {
537  osr_->scripts_na[i][prev_id] -= 1.0;
538  osr_->scripts_na[i][fraktur_id_] += 1.0;
539  }
540  }
541  }
542 
543  // Update Japanese / Korean pseudo-scripts
544  if (prev_id == katakana_id_)
545  osr_->scripts_na[i][japanese_id_] += 1.0;
546  if (prev_id == hiragana_id_)
547  osr_->scripts_na[i][japanese_id_] += 1.0;
548  if (prev_id == hangul_id_)
549  osr_->scripts_na[i][korean_id_] += 1.0;
550  if (prev_id == han_id_) {
551  osr_->scripts_na[i][korean_id_] += kHanRatioInKorean;
552  osr_->scripts_na[i][japanese_id_] += kHanRatioInJapanese;
553  }
554  }
555  } // iterate over each orientation
556 }
557 
558 bool ScriptDetector::must_stop(int orientation) {
559  osr_->update_best_script(orientation);
560  return osr_->best_result.sconfidence > 1;
561 }
562 
563 // Helper method to convert an orientation index to its value in degrees.
564 // The value represents the amount of clockwise rotation in degrees that must be
565 // applied for the text to be upright (readable).
566 int OrientationIdToValue(const int& id) {
567  switch (id) {
568  case 0:
569  return 0;
570  case 1:
571  return 270;
572  case 2:
573  return 180;
574  case 3:
575  return 90;
576  default:
577  return -1;
578  }
579 }
strngs.h
tesseract::Tesseract::poly_allow_detailed_fx
bool poly_allow_detailed_fx
Definition: tesseractclass.h:1061
C_BLOB::bounding_box
TBOX bounding_box() const
Definition: stepblob.cpp:247
OSResults::best_result
OSBestResult best_result
Definition: osdetect.h:81
os_detect_blob
bool os_detect_blob(BLOBNBOX *bbox, OrientationDetector *o, ScriptDetector *s, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:329
kNonAmbiguousMargin
const float kNonAmbiguousMargin
Definition: osdetect.cpp:48
kHanRatioInKorean
const float kHanRatioInKorean
Definition: osdetect.cpp:45
OrientationDetector
Definition: osdetect.h:84
os_detect
int os_detect(TO_BLOCK_LIST *port_blocks, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:233
kBlnXHeight
const int kBlnXHeight
Definition: normalis.h:23
POLY_BLOCK::IsText
bool IsText() const
Definition: polyblk.h:62
kSizeRatioToReject
const float kSizeRatioToReject
Definition: osdetect.cpp:40
QRSequenceGenerator
Definition: qrsequence.h:32
tesseractclass.h
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
blread.h
tesseract::FontInfo::is_fraktur
bool is_fraktur() const
Definition: fontinfo.h:115
linefind.h
OSBestResult::script_id
int script_id
Definition: osdetect.h:45
language_specific.log
log
Definition: language_specific.py:25
blobbox.h
BLOB_CHOICE::certainty
float certainty() const
Definition: ratngs.h:81
tesseract::Tesseract
Definition: tesseractclass.h:172
OSResults::update_best_orientation
void update_best_orientation()
Definition: osdetect.cpp:62
TBOX::top
int16_t top() const
Definition: rect.h:57
OSResults
Definition: osdetect.h:50
STRING
Definition: strngs.h:45
UNICHARSET::get_script_from_script_id
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:844
TO_BLOCK::blobs
BLOBNBOX_LIST blobs
Definition: blobbox.h:771
TO_BLOCK
Definition: blobbox.h:691
TBOX::set_top
void set_top(int y)
Definition: rect.h:60
kMaxNumberOfScripts
const int kMaxNumberOfScripts
Definition: osdetect.h:39
OSResults::unicharset
UNICHARSET * unicharset
Definition: osdetect.h:80
BLOB_CHOICE::script_id
int script_id() const
Definition: ratngs.h:112
OSResults::get_best_script
TESS_API int get_best_script(int orientation_id) const
Definition: osdetect.cpp:112
FCOORD
Definition: points.h:187
BLOB_CHOICE::unichar_id
UNICHAR_ID unichar_id() const
Definition: ratngs.h:75
OSResults::print_scores
void print_scores(void) const
Definition: osdetect.cpp:126
BLOBNBOX
Definition: blobbox.h:142
oldlist.h
C_BLOB
Definition: stepblob.h:36
tesseract::CCUtil::unicharset
UNICHARSET unicharset
Definition: ccutil.h:57
TBOX::height
int16_t height() const
Definition: rect.h:107
ratngs.h
orientation_and_script_detection
int orientation_and_script_detection(STRING &filename, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:190
tesseract::Classify::get_fontinfo_table
UnicityTable< FontInfo > & get_fontinfo_table()
Definition: classify.h:386
tesseract::LineFinder::FindAndRemoveLines
static void FindAndRemoveLines(int resolution, bool debug, Pix *pix, int *vertical_x, int *vertical_y, Pix **pix_music_mask, TabVector_LIST *v_lines, TabVector_LIST *h_lines)
Definition: linefind.cpp:243
OSBestResult::orientation_id
int orientation_id
Definition: osdetect.h:44
TBOX::set_right
void set_right(int x)
Definition: rect.h:81
tesseract::Textord::find_components
void find_components(Pix *pix, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks)
Definition: tordmain.cpp:215
UNICHARSET::add_script
int add_script(const char *script)
Definition: unicharset.cpp:1020
colfind.h
BLOCK::pdblk
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:189
STRING::c_str
const char * c_str() const
Definition: strngs.cpp:192
OSResults::scripts_na
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:78
OSBestResult::oconfidence
float oconfidence
Definition: osdetect.h:47
PDBLK::poly_block
POLY_BLOCK * poly_block() const
Definition: pdblock.h:54
TO_BLOCK::block
BLOCK * block
Definition: blobbox.h:776
tesseract::Classify::AdaptiveClassifier
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
Definition: adaptmatch.cpp:191
QRSequenceGenerator::GetVal
int GetVal()
Definition: qrsequence.h:41
kMinCredibleResolution
constexpr int kMinCredibleResolution
Definition: publictypes.h:37
GenericVector::empty
bool empty() const
Definition: genericvector.h:86
TBOX::width
int16_t width() const
Definition: rect.h:114
tesseract::Tesseract::mutable_textord
Textord * mutable_textord()
Definition: tesseractclass.h:269
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
TBLOB::PolygonalCopy
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
Definition: blobs.cpp:326
tesseract::Classify::tess_cn_matching
bool tess_cn_matching
Definition: classify.h:443
textord.h
TBOX::topright
const ICOORD & topright() const
Definition: rect.h:103
kHanRatioInJapanese
const float kHanRatioInJapanese
Definition: osdetect.cpp:46
TBLOB::Normalize
void Normalize(const BLOCK *block, const FCOORD *rotation, const DENORM *predecessor, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift, bool inverse, Pix *pix)
Definition: blobs.cpp:396
OSResults::set_best_orientation
void set_best_orientation(int orientation_id)
Definition: osdetect.cpp:84
fontinfo.h
OSResults::orientations
float orientations[4]
Definition: osdetect.h:76
FCOORD::rotate
void rotate(const FCOORD vec)
Definition: points.h:736
tesseract::FontInfo
Definition: fontinfo.h:62
read_unlv_file
bool read_unlv_file(STRING name, int32_t xsize, int32_t ysize, BLOCK_LIST *blocks)
Definition: blread.cpp:31
ScriptDetector::detect_blob
void detect_blob(BLOB_CHOICE_LIST *scores)
Definition: osdetect.cpp:471
TBLOB::bounding_box
TBOX bounding_box() const
Definition: blobs.cpp:466
GenericVector< int >
tesseract::Tesseract::min_characters_to_try
int min_characters_to_try
Definition: tesseractclass.h:1012
BLOB_CHOICE::fontinfo_id
int16_t fontinfo_id() const
Definition: ratngs.h:84
OrientationDetector::OrientationDetector
OrientationDetector(const GenericVector< int > *allowed_scripts, OSResults *results)
Definition: osdetect.cpp:374
OSResults::update_best_script
void update_best_script(int orientation_id)
Definition: osdetect.cpp:89
BLOB_CHOICE
Definition: ratngs.h:49
OrientationDetector::get_orientation
int get_orientation()
Definition: osdetect.cpp:447
TBLOB
Definition: blobs.h:282
tesseract::Classify::tess_bn_matching
bool tess_bn_matching
Definition: classify.h:444
imagefind.h
tesseract::Tesseract::pix_binary
Pix * pix_binary() const
Definition: tesseractclass.h:200
TBOX::left
int16_t left() const
Definition: rect.h:71
kScriptAcceptRatio
const float kScriptAcceptRatio
Definition: osdetect.cpp:43
ScriptDetector::ScriptDetector
ScriptDetector(const GenericVector< int > *allowed_scripts, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:453
tesseract::ImageFind::FindImages
static Pix * FindImages(Pix *pix, DebugPixa *pixa_debug)
Definition: imagefind.cpp:62
TBOX::right
int16_t right() const
Definition: rect.h:78
ScriptDetector
Definition: osdetect.h:96
OrientationIdToValue
int OrientationIdToValue(const int &id)
Definition: osdetect.cpp:566
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
OSBestResult::sconfidence
float sconfidence
Definition: osdetect.h:46
qrsequence.h
OSResults::accumulate
void accumulate(const OSResults &osr)
Definition: osdetect.cpp:144
UNICHARSET::id_to_unichar
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290
TBOX::set_bottom
void set_bottom(int y)
Definition: rect.h:67
BLOBNBOX::cblob
C_BLOB * cblob() const
Definition: blobbox.h:267
OrientationDetector::detect_blob
bool detect_blob(BLOB_CHOICE_LIST *scores)
Definition: osdetect.cpp:382
ScriptDetector::must_stop
bool must_stop(int orientation)
Definition: osdetect.cpp:558
GenericVector::size
int size() const
Definition: genericvector.h:71
os_detect_blobs
int os_detect_blobs(const GenericVector< int > *allowed_scripts, BLOBNBOX_CLIST *blob_list, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:278
osdetect.h
tabvector.h
kBlnBaselineOffset
const int kBlnBaselineOffset
Definition: normalis.h:24
kMinAcceptableBlobHeight
const int kMinAcceptableBlobHeight
Definition: osdetect.cpp:41
tesseract::Textord::filter_blobs
void filter_blobs(ICOORD page_tr, TO_BLOCK_LIST *blocks, bool testing_on)
Definition: tordmain.cpp:245
TBOX::set_left
void set_left(int x)
Definition: rect.h:74
FullPageBlock
void FullPageBlock(int width, int height, BLOCK_LIST *blocks)
Definition: blread.cpp:63
TBOX
Definition: rect.h:33