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