tesseract  5.0.0-alpha-619-ge9db
tesseract::MockClassifier Class Reference
Inheritance diagram for tesseract::MockClassifier:
tesseract::ShapeClassifier

Public Member Functions

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

Additional Inherited Members

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

Detailed Description

Definition at line 70 of file mastertrainer_test.cc.

Constructor & Destructor Documentation

◆ MockClassifier()

tesseract::MockClassifier::MockClassifier ( ShapeTable shape_table)
inlineexplicit

Definition at line 72 of file mastertrainer_test.cc.

73  : shape_table_(shape_table), num_done_(0), done_bad_font_(false) {
74  // Add a false font answer to the shape table. We pick a random unichar_id,
75  // add a new shape for it with a false font. Font must actually exist in
76  // the font table, but not match anything in the first 1000 samples.
77  false_unichar_id_ = 67;
78  false_shape_ = shape_table_->AddShape(false_unichar_id_, 25);
79  }

◆ ~MockClassifier()

virtual tesseract::MockClassifier::~MockClassifier ( )
inlinevirtual

Definition at line 80 of file mastertrainer_test.cc.

80 {}

Member Function Documentation

◆ ClassifySample()

virtual int tesseract::MockClassifier::ClassifySample ( const TrainingSample sample,
Pix *  page_pix,
int  debug,
UNICHAR_ID  keep_this,
GenericVector< ShapeRating > *  results 
)
inlinevirtual

Reimplemented from tesseract::ShapeClassifier.

Definition at line 88 of file mastertrainer_test.cc.

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

◆ GetShapeTable()

virtual const ShapeTable* tesseract::MockClassifier::GetShapeTable ( ) const
inlinevirtual

Implements tesseract::ShapeClassifier.

Definition at line 130 of file mastertrainer_test.cc.

130 { return shape_table_; }

The documentation for this class was generated from the following file:
GenericVector::push_back
int push_back(T object)
Definition: genericvector.h:799
sample
Definition: cluster.h:31
GenericVector::clear
void clear()
Definition: genericvector.h:857
tesseract::ShapeTable::FindShape
int FindShape(int unichar_id, int font_id) const
Definition: shapetable.cpp:386
tesseract::ShapeTable::AddShape
int AddShape(int unichar_id, int font_id)
Definition: shapetable.cpp:336
GenericVector::size
int size() const
Definition: genericvector.h:71