tesseract v5.3.3.20231005
MasterTrainerTest Class Reference
Inheritance diagram for MasterTrainerTest:
testing::Test

Protected Member Functions

void SetUp () override
 
std::string TestDataNameToPath (const std::string &name)
 
std::string TmpNameToPath (const std::string &name)
 
 MasterTrainerTest ()
 
 ~MasterTrainerTest () override
 
void LoadMasterTrainer ()
 
void VerifyIl1 ()
 
- Protected Member Functions inherited from testing::Test
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 

Protected Attributes

ShapeTableshape_table_
 
std::unique_ptr< MasterTrainermaster_trainer_
 

Additional Inherited Members

- Public Member Functions inherited from testing::Test
virtual ~Test ()
 
- Static Public Member Functions inherited from testing::Test
static void SetUpTestSuite ()
 
static void TearDownTestSuite ()
 
static void TearDownTestCase ()
 
static void SetUpTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool IsSkipped ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 

Detailed Description

Definition at line 144 of file mastertrainer_test.cc.

Constructor & Destructor Documentation

◆ MasterTrainerTest()

MasterTrainerTest::MasterTrainerTest ( )
inlineprotected

Definition at line 159 of file mastertrainer_test.cc.

159 {
160 shape_table_ = nullptr;
161 master_trainer_ = nullptr;
162 }
std::unique_ptr< MasterTrainer > master_trainer_

◆ ~MasterTrainerTest()

MasterTrainerTest::~MasterTrainerTest ( )
inlineoverrideprotected

Definition at line 163 of file mastertrainer_test.cc.

163 {
164 delete shape_table_;
165 }

Member Function Documentation

◆ LoadMasterTrainer()

void MasterTrainerTest::LoadMasterTrainer ( )
inlineprotected

Definition at line 170 of file mastertrainer_test.cc.

170 {
171 FLAGS_output_trainer = TmpNameToPath("tmp_trainer").c_str();
172 FLAGS_F = file::JoinPath(LANGDATA_DIR, "font_properties").c_str();
173 FLAGS_X = TestDataNameToPath("eng.xheights").c_str();
174 FLAGS_U = TestDataNameToPath("eng.unicharset").c_str();
175 std::string tr_file_name(TestDataNameToPath("eng.Arial.exp0.tr"));
176 const char *filelist[] = {tr_file_name.c_str(), nullptr};
177 std::string file_prefix;
178 delete shape_table_;
179 shape_table_ = nullptr;
180 master_trainer_ = LoadTrainingData(filelist, false, &shape_table_, file_prefix);
181 EXPECT_TRUE(master_trainer_ != nullptr);
182 EXPECT_TRUE(shape_table_ != nullptr);
183 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1982
std::unique_ptr< MasterTrainer > LoadTrainingData(const char *const *filelist, bool replication, ShapeTable **shape_table, std::string &file_prefix)
static std::string JoinPath(const std::string &s1, const std::string &s2)
Definition: include_gunit.h:65
std::string TestDataNameToPath(const std::string &name)
std::string TmpNameToPath(const std::string &name)

◆ SetUp()

void MasterTrainerTest::SetUp ( )
inlineoverrideprotectedvirtual

Reimplemented from testing::Test.

Definition at line 147 of file mastertrainer_test.cc.

147 {
148 std::locale::global(std::locale(""));
150 }
static void MakeTmpdir()
Definition: include_gunit.h:38

◆ TestDataNameToPath()

std::string MasterTrainerTest::TestDataNameToPath ( const std::string &  name)
inlineprotected

Definition at line 152 of file mastertrainer_test.cc.

152 {
153 return file::JoinPath(TESTING_DIR, name);
154 }

◆ TmpNameToPath()

std::string MasterTrainerTest::TmpNameToPath ( const std::string &  name)
inlineprotected

Definition at line 155 of file mastertrainer_test.cc.

155 {
156 return file::JoinPath(FLAGS_test_tmpdir, name);
157 }

◆ VerifyIl1()

void MasterTrainerTest::VerifyIl1 ( )
inlineprotected

Definition at line 187 of file mastertrainer_test.cc.

187 {
188 // Find the font id for Arial.
189 int font_id = master_trainer_->GetFontInfoId("Arial");
190 EXPECT_GE(font_id, 0);
191 // Track down the characters we are interested in.
192 int unichar_I = master_trainer_->unicharset().unichar_to_id("I");
193 EXPECT_GT(unichar_I, 0);
194 int unichar_l = master_trainer_->unicharset().unichar_to_id("l");
195 EXPECT_GT(unichar_l, 0);
196 int unichar_1 = master_trainer_->unicharset().unichar_to_id("1");
197 EXPECT_GT(unichar_1, 0);
198 // Now get the shape ids.
199 int shape_I = shape_table_->FindShape(unichar_I, font_id);
200 EXPECT_GE(shape_I, 0);
201 int shape_l = shape_table_->FindShape(unichar_l, font_id);
202 EXPECT_GE(shape_l, 0);
203 int shape_1 = shape_table_->FindShape(unichar_1, font_id);
204 EXPECT_GE(shape_1, 0);
205
206 float dist_I_l = master_trainer_->ShapeDistance(*shape_table_, shape_I, shape_l);
207 // No tolerance here. We expect that I and l should match exactly.
208 EXPECT_EQ(0.0f, dist_I_l);
209 float dist_l_I = master_trainer_->ShapeDistance(*shape_table_, shape_l, shape_I);
210 // BOTH ways.
211 EXPECT_EQ(0.0f, dist_l_I);
212
213 // l/1 on the other hand should be distinct.
214 float dist_l_1 = master_trainer_->ShapeDistance(*shape_table_, shape_l, shape_1);
215 EXPECT_GT(dist_l_1, kMin1lDistance);
216 float dist_1_l = master_trainer_->ShapeDistance(*shape_table_, shape_1, shape_l);
217 EXPECT_GT(dist_1_l, kMin1lDistance);
218
219 // So should I/1.
220 float dist_I_1 = master_trainer_->ShapeDistance(*shape_table_, shape_I, shape_1);
221 EXPECT_GT(dist_I_1, kMin1lDistance);
222 float dist_1_I = master_trainer_->ShapeDistance(*shape_table_, shape_1, shape_I);
223 EXPECT_GT(dist_1_I, kMin1lDistance);
224 }
const double kMin1lDistance
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:2043
#define EXPECT_GT(val1, val2)
Definition: gtest.h:2053
#define EXPECT_GE(val1, val2)
Definition: gtest.h:2051
int FindShape(int unichar_id, int font_id) const
Definition: shapetable.cpp:400

Member Data Documentation

◆ master_trainer_

std::unique_ptr<MasterTrainer> MasterTrainerTest::master_trainer_
protected

Definition at line 228 of file mastertrainer_test.cc.

◆ shape_table_

ShapeTable* MasterTrainerTest::shape_table_
protected

Definition at line 227 of file mastertrainer_test.cc.


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