Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OrientationDetector Class Reference

#include <osdetect.h>

Public Member Functions

 OrientationDetector (OSResults *)
 
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 ( OSResults osr)

Definition at line 370 of file osdetect.cpp.

370  {
371  osr_ = osr;
372 }

Member Function Documentation

bool OrientationDetector::detect_blob ( BLOB_CHOICE_LIST *  scores)

Definition at line 376 of file osdetect.cpp.

376  {
377  float blob_o_score[4] = {0.0, 0.0, 0.0, 0.0};
378  float total_blob_o_score = 0.0;
379 
380  for (int i = 0; i < 4; ++i) {
381  BLOB_CHOICE_IT choice_it;
382  choice_it.set_to_list(scores + i);
383  if (!choice_it.empty()) {
384  // The certainty score ranges between [-20,0]. This is converted here to
385  // [0,1], with 1 indicating best match.
386  blob_o_score[i] = 1 + 0.05 * choice_it.data()->certainty();
387  total_blob_o_score += blob_o_score[i];
388  }
389  }
390  // Normalize the orientation scores for the blob and use them to
391  // update the aggregated orientation score.
392  for (int i = 0; total_blob_o_score != 0 && i < 4; ++i) {
393  osr_->orientations[i] += log(blob_o_score[i] / total_blob_o_score);
394  }
395 
396  float first = -1;
397  float second = -1;
398 
399  int idx = -1;
400  for (int i = 0; i < 4; ++i) {
401  if (osr_->orientations[i] > first) {
402  idx = i;
403  second = first;
404  first = osr_->orientations[i];
405  } else if (osr_->orientations[i] > second) {
406  second = osr_->orientations[i];
407  }
408  }
409 
410  return first / second > kOrientationAcceptRatio;
411 }
const float kOrientationAcceptRatio
Definition: osdetect.cpp:42
float orientations[4]
Definition: osdetect.h:74
int OrientationDetector::get_orientation ( )

Definition at line 413 of file osdetect.cpp.

413  {
414  osr_->update_best_orientation();
415  return osr_->best_result.orientation_id;
416 }
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: