Baseline normalizes the blobs in-place, recording the normalization in the DENORMs in the blobs.
| 805 | // Baseline normalizes the blobs in-place, recording the normalization in the |
| 806 | // DENORMs in the blobs. |
| 807 | void TWERD::BLNormalize(const BLOCK* block, const ROW* row, Pix* pix, |
| 808 | bool inverse, float x_height, float baseline_shift, |
| 809 | bool numeric_mode, tesseract::OcrEngineMode hint, |
| 810 | const TBOX* norm_box, |
| 811 | DENORM* word_denorm) { |
| 812 | TBOX word_box = bounding_box(); |
| 813 | if (norm_box != NULL) word_box = *norm_box; |
| 814 | float word_middle = (word_box.left() + word_box.right()) / 2.0f; |
| 815 | float input_y_offset = 0.0f; |
| 816 | float final_y_offset = static_cast<float>(kBlnBaselineOffset); |
| 817 | float scale = kBlnXHeight / x_height; |
| 818 | if (hint == tesseract::OEM_CUBE_ONLY || row == NULL) { |
| 819 | word_middle = word_box.left(); |
| 820 | input_y_offset = word_box.bottom(); |
| 821 | final_y_offset = 0.0f; |
| 822 | if (hint == tesseract::OEM_CUBE_ONLY) |
| 823 | scale = 1.0f; |
| 824 | } else { |
| 825 | input_y_offset = row->base_line(word_middle) + baseline_shift; |
| 826 | } |
| 827 | for (int b = 0; b < blobs.size(); ++b) { |
| 828 | TBLOB* blob = blobs[b]; |
| 829 | TBOX blob_box = blob->bounding_box(); |
| 830 | float mid_x = (blob_box.left() + blob_box.right()) / 2.0f; |
| 831 | float baseline = input_y_offset; |
| 832 | float blob_scale = scale; |
| 833 | if (numeric_mode) { |
| 834 | baseline = blob_box.bottom(); |
| 835 | blob_scale = ClipToRange(kBlnXHeight * 4.0f / (3 * blob_box.height()), |
| 836 | scale, scale * 1.5f); |
| 837 | } else if (row != NULL && hint != tesseract::OEM_CUBE_ONLY) { |
| 838 | baseline = row->base_line(mid_x) + baseline_shift; |
| 839 | } |
| 840 | // The image will be 8-bit grey if the input was grey or color. Note that in |
| 841 | // a grey image 0 is black and 255 is white. If the input was binary, then |
| 842 | // the pix will be binary and 0 is white, with 1 being black. |
| 843 | // To tell the difference pixGetDepth() will return 8 or 1. |
| 844 | // The inverse flag will be true iff the word has been determined to be |
| 845 | // white on black, and is independent of whether the pix is 8 bit or 1 bit. |
| 846 | blob->Normalize(block, NULL, NULL, word_middle, baseline, blob_scale, |
| 847 | blob_scale, 0.0f, final_y_offset, inverse, pix); |
| 848 | } |
| 849 | if (word_denorm != NULL) { |
| 850 | word_denorm->SetupNormalization(block, NULL, NULL, word_middle, |
| 851 | input_y_offset, scale, scale, |
| 852 | 0.0f, final_y_offset); |
| 853 | word_denorm->set_inverse(inverse); |
| 854 | word_denorm->set_pix(pix); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | // Copies the data and the blobs, but leaves next untouched. |
| 859 | void TWERD::CopyFrom(const TWERD& src) { |
no test coverage detected