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

Protected Member Functions

std::string TestDataNameToPath (const std::string &name)
 
std::string TessdataPath ()
 
 ApplyBoxTest ()
 
 ~ApplyBoxTest () override
 
bool SetImage (const char *filename)
 
void VerifyBoxesAndText (const char *imagefile, const char *truth_str, const char *target_box_file, bool line_mode)
 
- Protected Member Functions inherited from testing::Test
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 

Protected Attributes

Image src_pix_
 
std::string ocr_text_
 
tesseract::TessBaseAPI api_
 

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 27 of file applybox_test.cc.

Constructor & Destructor Documentation

◆ ApplyBoxTest()

tesseract::ApplyBoxTest::ApplyBoxTest ( )
inlineprotected

Definition at line 36 of file applybox_test.cc.

36 {
37 src_pix_ = nullptr;
38 }

◆ ~ApplyBoxTest()

tesseract::ApplyBoxTest::~ApplyBoxTest ( )
inlineoverrideprotected

Definition at line 39 of file applybox_test.cc.

39 {
41 }
void destroy()
Definition: image.cpp:32

Member Function Documentation

◆ SetImage()

bool tesseract::ApplyBoxTest::SetImage ( const char *  filename)
inlineprotected

Definition at line 43 of file applybox_test.cc.

43 {
44 bool found = false;
46 src_pix_ = pixRead(TestDataNameToPath(filename).c_str());
47 if (api_.Init(TessdataPath().c_str(), "eng", tesseract::OEM_TESSERACT_ONLY) != -1) {
50 api_.SetVariable("tessedit_make_boxes_from_boxes", "1");
51 api_.SetInputName(TestDataNameToPath(filename).c_str());
52 found = true;
53 }
54 return found;
55 }
@ OEM_TESSERACT_ONLY
Definition: publictypes.h:264
@ PSM_SINGLE_BLOCK
Assume a single uniform block of text. (Default.)
Definition: publictypes.h:166
void SetPageSegMode(PageSegMode mode)
Definition: baseapi.cpp:511
bool SetVariable(const char *name, const char *value)
Definition: baseapi.cpp:279
void SetInputName(const char *name)
Definition: baseapi.cpp:270
int Init(const char *datapath, const char *language, OcrEngineMode mode, char **configs, int configs_size, const std::vector< std::string > *vars_vec, const std::vector< std::string > *vars_values, bool set_only_non_debug_params)
Definition: baseapi.cpp:368
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: baseapi.cpp:576
std::string TestDataNameToPath(const std::string &name)
tesseract::TessBaseAPI api_
std::string TessdataPath()

◆ TessdataPath()

std::string tesseract::ApplyBoxTest::TessdataPath ( )
inlineprotected

Definition at line 32 of file applybox_test.cc.

32 {
33 return TESSDATA_DIR;
34 }

◆ TestDataNameToPath()

std::string tesseract::ApplyBoxTest::TestDataNameToPath ( const std::string &  name)
inlineprotected

Definition at line 29 of file applybox_test.cc.

29 {
30 return file::JoinPath(TESTING_DIR, name);
31 }
static std::string JoinPath(const std::string &s1, const std::string &s2)
Definition: include_gunit.h:65

◆ VerifyBoxesAndText()

void tesseract::ApplyBoxTest::VerifyBoxesAndText ( const char *  imagefile,
const char *  truth_str,
const char *  target_box_file,
bool  line_mode 
)
inlineprotected

Definition at line 62 of file applybox_test.cc.

63 {
64 if (!SetImage(imagefile)) {
65 // eng.traineddata not found or other problem during Init.
66 GTEST_SKIP();
67 return;
68 }
69 if (line_mode) {
70 api_.SetVariable("tessedit_resegment_from_line_boxes", "1");
71 } else {
72 api_.SetVariable("tessedit_resegment_from_boxes", "1");
73 }
74 api_.Recognize(nullptr);
75 char *ocr_text = api_.GetUTF8Text();
76 EXPECT_STREQ(truth_str, ocr_text);
77 delete[] ocr_text;
78 // Test the boxes by reading the target box file in parallel with the
79 // bounding boxes in the ocr output.
80 std::string box_filename = TestDataNameToPath(target_box_file);
81 FILE *box_file = OpenBoxFile(box_filename.c_str());
82 ASSERT_TRUE(box_file != nullptr);
83 int height = pixGetHeight(src_pix_);
84 ResultIterator *it = api_.GetIterator();
85 do {
86 int left, top, right, bottom;
87 EXPECT_TRUE(it->BoundingBox(tesseract::RIL_SYMBOL, &left, &top, &right, &bottom));
88 TBOX ocr_box(ICOORD(left, height - bottom), ICOORD(right, height - top));
89 int line_number = 0;
90 TBOX truth_box;
91 std::string box_text;
92 EXPECT_TRUE(ReadNextBox(0, &line_number, box_file, box_text, &truth_box));
93 // Testing for major overlap is a bit weak, but if they all
94 // major overlap successfully, then it has to be fairly close.
95 EXPECT_TRUE(ocr_box.major_overlap(truth_box));
96 // Also check that the symbol text matches the box text.
97 char *symbol_text = it->GetUTF8Text(tesseract::RIL_SYMBOL);
98 EXPECT_STREQ(box_text.c_str(), symbol_text);
99 delete[] symbol_text;
100 } while (it->Next(tesseract::RIL_SYMBOL));
101 delete it;
102 }
@ TBOX
#define GTEST_SKIP()
Definition: gtest.h:1889
#define EXPECT_TRUE(condition)
Definition: gtest.h:1982
#define EXPECT_STREQ(s1, s2)
Definition: gtest.h:2112
#define ASSERT_TRUE(condition)
Definition: gtest.h:1990
FILE * OpenBoxFile(const char *fname)
Definition: boxread.cpp:59
bool ReadNextBox(int *line_number, FILE *box_file, std::string &utf8_str, TBOX *bounding_box)
Definition: boxread.cpp:153
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:834
ResultIterator * GetIterator()
Definition: baseapi.cpp:1337
bool SetImage(const char *filename)

Member Data Documentation

◆ api_

tesseract::TessBaseAPI tesseract::ApplyBoxTest::api_
protected

Definition at line 106 of file applybox_test.cc.

◆ ocr_text_

std::string tesseract::ApplyBoxTest::ocr_text_
protected

Definition at line 105 of file applybox_test.cc.

◆ src_pix_

Image tesseract::ApplyBoxTest::src_pix_
protected

Definition at line 104 of file applybox_test.cc.


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