tesseract  4.00.00dev
OrientationDetector Class Reference

#include <osdetect.h>

Public Member Functions

 OrientationDetector (const GenericVector< int > *allowed_scripts, OSResults *results)
 
bool detect_blob (BLOB_CHOICE_LIST *scores)
 
int get_orientation ()
 

Detailed Description

Definition at line 82 of file osdetect.h.

Constructor & Destructor Documentation

◆ OrientationDetector()

OrientationDetector::OrientationDetector ( const GenericVector< int > *  allowed_scripts,
OSResults results 
)

Definition at line 371 of file osdetect.cpp.

372  {
373  osr_ = osr;
374  allowed_scripts_ = allowed_scripts;
375 }

Member Function Documentation

◆ detect_blob()

bool OrientationDetector::detect_blob ( BLOB_CHOICE_LIST *  scores)

Definition at line 379 of file osdetect.cpp.

379  {
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 }
bool empty() const
Definition: genericvector.h:90
int size() const
Definition: genericvector.h:72
float certainty() const
Definition: ratngs.h:82
float orientations[4]
Definition: osdetect.h:74
int script_id() const
Definition: ratngs.h:111

◆ get_orientation()

int OrientationDetector::get_orientation ( )

Definition at line 444 of file osdetect.cpp.

444  {
445  osr_->update_best_orientation();
446  return osr_->best_result.orientation_id;
447 }
void update_best_orientation()
Definition: osdetect.cpp:64
int orientation_id
Definition: osdetect.h:41
OSBestResult best_result
Definition: osdetect.h:79

The documentation for this class was generated from the following files: