tesseract  5.0.0
MockClassifier Class Reference
Inheritance diagram for MockClassifier:
tesseract::ShapeClassifier

Public Member Functions

 MockClassifier (ShapeTable *shape_table)
 
 ~MockClassifier () override=default
 
int ClassifySample (const TrainingSample &sample, Image page_pix, int debug, UNICHAR_ID keep_this, std::vector< ShapeRating > *results) override
 
const ShapeTableGetShapeTable () const override
 
- Public Member Functions inherited from tesseract::ShapeClassifier
virtual ~ShapeClassifier ()=default
 
virtual int UnicharClassifySample (const TrainingSample &sample, Image page_pix, int debug, UNICHAR_ID keep_this, std::vector< UnicharRating > *results)
 
virtual int BestShapeForUnichar (const TrainingSample &sample, Image page_pix, UNICHAR_ID unichar_id, ShapeRating *result)
 
virtual const UNICHARSETGetUnicharset () const
 
void DebugDisplay (const TrainingSample &sample, Image page_pix, UNICHAR_ID unichar_id)
 
virtual int DisplayClassifyAs (const TrainingSample &sample, Image page_pix, UNICHAR_ID unichar_id, int index, std::vector< ScrollView * > &windows)
 
virtual void UnicharPrintResults (const char *context, const std::vector< UnicharRating > &results) const
 
virtual void PrintResults (const char *context, const std::vector< ShapeRating > &results) const
 

Additional Inherited Members

- Protected Member Functions inherited from tesseract::ShapeClassifier
void FilterDuplicateUnichars (std::vector< ShapeRating > *results) const
 

Detailed Description

Definition at line 63 of file mastertrainer_test.cc.

Constructor & Destructor Documentation

◆ MockClassifier()

MockClassifier::MockClassifier ( ShapeTable shape_table)
inlineexplicit

Definition at line 65 of file mastertrainer_test.cc.

66  : shape_table_(shape_table), num_done_(0), done_bad_font_(false) {
67  // Add a false font answer to the shape table. We pick a random unichar_id,
68  // add a new shape for it with a false font. Font must actually exist in
69  // the font table, but not match anything in the first 1000 samples.
70  false_unichar_id_ = 67;
71  false_shape_ = shape_table_->AddShape(false_unichar_id_, 25);
72  }
unsigned AddShape(int unichar_id, int font_id)
Definition: shapetable.cpp:351

◆ ~MockClassifier()

MockClassifier::~MockClassifier ( )
overridedefault

Member Function Documentation

◆ ClassifySample()

int MockClassifier::ClassifySample ( const TrainingSample sample,
Image  page_pix,
int  debug,
UNICHAR_ID  keep_this,
std::vector< ShapeRating > *  results 
)
inlineoverridevirtual

Reimplemented from tesseract::ShapeClassifier.

Definition at line 81 of file mastertrainer_test.cc.

82  {
83  results->clear();
84  // Everything except the first kNumNonReject is a reject.
85  if (++num_done_ > kNumNonReject) {
86  return 0;
87  }
88 
89  int class_id = sample.class_id();
90  int font_id = sample.font_id();
91  int shape_id = shape_table_->FindShape(class_id, font_id);
92  // Get ids of some wrong answers.
93  int wrong_id1 = shape_id > 10 ? shape_id - 1 : shape_id + 1;
94  int wrong_id2 = shape_id > 10 ? shape_id - 2 : shape_id + 2;
95  if (num_done_ <= kNumTopNErrs) {
96  // The first kNumTopNErrs are top-n errors.
97  results->push_back(ShapeRating(wrong_id1, 1.0f));
98  } else if (num_done_ <= kNumTop2Errs) {
99  // The next kNumTop2Errs - kNumTopNErrs are top-2 errors.
100  results->push_back(ShapeRating(wrong_id1, 1.0f));
101  results->push_back(ShapeRating(wrong_id2, 0.875f));
102  results->push_back(ShapeRating(shape_id, 0.75f));
103  } else if (num_done_ <= kNumTop1Errs) {
104  // The next kNumTop1Errs - kNumTop2Errs are top-1 errors.
105  results->push_back(ShapeRating(wrong_id1, 1.0f));
106  results->push_back(ShapeRating(shape_id, 0.8f));
107  } else if (num_done_ <= kNumTopTopErrs) {
108  // The next kNumTopTopErrs - kNumTop1Errs are cases where the actual top
109  // is not correct, but do not count as a top-1 error because the rating
110  // is close enough to the top answer.
111  results->push_back(ShapeRating(wrong_id1, 1.0f));
112  results->push_back(ShapeRating(shape_id, 0.99f));
113  } else if (!done_bad_font_ && class_id == false_unichar_id_) {
114  // There is a single character with a bad font.
115  results->push_back(ShapeRating(false_shape_, 1.0f));
116  done_bad_font_ = true;
117  } else {
118  // Everything else is correct.
119  results->push_back(ShapeRating(shape_id, 1.0f));
120  }
121  return results->size();
122  }
int FindShape(int unichar_id, int font_id) const
Definition: shapetable.cpp:400
UNICHAR_ID class_id() const

◆ GetShapeTable()

const ShapeTable* MockClassifier::GetShapeTable ( ) const
inlineoverridevirtual

Implements tesseract::ShapeClassifier.

Definition at line 124 of file mastertrainer_test.cc.

124  {
125  return shape_table_;
126  }

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