All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 ( const GenericVector< int > *  allowed_scripts,
OSResults results 
)

Definition at line 369 of file osdetect.cpp.

370  {
371  osr_ = osr;
372  allowed_scripts_ = allowed_scripts;
373 }

Member Function Documentation

bool OrientationDetector::detect_blob ( BLOB_CHOICE_LIST *  scores)

Definition at line 377 of file osdetect.cpp.

377  {
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 }
int size() const
Definition: genericvector.h:72
float orientations[4]
Definition: osdetect.h:74
bool empty() const
Definition: genericvector.h:84
#define NULL
Definition: host.h:144
float certainty() const
Definition: ratngs.h:82
int OrientationDetector::get_orientation ( )

Definition at line 442 of file osdetect.cpp.

442  {
443  osr_->update_best_orientation();
444  return osr_->best_result.orientation_id;
445 }
void update_best_orientation()
Definition: osdetect.cpp:67
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: