tesseract  5.0.0
tesseract::LayoutTest Class Reference
Inheritance diagram for tesseract::LayoutTest:

Protected Member Functions

std::string TestDataNameToPath (const std::string &name)
 
std::string TessdataPath ()
 
 LayoutTest ()
 
 ~LayoutTest () override
 
void SetImage (const char *filename, const char *lang)
 
void VerifyBlockTextOrder (const char *strings[], const PolyBlockType *blocks, ResultIterator *it)
 
void VerifyRoughBlockOrder (bool right_to_left, ResultIterator *it)
 
void VerifyTotalContainment (int winding_target, MutableIterator *it)
 

Protected Attributes

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

Detailed Description

Definition at line 55 of file layout_test.cc.

Constructor & Destructor Documentation

◆ LayoutTest()

tesseract::LayoutTest::LayoutTest ( )
inlineprotected

Definition at line 64 of file layout_test.cc.

64  {
65  src_pix_ = nullptr;
66  }

◆ ~LayoutTest()

tesseract::LayoutTest::~LayoutTest ( )
inlineoverrideprotected

Definition at line 67 of file layout_test.cc.

67  {
68  src_pix_.destroy();
69  }
void destroy()
Definition: image.cpp:32

Member Function Documentation

◆ SetImage()

void tesseract::LayoutTest::SetImage ( const char *  filename,
const char *  lang 
)
inlineprotected

Definition at line 71 of file layout_test.cc.

71  {
72  src_pix_.destroy();
73  src_pix_ = pixRead(TestDataNameToPath(filename).c_str());
77  }
@ OEM_TESSERACT_ONLY
Definition: publictypes.h:266
@ PSM_AUTO
Fully automatic page segmentation, but no OSD.
Definition: publictypes.h:164
void SetPageSegMode(PageSegMode mode)
Definition: baseapi.cpp:508
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:365
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: baseapi.cpp:573
tesseract::TessBaseAPI api_
Definition: layout_test.cc:187
std::string TestDataNameToPath(const std::string &name)
Definition: layout_test.cc:57
std::string TessdataPath()
Definition: layout_test.cc:60

◆ TessdataPath()

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

Definition at line 60 of file layout_test.cc.

60  {
61  return file::JoinPath(TESSDATA_DIR, "");
62  }
static std::string JoinPath(const std::string &s1, const std::string &s2)
Definition: include_gunit.h:65

◆ TestDataNameToPath()

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

Definition at line 57 of file layout_test.cc.

57  {
58  return file::JoinPath(TESTING_DIR, "/" + name);
59  }

◆ VerifyBlockTextOrder()

void tesseract::LayoutTest::VerifyBlockTextOrder ( const char *  strings[],
const PolyBlockType blocks,
ResultIterator it 
)
inlineprotected

Definition at line 84 of file layout_test.cc.

85  {
86  it->Begin();
87  int string_index = 0;
88  int block_index = 0;
89  do {
90  char *block_text = it->GetUTF8Text(tesseract::RIL_BLOCK);
91  if (block_text != nullptr && it->BlockType() == blocks[string_index] &&
92  strstr(block_text, strings[string_index]) != nullptr) {
93  LOG(INFO) << "Found string " << strings[string_index] << " in block " << block_index
94  << " of type " << kPolyBlockNames[blocks[string_index]] << "\n";
95  // Found this one.
96  ++string_index;
97  } else if (it->BlockType() == blocks[string_index] && block_text == nullptr &&
98  strings[string_index][0] == '\0') {
99  LOG(INFO) << "Found block of type " << kPolyBlockNames[blocks[string_index]] << " at block "
100  << block_index << "\n";
101  // Found this one.
102  ++string_index;
103  } else {
104  LOG(INFO) << "No match found in block with text:\n" << block_text;
105  }
106  delete[] block_text;
107  ++block_index;
108  if (strings[string_index] == nullptr) {
109  break;
110  }
111  } while (it->Next(tesseract::RIL_BLOCK));
112  EXPECT_TRUE(strings[string_index] == nullptr);
113  }
@ LOG
@ INFO
Definition: log.h:28

◆ VerifyRoughBlockOrder()

void tesseract::LayoutTest::VerifyRoughBlockOrder ( bool  right_to_left,
ResultIterator it 
)
inlineprotected

Definition at line 120 of file layout_test.cc.

120  {
121  int prev_left = 0;
122  int prev_right = 0;
123  int prev_bottom = 0;
124  it->Begin();
125  do {
126  int left, top, right, bottom;
127  if (it->BoundingBox(tesseract::RIL_BLOCK, &left, &top, &right, &bottom) &&
128  PTIsTextType(it->BlockType()) && right - left > 800 && bottom - top > 200) {
129  if (prev_right > prev_left) {
130  if (std::min(right, prev_right) > std::max(left, prev_left)) {
131  EXPECT_GE(top, prev_bottom) << "Overlapping block should be below";
132  } else if (top < prev_bottom) {
133  if (right_to_left) {
134  EXPECT_GE(prev_left, right) << "Block should be to the left";
135  } else {
136  EXPECT_GE(left, prev_right) << "Block should be to the right";
137  }
138  }
139  }
140  prev_left = left;
141  prev_right = right;
142  prev_bottom = bottom;
143  }
144  } while (it->Next(tesseract::RIL_BLOCK));
145  }
bool PTIsTextType(PolyBlockType type)
Definition: publictypes.h:82

◆ VerifyTotalContainment()

void tesseract::LayoutTest::VerifyTotalContainment ( int  winding_target,
MutableIterator it 
)
inlineprotected

Definition at line 150 of file layout_test.cc.

150  {
151  it->Begin();
152  do {
153  int left, top, right, bottom;
154  if (it->BoundingBox(tesseract::RIL_BLOCK, &left, &top, &right, &bottom) &&
155  PTIsTextType(it->BlockType()) && right - left > 800 && bottom - top > 200) {
156  const PAGE_RES_IT *pr_it = it->PageResIt();
157  POLY_BLOCK *pb = pr_it->block()->block->pdblk.poly_block();
158  CHECK(pb != nullptr);
159  FCOORD skew = pr_it->block()->block->skew();
160  EXPECT_GT(skew.x(), 0.0f);
161  EXPECT_GT(skew.y(), 0.0f);
162  // Iterate the words in the block.
163  MutableIterator word_it = *it;
164  do {
165  const PAGE_RES_IT *w_it = word_it.PageResIt();
166  // Iterate the blobs in the word.
167  C_BLOB_IT b_it(w_it->word()->word->cblob_list());
168  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
169  C_BLOB *blob = b_it.data();
170  // Iterate the outlines in the blob.
171  C_OUTLINE_IT ol_it(blob->out_list());
172  for (ol_it.mark_cycle_pt(); !ol_it.cycled_list(); ol_it.forward()) {
173  C_OUTLINE *ol = ol_it.data();
174  TBOX box = ol->bounding_box();
175  ICOORD middle((box.left() + box.right()) / 2, (box.top() + box.bottom()) / 2);
176  EXPECT_EQ(winding_target, pb->winding_number(middle));
177  }
178  }
179  } while (word_it.Next(tesseract::RIL_WORD) &&
180  !word_it.IsAtBeginningOf(tesseract::RIL_BLOCK));
181  }
182  } while (it->Next(tesseract::RIL_BLOCK));
183  }
@ TBOX
#define CHECK(condition)
Definition: include_gunit.h:76

Member Data Documentation

◆ api_

tesseract::TessBaseAPI tesseract::LayoutTest::api_
protected

Definition at line 187 of file layout_test.cc.

◆ ocr_text_

std::string tesseract::LayoutTest::ocr_text_
protected

Definition at line 186 of file layout_test.cc.

◆ src_pix_

Image tesseract::LayoutTest::src_pix_
protected

Definition at line 185 of file layout_test.cc.


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