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