Crop the char samp such that there are no white spaces on any side. The norm_top_ and norm_bottom_ fields are the character top/bottom with respect to whatever context the character is being recognized in (e.g. word bounding box) normalized to a standard size of 255. Here they default to 0 and 255 (word box boundaries), but since they are context dependent, they may need to be reset by the calling
| 336 | // since they are context dependent, they may need to be reset by the |
| 337 | // calling function. |
| 338 | CharSamp *CharSamp::Crop() { |
| 339 | // get the dimesions of the cropped img |
| 340 | int cropped_left = 0; |
| 341 | int cropped_top = 0; |
| 342 | int cropped_wid = wid_; |
| 343 | int cropped_hgt = hgt_; |
| 344 | Bmp8::Crop(&cropped_left, &cropped_top, |
| 345 | &cropped_wid, &cropped_hgt); |
| 346 | |
| 347 | if (cropped_wid == 0 || cropped_hgt == 0) { |
| 348 | return NULL; |
| 349 | } |
| 350 | // create the cropped char samp |
| 351 | CharSamp *cropped_samp = new CharSamp(left_ + cropped_left, |
| 352 | top_ + cropped_top, |
| 353 | cropped_wid, cropped_hgt); |
| 354 | cropped_samp->SetLabel(label32_); |
| 355 | cropped_samp->SetFirstChar(first_char_); |
| 356 | cropped_samp->SetLastChar(last_char_); |
| 357 | // the following 3 fields may/should be reset by the calling function |
| 358 | // using context information, i.e., location of character box |
| 359 | // w.r.t. the word bounding box |
| 360 | cropped_samp->SetNormAspectRatio(255 * |
| 361 | cropped_wid / (cropped_wid + cropped_hgt)); |
| 362 | cropped_samp->SetNormTop(0); |
| 363 | cropped_samp->SetNormBottom(255); |
| 364 | |
| 365 | // copy the bitmap to the cropped img |
| 366 | Copy(cropped_left, cropped_top, cropped_wid, cropped_hgt, cropped_samp); |
| 367 | return cropped_samp; |
| 368 | } |
| 369 | |
| 370 | // segment the char samp to connected components |
| 371 | // based on contiguity and vertical pixel density histogram |
nothing calls this directly
no test coverage detected