15 #include "allheaders.h"
22 #include <tensorflow/core/lib/gtl/map_util.h>
23 #include <tensorflow/core/lib/gtl/stl_util.h>
37 CHECK(part !=
nullptr);
38 CHECK_LE(math_blobs + digit_blobs, total_blobs);
40 for (
int i = 0; i < math_blobs; i++,
count++) {
45 for (
int i = 0; i < digit_blobs; i++,
count++) {
50 for (
int i =
count; i < total_blobs; i++) {
105 CHECK(part_grid !=
nullptr);
121 std::locale::global(std::locale(
""));
139 CHECK(pix !=
nullptr);
140 CHECK(blocks !=
nullptr);
141 BLOCK_IT block_it(blocks);
143 new BLOCK(
"",
true, 0, 0, 0, 0, pixGetWidth(pix), pixGetHeight(pix));
144 block_it.add_to_end(block);
150 std::vector<ColPartition*>* all_parts) {
151 const int kWidth = 10, kHeight = 10;
153 for (
int y = 0; y < rows; ++y) {
154 for (
int x = 0; x < cols; ++x) {
155 int left = x * kWidth * 2, bottom = y * kHeight * 2;
156 TBOX box(left, bottom, left + kWidth, bottom + kHeight);
160 all_parts->push_back(part);
166 for (
size_t i = 0; i < all_parts->size(); ++i) {
167 (*all_parts)[i]->DeleteBoxes();
168 delete ((*all_parts)[i]);
174 CHECK(part !=
nullptr);
184 #else // TODO: missing equ_gt1.tif
187 Pix* pix_binary = pixRead(imagefile.c_str());
188 CHECK(pix_binary !=
nullptr && pixGetDepth(pix_binary) == 1);
192 TO_BLOCK_LIST to_blocks;
193 AddPageBlock(pix_binary, &blocks);
194 Textord* textord = tesseract_->mutable_textord();
198 TO_BLOCK_IT to_block_it(&to_blocks);
199 std::map<int, int> stt_count;
200 for (to_block_it.mark_cycle_pt(); !to_block_it.cycled_list();
201 to_block_it.forward()) {
202 TO_BLOCK* to_block = to_block_it.data();
203 BLOBNBOX_IT blob_it(&(to_block->
blobs));
204 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
207 equation_det_->RunIdentifySpecialText(blob, 0);
214 const int kCountRange = 3;
215 EXPECT_GE(39 + kCountRange, stt_count[
BSTT_NONE]);
216 EXPECT_LE(39 - kCountRange, stt_count[
BSTT_NONE]);
219 EXPECT_GE(45 + kCountRange, stt_count[
BSTT_ITALIC]);
220 EXPECT_LE(45 - kCountRange, stt_count[
BSTT_ITALIC]);
221 EXPECT_GE(41 + kCountRange, stt_count[
BSTT_DIGIT]);
222 EXPECT_LE(41 - kCountRange, stt_count[
BSTT_DIGIT]);
223 EXPECT_GE(50 + kCountRange, stt_count[
BSTT_MATH]);
224 EXPECT_LE(50 - kCountRange, stt_count[
BSTT_MATH]);
229 pixDestroy(&pix_binary);
235 EXPECT_EQ(
BSTT_NONE, equation_det_->RunEstimateTypeForUnichar(
"a"));
236 EXPECT_EQ(
BSTT_NONE, equation_det_->RunEstimateTypeForUnichar(
"c"));
239 EXPECT_EQ(
BSTT_NONE, equation_det_->RunEstimateTypeForUnichar(
"'"));
240 EXPECT_EQ(
BSTT_NONE, equation_det_->RunEstimateTypeForUnichar(
","));
243 EXPECT_EQ(
BSTT_DIGIT, equation_det_->RunEstimateTypeForUnichar(
"1"));
244 EXPECT_EQ(
BSTT_DIGIT, equation_det_->RunEstimateTypeForUnichar(
"4"));
245 EXPECT_EQ(
BSTT_DIGIT, equation_det_->RunEstimateTypeForUnichar(
"|"));
248 EXPECT_EQ(
BSTT_MATH, equation_det_->RunEstimateTypeForUnichar(
"("));
249 EXPECT_EQ(
BSTT_MATH, equation_det_->RunEstimateTypeForUnichar(
"+"));
262 TBOX box1(0, 950, 999, 999);
266 TBOX box2(300, 920, 900, 940);
270 TBOX box3(0, 900, 600, 910);
274 TBOX box4(300, 890, 600, 899);
278 TBOX box5(300, 500, 900, 510);
286 equation_det_->RunIsIndented(&part_grid, part1));
289 equation_det_->RunIsIndented(&part_grid, part2));
292 equation_det_->RunIsIndented(&part_grid, part3));
295 equation_det_->RunIsIndented(&part_grid, part4));
298 equation_det_->RunIsIndented(&part_grid, part5));
320 TBOX box1(0, 950, 499, 999);
321 TBOX box2(500, 950, 999, 998);
322 TBOX box3(0, 900, 499, 949);
323 TBOX box4(0, 550, 499, 590);
327 EXPECT_TRUE(equation_det_->RunIsNearSmallNeighbor(box1, box2));
328 EXPECT_FALSE(equation_det_->RunIsNearSmallNeighbor(box2, box1));
330 EXPECT_TRUE(equation_det_->RunIsNearSmallNeighbor(box1, box3));
331 EXPECT_FALSE(equation_det_->RunIsNearSmallNeighbor(box2, box3));
333 EXPECT_FALSE(equation_det_->RunIsNearSmallNeighbor(box2, box3));
334 EXPECT_FALSE(equation_det_->RunIsNearSmallNeighbor(box3, box2));
337 EXPECT_FALSE(equation_det_->RunIsNearSmallNeighbor(box1, box4));
338 EXPECT_FALSE(equation_det_->RunIsNearSmallNeighbor(box2, box4));
339 EXPECT_FALSE(equation_det_->RunIsNearSmallNeighbor(box3, box4));
343 TBOX box(0, 950, 999, 999);
354 equation_det_->AddMathDigitBlobs(8, 0, 20, part1);
355 EXPECT_TRUE(equation_det_->RunCheckSeedBlobsCount(part1));
358 equation_det_->AddMathDigitBlobs(1, 8, 20, part2);
359 EXPECT_FALSE(equation_det_->RunCheckSeedBlobsCount(part2));
362 equation_det_->AddMathDigitBlobs(3, 8, 20, part3);
363 EXPECT_TRUE(equation_det_->RunCheckSeedBlobsCount(part3));
366 equation_det_->AddMathDigitBlobs(0, 0, 8, part4);
367 EXPECT_FALSE(equation_det_->RunCheckSeedBlobsCount(part4));
382 int width = 1024, height = 768;
383 Pix* pix = pixCreate(width, height, 1);
384 pixRasterop(pix, 0, 0, width, height / 2, PIX_SET,
nullptr, 0, 0);
385 TBOX box1(100, 0, 140, 140), box2(100, height / 2 - 20, 140, height / 2 + 20),
386 box3(100, height - 40, 140, height);
387 equation_det_->SetPixBinary(pix);
390 EXPECT_NEAR(0.0, equation_det_->RunComputeForegroundDensity(box1), 0.0001f);
391 EXPECT_NEAR(0.5, equation_det_->RunComputeForegroundDensity(box2), 0.0001f);
392 EXPECT_NEAR(1.0, equation_det_->RunComputeForegroundDensity(box3), 0.0001f);
405 EXPECT_EQ(3, equation_det_->RunCountAlignment(vec, 1));
406 EXPECT_EQ(1, equation_det_->RunCountAlignment(vec, 100));
407 EXPECT_EQ(2, equation_det_->RunCountAlignment(vec, 200));
410 EXPECT_EQ(3, equation_det_->RunCountAlignment(vec, 3));
411 EXPECT_EQ(1, equation_det_->RunCountAlignment(vec, 99));
412 EXPECT_EQ(2, equation_det_->RunCountAlignment(vec, 202));
415 EXPECT_EQ(0, equation_det_->RunCountAlignment(vec, 150));
416 EXPECT_EQ(0, equation_det_->RunCountAlignment(vec, 50));
417 EXPECT_EQ(0, equation_det_->RunCountAlignment(vec, 250));
421 Pix* pix = pixCreate(1001, 1001, 1);
422 equation_det_->SetPixBinary(pix);
425 TBOX box1(0, 0, 999, 99);
428 TBOX box2(0, 100, 499, 199);
431 TBOX box3(500, 100, 999, 199);
434 TBOX box4(0, 200, 999, 299);
437 TBOX box5(0, 900, 999, 999);
445 TBOX super_box(0, 0, 999, 199);
446 equation_det_->TestComputeCPsSuperBBox(super_box, &part_grid);
450 TBOX super_box2(0, 0, 999, 299);
451 equation_det_->TestComputeCPsSuperBBox(super_box2, &part_grid);
455 TBOX super_box3(0, 0, 999, 999);
456 equation_det_->TestComputeCPsSuperBBox(super_box3, &part_grid);
472 TBOX box(0, 0, 999, 99);
480 equation_det_->RunSplitCPHorLite(part, &splitted_boxes);
481 EXPECT_TRUE(splitted_boxes.
empty());
484 AddBlobIntoPart(
TBOX(0, 0, 10, 50), part);
485 equation_det_->RunSplitCPHorLite(part, &splitted_boxes);
486 EXPECT_EQ(1, splitted_boxes.
size());
487 EXPECT_TRUE(
TBOX(0, 0, 10, 50) == splitted_boxes[0]);
490 AddBlobIntoPart(
TBOX(11, 0, 20, 60), part);
491 AddBlobIntoPart(
TBOX(25, 0, 30, 55), part);
492 AddBlobIntoPart(
TBOX(100, 0, 110, 15), part);
493 AddBlobIntoPart(
TBOX(125, 0, 140, 45), part);
494 AddBlobIntoPart(
TBOX(500, 0, 540, 35), part);
495 equation_det_->RunSplitCPHorLite(part, &splitted_boxes);
497 EXPECT_EQ(3, splitted_boxes.
size());
498 EXPECT_TRUE(
TBOX(0, 0, 30, 60) == splitted_boxes[0]);
499 EXPECT_TRUE(
TBOX(100, 0, 140, 45) == splitted_boxes[1]);
500 EXPECT_TRUE(
TBOX(500, 0, 540, 35) == splitted_boxes[2]);
507 TBOX box(0, 0, 999, 99);
515 equation_det_->RunSplitCPHor(part, &parts_splitted);
516 EXPECT_TRUE(parts_splitted.
empty());
518 AddBlobIntoPart(
TBOX(0, 0, 10, 50), part);
520 equation_det_->RunSplitCPHor(part, &parts_splitted);
521 EXPECT_EQ(1, parts_splitted.
size());
522 EXPECT_TRUE(
TBOX(0, 0, 10, 50) == parts_splitted[0]->bounding_box());
525 AddBlobIntoPart(
TBOX(11, 0, 20, 60), part);
526 AddBlobIntoPart(
TBOX(25, 0, 30, 55), part);
527 AddBlobIntoPart(
TBOX(100, 0, 110, 15), part);
528 AddBlobIntoPart(
TBOX(125, 0, 140, 45), part);
529 AddBlobIntoPart(
TBOX(500, 0, 540, 35), part);
530 equation_det_->RunSplitCPHor(part, &parts_splitted);
533 EXPECT_EQ(3, parts_splitted.
size());
534 EXPECT_TRUE(
TBOX(0, 0, 30, 60) == parts_splitted[0]->bounding_box());
535 EXPECT_TRUE(
TBOX(100, 0, 140, 45) == parts_splitted[1]->bounding_box());
536 EXPECT_TRUE(
TBOX(500, 0, 540, 35) == parts_splitted[2]->bounding_box());