13 #include "allheaders.h"
25 const char* kTruthTextWords =
"To simple burn running of goods lately.\n";
26 const char* kTruthTextLine =
"Tosimpleburnrunningofgoodslately.\n";
29 class ApplyBoxTest :
public testing::Test {
36 ApplyBoxTest() { src_pix_ =
nullptr; }
37 ~ApplyBoxTest() { pixDestroy(&src_pix_); }
39 bool SetImage(
const char* filename) {
41 pixDestroy(&src_pix_);
42 src_pix_ = pixRead(TestDataNameToPath(filename).c_str());
45 api_.SetImage(src_pix_);
46 api_.SetVariable(
"tessedit_make_boxes_from_boxes",
"1");
47 api_.SetInputName(TestDataNameToPath(filename).c_str());
58 void VerifyBoxesAndText(
const char* imagefile,
const char* truth_str,
59 const char* target_box_file,
bool line_mode) {
60 if (!SetImage(imagefile)) {
66 api_.SetVariable(
"tessedit_resegment_from_line_boxes",
"1");
68 api_.SetVariable(
"tessedit_resegment_from_boxes",
"1");
69 api_.Recognize(
nullptr);
70 char* ocr_text = api_.GetUTF8Text();
71 EXPECT_STREQ(truth_str, ocr_text);
75 std::string box_filename = TestDataNameToPath(target_box_file);
77 ASSERT_TRUE(box_file !=
nullptr);
78 int height = pixGetHeight(src_pix_);
79 ResultIterator* it = api_.GetIterator();
81 int left, top, right, bottom;
89 ReadNextBox(0, &line_number, box_file, &box_text, &truth_box));
92 EXPECT_TRUE(ocr_box.major_overlap(truth_box));
95 EXPECT_STREQ(box_text.
c_str(), symbol_text);
107 TEST_F(ApplyBoxTest, TimesCharLevel) {
108 VerifyBoxesAndText(
"trainingtimes.tif", kTruthTextWords,
"trainingtimes.box",
113 TEST_F(ApplyBoxTest, ItalicCharLevel) {
114 VerifyBoxesAndText(
"trainingital.tif", kTruthTextWords,
"trainingital.box",
119 TEST_F(ApplyBoxTest, TimesLineLevel) {
120 VerifyBoxesAndText(
"trainingtimesline.tif", kTruthTextLine,
121 "trainingtimes.box",
true);
125 TEST_F(ApplyBoxTest, ItalLineLevel) {
126 VerifyBoxesAndText(
"trainingitalline.tif", kTruthTextLine,
"trainingital.box",