tesseract  4.0.0-1-g2a2b
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 "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 "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  }
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.string (), '.');
198  if (lastdot != nullptr)
199  name[lastdot-name.string()] = '\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  BLOBNBOX** 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++] = (BLOBNBOX*)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 (int i = 0; i < 4; ++i) {
420  if (blob_o_score[i] > 0.0f) {
421  ++num_good_scores;
422  if (worst_score == 0.0f || blob_o_score[i] < worst_score)
423  worst_score = blob_o_score[i];
424  }
425  }
426  if (num_good_scores == 1) {
427  // Lower worst if there is only one.
428  worst_score /= 2.0f;
429  }
430  for (int i = 0; i < 4; ++i) {
431  if (blob_o_score[i] == 0.0f) {
432  blob_o_score[i] = 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  bool done[kMaxNumberOfScripts];
473  for (int i = 0; i < 4; ++i) {
474  for (int j = 0; j < kMaxNumberOfScripts; ++j)
475  done[j] = false;
476 
477  BLOB_CHOICE_IT choice_it;
478  choice_it.set_to_list(scores + i);
479 
480  float prev_score = -1;
481  int script_count = 0;
482  int prev_id = -1;
483  int prev_fontinfo_id = -1;
484  const char* prev_unichar = "";
485  const char* unichar = "";
486 
487  for (choice_it.mark_cycle_pt(); !choice_it.cycled_list();
488  choice_it.forward()) {
489  BLOB_CHOICE* choice = choice_it.data();
490  int id = choice->script_id();
491  if (allowed_scripts_ != nullptr && !allowed_scripts_->empty()) {
492  // Check that the choice is in an allowed script.
493  int s = 0;
494  for (s = 0; s < allowed_scripts_->size(); ++s) {
495  if ((*allowed_scripts_)[s] == id) break;
496  }
497  if (s == allowed_scripts_->size()) continue; // Not found in list.
498  }
499  // Script already processed before.
500  if (done[id]) continue;
501  done[id] = true;
502 
503  unichar = tess_->unicharset.id_to_unichar(choice->unichar_id());
504  // Save data from the first match
505  if (prev_score < 0) {
506  prev_score = -choice->certainty();
507  script_count = 1;
508  prev_id = id;
509  prev_unichar = unichar;
510  prev_fontinfo_id = choice->fontinfo_id();
511  } else if (-choice->certainty() < prev_score + kNonAmbiguousMargin) {
512  ++script_count;
513  }
514 
515  if (strlen(prev_unichar) == 1)
516  if (unichar[0] >= '0' && unichar[0] <= '9')
517  break;
518 
519  // if script_count is >= 2, character is ambiguous, skip other matches
520  // since they are useless.
521  if (script_count >= 2)
522  break;
523  }
524  // Character is non ambiguous
525  if (script_count == 1) {
526  // Update the score of the winning script
527  osr_->scripts_na[i][prev_id] += 1.0;
528 
529  // Workaround for Fraktur
530  if (prev_id == latin_id_) {
531  if (prev_fontinfo_id >= 0) {
532  const tesseract::FontInfo &fi =
533  tess_->get_fontinfo_table().get(prev_fontinfo_id);
534  //printf("Font: %s i:%i b:%i f:%i s:%i k:%i (%s)\n", fi.name,
535  // fi.is_italic(), fi.is_bold(), fi.is_fixed_pitch(),
536  // fi.is_serif(), fi.is_fraktur(),
537  // prev_unichar);
538  if (fi.is_fraktur()) {
539  osr_->scripts_na[i][prev_id] -= 1.0;
540  osr_->scripts_na[i][fraktur_id_] += 1.0;
541  }
542  }
543  }
544 
545  // Update Japanese / Korean pseudo-scripts
546  if (prev_id == katakana_id_)
547  osr_->scripts_na[i][japanese_id_] += 1.0;
548  if (prev_id == hiragana_id_)
549  osr_->scripts_na[i][japanese_id_] += 1.0;
550  if (prev_id == hangul_id_)
551  osr_->scripts_na[i][korean_id_] += 1.0;
552  if (prev_id == han_id_) {
553  osr_->scripts_na[i][korean_id_] += kHanRatioInKorean;
554  osr_->scripts_na[i][japanese_id_] += kHanRatioInJapanese;
555  }
556  }
557  } // iterate over each orientation
558 }
559 
560 bool ScriptDetector::must_stop(int orientation) {
561  osr_->update_best_script(orientation);
562  return osr_->best_result.sconfidence > 1;
563 }
564 
565 // Helper method to convert an orientation index to its value in degrees.
566 // The value represents the amount of clockwise rotation in degrees that must be
567 // applied for the text to be upright (readable).
568 int OrientationIdToValue(const int& id) {
569  switch (id) {
570  case 0:
571  return 0;
572  case 1:
573  return 270;
574  case 2:
575  return 180;
576  case 3:
577  return 90;
578  default:
579  return -1;
580  }
581 }
OrientationDetector(const GenericVector< int > *allowed_scripts, OSResults *results)
Definition: osdetect.cpp:374
UNICHARSET * unicharset
Definition: osdetect.h:80
const ICOORD & topright() const
Definition: rect.h:104
bool must_stop(int orientation)
Definition: osdetect.cpp:560
float certainty() const
Definition: ratngs.h:83
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
Definition: blobs.cpp:337
int size() const
Definition: genericvector.h:71
void update_best_orientation()
Definition: osdetect.cpp:62
bool os_detect_blob(BLOBNBOX *bbox, OrientationDetector *o, ScriptDetector *s, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:329
void set_top(int y)
Definition: rect.h:61
UnicityTable< FontInfo > & get_fontinfo_table()
Definition: classify.h:386
void set_best_orientation(int orientation_id)
Definition: osdetect.cpp:84
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:849
void set_bottom(int y)
Definition: rect.h:68
const char * string() const
Definition: strngs.cpp:196
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
Definition: adaptmatch.cpp:192
void rotate(const FCOORD vec)
Definition: points.h:764
int os_detect(TO_BLOCK_LIST *port_blocks, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:233
Definition: rect.h:34
const int kBlnXHeight
Definition: normalis.h:24
int script_id
Definition: osdetect.h:44
const float kScriptAcceptRatio
Definition: osdetect.cpp:43
void find_components(Pix *pix, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks)
Definition: tordmain.cpp:219
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:78
const int kBlnBaselineOffset
Definition: normalis.h:25
void print_scores(void) const
Definition: osdetect.cpp:126
int orientation_and_script_detection(STRING &filename, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:190
float orientations[4]
Definition: osdetect.h:76
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:241
int16_t fontinfo_id() const
Definition: ratngs.h:86
float sconfidence
Definition: osdetect.h:45
OSBestResult best_result
Definition: osdetect.h:81
void set_right(int x)
Definition: rect.h:82
int orientation_id
Definition: osdetect.h:43
int16_t width() const
Definition: rect.h:115
int16_t left() const
Definition: rect.h:72
ScriptDetector(const GenericVector< int > *allowed_scripts, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:453
int16_t top() const
Definition: rect.h:58
void update_best_script(int orientation_id)
Definition: osdetect.cpp:89
UNICHARSET unicharset
Definition: ccutil.h:68
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:407
const int kMaxNumberOfScripts
Definition: osdetect.h:38
void detect_blob(BLOB_CHOICE_LIST *scores)
Definition: osdetect.cpp:471
POLY_BLOCK * poly_block() const
Definition: pdblock.h:56
Pix * pix_binary() const
bool empty() const
Definition: genericvector.h:90
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
TBOX bounding_box() const
Definition: blobs.cpp:478
bool IsText() const
Definition: polyblk.h:49
Textord * mutable_textord()
const float kSizeRatioToReject
Definition: osdetect.cpp:40
void accumulate(const OSResults &osr)
Definition: osdetect.cpp:144
BLOCK * block
Definition: blobbox.h:790
void set_left(int x)
Definition: rect.h:75
void filter_blobs(ICOORD page_tr, TO_BLOCK_LIST *blocks, bool testing_on)
Definition: tordmain.cpp:250
const float kHanRatioInJapanese
Definition: osdetect.cpp:46
Definition: strngs.h:45
TBOX bounding_box() const
Definition: stepblob.cpp:255
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290
int script_id() const
Definition: ratngs.h:112
Definition: points.h:189
bool detect_blob(BLOB_CHOICE_LIST *scores)
Definition: osdetect.cpp:382
int16_t right() const
Definition: rect.h:79
BLOBNBOX_LIST blobs
Definition: blobbox.h:785
bool read_unlv_file(STRING name, int32_t xsize, int32_t ysize, BLOCK_LIST *blocks)
Definition: blread.cpp:34
const int kMinAcceptableBlobHeight
Definition: osdetect.cpp:41
float oconfidence
Definition: osdetect.h:46
static Pix * FindImages(Pix *pix, DebugPixa *pixa_debug)
Definition: imagefind.cpp:63
int OrientationIdToValue(const int &id)
Definition: osdetect.cpp:568
Definition: blobs.h:268
void FullPageBlock(int width, int height, BLOCK_LIST *blocks)
Definition: blread.cpp:65
TESS_API int get_best_script(int orientation_id) const
Definition: osdetect.cpp:112
bool is_fraktur() const
Definition: fontinfo.h:115
constexpr int kMinCredibleResolution
Definition: publictypes.h:38
int16_t bottom() const
Definition: rect.h:65
UNICHAR_ID unichar_id() const
Definition: ratngs.h:77
PDBLK pdblk
Definition: ocrblock.h:192
int16_t height() const
Definition: rect.h:108
const float kNonAmbiguousMargin
Definition: osdetect.cpp:48
C_BLOB * cblob() const
Definition: blobbox.h:269
const float kHanRatioInKorean
Definition: osdetect.cpp:45
int add_script(const char *script)
int os_detect_blobs(const GenericVector< int > *allowed_scripts, BLOBNBOX_CLIST *blob_list, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:278
#define ASSERT_HOST(x)
Definition: errcode.h:84