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