Expands the image partition into any non-text until it touches text. The expansion proceeds in the order of increasing increase in area as a heuristic to find the best rectangle by expanding in the most constrained direction first.
| 955 | // as a heuristic to find the best rectangle by expanding in the most |
| 956 | // constrained direction first. |
| 957 | static void MaximalImageBoundingBox(ColPartitionGrid* part_grid, TBOX* im_box) { |
| 958 | bool dunnit[BND_COUNT]; |
| 959 | memset(dunnit, 0, sizeof(dunnit)); |
| 960 | TBOX limit_box(part_grid->bleft().x(), part_grid->bleft().y(), |
| 961 | part_grid->tright().x(), part_grid->tright().y()); |
| 962 | TBOX text_box(*im_box); |
| 963 | for (int iteration = 0; iteration < BND_COUNT; ++iteration) { |
| 964 | // Find the direction with least area increase. |
| 965 | int best_delta = -1; |
| 966 | BlobNeighbourDir best_dir = BND_LEFT; |
| 967 | TBOX expanded_boxes[BND_COUNT]; |
| 968 | for (int dir = 0; dir < BND_COUNT; ++dir) { |
| 969 | BlobNeighbourDir bnd = static_cast<BlobNeighbourDir>(dir); |
| 970 | if (!dunnit[bnd]) { |
| 971 | TBOX expanded_box; |
| 972 | int area_delta = ExpandImageDir(bnd, text_box, limit_box, part_grid, |
| 973 | &expanded_boxes[bnd]); |
| 974 | if (best_delta < 0 || area_delta < best_delta) { |
| 975 | best_delta = area_delta; |
| 976 | best_dir = bnd; |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | // Run the best and remember the direction. |
| 981 | dunnit[best_dir] = true; |
| 982 | text_box = expanded_boxes[best_dir]; |
| 983 | } |
| 984 | *im_box = text_box; |
| 985 | } |
| 986 | |
| 987 | // Helper deletes the given partition but first marks up all the blobs as |
| 988 | // noise, so they get deleted later, and disowns them. |
no test coverage detected