tesseract 4.1.1
Loading...
Searching...
No Matches
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 84 of file osdetect.h.

Constructor & Destructor Documentation

◆ OrientationDetector()

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

Definition at line 374 of file osdetect.cpp.

375 {
376 osr_ = osr;
377 allowed_scripts_ = allowed_scripts;
378}

Member Function Documentation

◆ detect_blob()

bool OrientationDetector::detect_blob ( BLOB_CHOICE_LIST *  scores)

Definition at line 382 of file osdetect.cpp.

382 {
383 float blob_o_score[4] = {0.0f, 0.0f, 0.0f, 0.0f};
384 float total_blob_o_score = 0.0f;
385
386 for (int i = 0; i < 4; ++i) {
387 BLOB_CHOICE_IT choice_it(scores + i);
388 if (!choice_it.empty()) {
389 BLOB_CHOICE* choice = nullptr;
390 if (allowed_scripts_ != nullptr && !allowed_scripts_->empty()) {
391 // Find the top choice in an allowed script.
392 for (choice_it.mark_cycle_pt(); !choice_it.cycled_list() &&
393 choice == nullptr; choice_it.forward()) {
394 int choice_script = choice_it.data()->script_id();
395 int s = 0;
396 for (s = 0; s < allowed_scripts_->size(); ++s) {
397 if ((*allowed_scripts_)[s] == choice_script) {
398 choice = choice_it.data();
399 break;
400 }
401 }
402 }
403 } else {
404 choice = choice_it.data();
405 }
406 if (choice != nullptr) {
407 // The certainty score ranges between [-20,0]. This is converted here to
408 // [0,1], with 1 indicating best match.
409 blob_o_score[i] = 1 + 0.05 * choice->certainty();
410 total_blob_o_score += blob_o_score[i];
411 }
412 }
413 }
414 if (total_blob_o_score == 0.0) return false;
415 // Fill in any blanks with the worst score of the others. This is better than
416 // picking an arbitrary probability for it and way better than -inf.
417 float worst_score = 0.0f;
418 int num_good_scores = 0;
419 for (float f : blob_o_score) {
420 if (f > 0.0f) {
421 ++num_good_scores;
422 if (worst_score == 0.0f || f < worst_score)
423 worst_score = f;
424 }
425 }
426 if (num_good_scores == 1) {
427 // Lower worst if there is only one.
428 worst_score /= 2.0f;
429 }
430 for (float& f : blob_o_score) {
431 if (f == 0.0f) {
432 f = worst_score;
433 total_blob_o_score += worst_score;
434 }
435 }
436 // Normalize the orientation scores for the blob and use them to
437 // update the aggregated orientation score.
438 for (int i = 0; total_blob_o_score != 0 && i < 4; ++i) {
439 osr_->orientations[i] += log(blob_o_score[i] / total_blob_o_score);
440 }
441
442 // TODO(ranjith) Add an early exit test, based on min_orientation_margin,
443 // as used in pagesegmain.cpp.
444 return false;
445}
bool empty() const
Definition: genericvector.h:91
int size() const
Definition: genericvector.h:72
float orientations[4]
Definition: osdetect.h:76
float certainty() const
Definition: ratngs.h:83
int script_id() const
Definition: ratngs.h:114

◆ get_orientation()

int OrientationDetector::get_orientation ( )

Definition at line 447 of file osdetect.cpp.

447 {
449 return osr_->best_result.orientation_id;
450}
int orientation_id
Definition: osdetect.h:43
OSBestResult best_result
Definition: osdetect.h:81
void update_best_orientation()
Definition: osdetect.cpp:62

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