MCPcopy Create free account
hub / github.com/creatale/node-dv / BLNormalize

Method BLNormalize

deps/tesseract/ccstruct/blobs.cpp:807–856  ·  view source on GitHub ↗

Baseline normalizes the blobs in-place, recording the normalization in the DENORMs in the blobs.

Source from the content-addressed store, hash-verified

805// Baseline normalizes the blobs in-place, recording the normalization in the
806// DENORMs in the blobs.
807void 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.
859void TWERD::CopyFrom(const TWERD& src) {

Callers 1

SetupForRecognitionMethod · 0.80

Calls 10

ClipToRangeFunction · 0.85
base_lineMethod · 0.80
heightMethod · 0.80
SetupNormalizationMethod · 0.80
set_inverseMethod · 0.80
set_pixMethod · 0.80
bounding_boxFunction · 0.70
sizeMethod · 0.45
bounding_boxMethod · 0.45
NormalizeMethod · 0.45

Tested by

no test coverage detected