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

Method Normalize

deps/tesseract/cube/cube_object.cpp:219–256  ·  view source on GitHub ↗

Normalize the input word bitmap to have a minimum aspect ratio

Source from the content-addressed store, hash-verified

217
218// Normalize the input word bitmap to have a minimum aspect ratio
219bool CubeObject::Normalize() {
220 // create a cube search object
221 CubeSearchObject *srch_obj = new CubeSearchObject(cntxt_, char_samp_);
222 // Perform over-segmentation
223 int seg_cnt = srch_obj->SegPtCnt();
224 // Only perform normalization if segment count is large enough
225 if (seg_cnt < kMinNormalizationSegmentCnt) {
226 delete srch_obj;
227 return true;
228 }
229 // compute the mean AR of the segments
230 double ar_mean = 0.0;
231 for (int seg_idx = 0; seg_idx <= seg_cnt; seg_idx++) {
232 CharSamp *seg_samp = srch_obj->CharSample(seg_idx - 1, seg_idx);
233 if (seg_samp != NULL && seg_samp->Width() > 0) {
234 ar_mean += (1.0 * seg_samp->Height() / seg_samp->Width());
235 }
236 }
237 ar_mean /= (seg_cnt + 1);
238 // perform normalization if segment AR is too high
239 if (ar_mean > kMinNormalizationAspectRatio) {
240 // scale down the image in the y-direction to attain AR
241 CharSamp *new_samp = char_samp_->Scale(char_samp_->Width(),
242 2.0 * char_samp_->Height() / ar_mean,
243 false);
244 if (new_samp != NULL) {
245 // free existing char samp if owned
246 if (own_char_samp_) {
247 delete char_samp_;
248 }
249 // update with new scaled charsamp and set ownership flag
250 char_samp_ = new_samp;
251 own_char_samp_ = true;
252 }
253 }
254 delete srch_obj;
255 return true;
256}
257}

Callers

nothing calls this directly

Calls 5

SegPtCntMethod · 0.80
CharSampleMethod · 0.45
WidthMethod · 0.45
HeightMethod · 0.45
ScaleMethod · 0.45

Tested by

no test coverage detected