Factory to build a BoxWord from a TWERD using the DENORMs on each blob to switch back to original image coordinates.
| 57 | // Factory to build a BoxWord from a TWERD using the DENORMs on each blob to |
| 58 | // switch back to original image coordinates. |
| 59 | BoxWord* BoxWord::CopyFromNormalized(TWERD* tessword) { |
| 60 | BoxWord* boxword = new BoxWord(); |
| 61 | // Count the blobs. |
| 62 | boxword->length_ = tessword->NumBlobs(); |
| 63 | // Allocate memory. |
| 64 | boxword->boxes_.reserve(boxword->length_); |
| 65 | |
| 66 | for (int b = 0; b < boxword->length_; ++b) { |
| 67 | TBLOB* tblob = tessword->blobs[b]; |
| 68 | TBOX blob_box; |
| 69 | for (TESSLINE* outline = tblob->outlines; outline != NULL; |
| 70 | outline = outline->next) { |
| 71 | EDGEPT* edgept = outline->loop; |
| 72 | // Iterate over the edges. |
| 73 | do { |
| 74 | if (!edgept->IsHidden() || !edgept->prev->IsHidden()) { |
| 75 | ICOORD pos(edgept->pos.x, edgept->pos.y); |
| 76 | TPOINT denormed; |
| 77 | tblob->denorm().DenormTransform(NULL, edgept->pos, &denormed); |
| 78 | pos.set_x(denormed.x); |
| 79 | pos.set_y(denormed.y); |
| 80 | TBOX pt_box(pos, pos); |
| 81 | blob_box += pt_box; |
| 82 | } |
| 83 | edgept = edgept->next; |
| 84 | } while (edgept != outline->loop); |
| 85 | } |
| 86 | boxword->boxes_.push_back(blob_box); |
| 87 | } |
| 88 | boxword->ComputeBoundingBox(); |
| 89 | return boxword; |
| 90 | } |
| 91 | |
| 92 | // Clean up the bounding boxes from the polygonal approximation by |
| 93 | // expanding slightly, then clipping to the blobs from the original_word |
nothing calls this directly
no test coverage detected