| 652 | } |
| 653 | |
| 654 | void EquationDetect::SplitCPHor(ColPartition* part, |
| 655 | GenericVector<ColPartition*>* parts_splitted) { |
| 656 | ASSERT_HOST(part && parts_splitted); |
| 657 | if (part->median_width() == 0 || part->boxes_count() == 0) { |
| 658 | return; |
| 659 | } |
| 660 | |
| 661 | // Make a copy of part, and reset parts_splitted. |
| 662 | ColPartition* right_part = part->CopyButDontOwnBlobs(); |
| 663 | parts_splitted->delete_data_pointers(); |
| 664 | parts_splitted->clear(); |
| 665 | |
| 666 | const double kThreshold = part->median_width() * 3.0; |
| 667 | bool found_split = true; |
| 668 | while (found_split) { |
| 669 | found_split = false; |
| 670 | BLOBNBOX_C_IT box_it(right_part->boxes()); |
| 671 | // Blobs are sorted left side first. If blobs overlap, |
| 672 | // the previous blob may have a "more right" right side. |
| 673 | // Account for this by always keeping the largest "right" |
| 674 | // so far. |
| 675 | int previous_right = MIN_INT32; |
| 676 | |
| 677 | // Look for the next split in the partition. |
| 678 | for (box_it.mark_cycle_pt(); !box_it.cycled_list(); box_it.forward()) { |
| 679 | const TBOX& box = box_it.data()->bounding_box(); |
| 680 | if (previous_right != MIN_INT32 && |
| 681 | box.left() - previous_right > kThreshold) { |
| 682 | // We have a split position. Split the partition in two pieces. |
| 683 | // Insert the left piece in the grid and keep processing the right. |
| 684 | int mid_x = (box.left() + previous_right) / 2; |
| 685 | ColPartition* left_part = right_part; |
| 686 | right_part = left_part->SplitAt(mid_x); |
| 687 | |
| 688 | parts_splitted->push_back(left_part); |
| 689 | left_part->ComputeSpecialBlobsDensity(); |
| 690 | found_split = true; |
| 691 | break; |
| 692 | } |
| 693 | |
| 694 | // The right side of the previous blobs. |
| 695 | previous_right = MAX(previous_right, box.right()); |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | // Add the last piece. |
| 700 | right_part->ComputeSpecialBlobsDensity(); |
| 701 | parts_splitted->push_back(right_part); |
| 702 | } |
| 703 | |
| 704 | void EquationDetect::SplitCPHorLite(ColPartition* part, |
| 705 | GenericVector<TBOX>* splitted_boxes) { |
nothing calls this directly
no test coverage detected