00001
00020 #ifndef BLOBBOX_H
00021 #define BLOBBOX_H
00022
00023 #include "varable.h"
00024 #include "clst.h"
00025 #include "elst2.h"
00026 #include "werd.h"
00027 #include "ocrblock.h"
00028 #include "statistc.h"
00029
00032 extern double_VAR_H (textord_error_weight, 3,
00033 "Weighting for error in believability");
00040 enum PITCH_TYPE
00041 {
00043 PITCH_DUNNO,
00045 PITCH_DEF_FIXED,
00047 PITCH_MAYBE_FIXED,
00048 PITCH_DEF_PROP,
00049 PITCH_MAYBE_PROP,
00050 PITCH_CORR_FIXED,
00051 PITCH_CORR_PROP
00052 };
00053
00054 class BLOBNBOX;
00055 ELISTIZEH (BLOBNBOX)
00056
00057
00061 class BLOBNBOX:public ELIST_LINK
00062 {
00063 public:
00064 BLOBNBOX() {
00065 blob_ptr = NULL;
00066 cblob_ptr = NULL;
00067 joined = FALSE;
00068 reduced = FALSE;
00069 area = 0;
00070 }
00071 BLOBNBOX(
00072 PBLOB *srcblob) {
00073 blob_ptr = srcblob;
00074 cblob_ptr = NULL;
00075 box = srcblob->bounding_box ();
00076 joined = FALSE;
00077 reduced = FALSE;
00078 area = (int) srcblob->area ();
00079 }
00080 BLOBNBOX(
00081 C_BLOB *srcblob) {
00082 blob_ptr = NULL;
00083 cblob_ptr = srcblob;
00084 box = srcblob->bounding_box ();
00085 joined = FALSE;
00086 reduced = FALSE;
00087 area = (int) srcblob->area ();
00088 }
00089
00090 const BOX &bounding_box() const {
00091 return box;
00092 }
00093 const BOX &reduced_box() const {
00094 return red_box;
00095 }
00096 void set_reduced_box(
00097 BOX new_box) {
00098 red_box = new_box;
00099 reduced = TRUE;
00100 }
00101 INT32 enclosed_area() const {
00102 return area;
00103 }
00104
00105 void rotate_box(
00106 FCOORD vec) {
00107 box.rotate (vec);
00108 }
00109
00110 BOOL8 joined_to_prev() const {
00111 return joined != 0;
00112 }
00113 BOOL8 red_box_set() const {
00114 return reduced != 0;
00115 }
00116 void merge(
00117 BLOBNBOX *nextblob);
00118 void chop(
00119 BLOBNBOX_IT *start_it,
00120 BLOBNBOX_IT *blob_it,
00121 FCOORD rotation,
00122 float xheight);
00123
00124 PBLOB *blob() {
00125 return blob_ptr;
00126 }
00127 C_BLOB *cblob() {
00128 return cblob_ptr;
00129 }
00130
00131 #ifndef GRAPHICS_DISABLED
00132
00135 void plot(
00136 WINDOW window,
00137 COLOUR blob_colour,
00138 COLOUR child_colour) {
00139 if (blob_ptr != NULL)
00140 blob_ptr->plot (window, blob_colour, child_colour);
00141 if (cblob_ptr != NULL)
00142 cblob_ptr->plot (window, blob_colour, child_colour);
00143 }
00144 #endif
00145
00146 NEWDELETE2 (BLOBNBOX) private:
00148 int area:30;
00150 int joined:1;
00152 int reduced:1;
00154 BOX box;
00156 BOX red_box;
00158 PBLOB *blob_ptr;
00160 C_BLOB *cblob_ptr;
00161 };
00162
00167 class TO_ROW:public ELIST2_LINK
00168 {
00169 public:
00170 TO_ROW() {
00171 }
00172 TO_ROW(
00173 BLOBNBOX *blob,
00174 float top,
00175 float bottom,
00176 float row_size);
00177
00178 float max_y() const {
00179 return y_max;
00180 }
00181 float min_y() const {
00182 return y_min;
00183 }
00184 float mean_y() const {
00185 return (y_min + y_max) / 2.0f;
00186 }
00187 float initial_min_y() const {
00188 return initial_y_min;
00189 }
00190 float line_m() const {
00191 return m;
00192 }
00193 float line_c() const {
00194 return c;
00195 }
00196 float line_error() const {
00197 return error;
00198 }
00199 float parallel_c() const {
00200 return para_c;
00201 }
00202 float parallel_error() const {
00203 return para_error;
00204 }
00205 float believability() const {
00206 return credibility;
00207 }
00208 float intercept() const {
00209 return y_origin;
00210 }
00211 void add_blob(
00212 BLOBNBOX *blob,
00213 float top,
00214 float bottom,
00215 float row_size);
00216 void insert_blob(
00217 BLOBNBOX *blob);
00218
00219 BLOBNBOX_LIST *blob_list() {
00220 return &blobs;
00221 }
00222
00223 void set_line(
00224 float new_m,
00225 float new_c,
00226 float new_error) {
00227 m = new_m;
00228 c = new_c;
00229 error = new_error;
00230 }
00231 void set_parallel_line(
00232 float gradient,
00233 float new_c,
00234 float new_error) {
00235 para_c = new_c;
00236 para_error = new_error;
00237 credibility =
00238 (float) (blobs.length () - textord_error_weight * new_error);
00239 y_origin = (float) (new_c / sqrt (1 + gradient * gradient));
00240
00241 }
00242 void set_limits(
00243 float new_min,
00244 float new_max) {
00245 y_min = new_min;
00246 y_max = new_max;
00247 }
00248 void compute_vertical_projection();
00249
00250 NEWDELETE2 (TO_ROW) BOOL8 merged;
00252 BOOL8 all_caps;
00254 BOOL8 used_dm_model;
00256 INT16 projection_left;
00258 INT16 projection_right;
00260 PITCH_TYPE pitch_decision;
00262 float fixed_pitch;
00264 float fp_space;
00266 float fp_nonsp;
00268 float pr_space;
00270 float pr_nonsp;
00272 float spacing;
00274 float xheight;
00276 float ascrise;
00278 float descdrop;
00280 INT32 min_space;
00282 INT32 max_nonspace;
00284 INT32 space_threshold;
00286 float kern_size;
00288 float space_size;
00290 WERD_LIST rep_words;
00292 ICOORDELT_LIST char_cells;
00294 QSPLINE baseline;
00296 STATS projection;
00297
00298 private:
00300 BLOBNBOX_LIST blobs;
00302 float y_min;
00304 float y_max;
00305 float initial_y_min;
00307 float m, c;
00309 float error;
00311 float para_c;
00312 float para_error;
00314 float y_origin;
00316 float credibility;
00317 };
00318
00319 ELIST2IZEH (TO_ROW)
00320
00325 class TO_BLOCK:public ELIST_LINK
00326 {
00327 public:
00328 TO_BLOCK() {
00329 }
00330 TO_BLOCK(
00331 BLOCK *src_block);
00332 ~TO_BLOCK();
00333
00334 TO_ROW_LIST *get_rows() {
00335 return &row_list;
00336 }
00337
00338 void print_rows() {
00339 TO_ROW_IT row_it = &row_list;
00340 TO_ROW *row;
00341
00342 for (row_it.mark_cycle_pt (); !row_it.cycled_list ();
00343 row_it.forward ()) {
00344 row = row_it.data ();
00345 printf ("Row range (%g,%g), para_c=%g, blobcount=" INT32FORMAT
00346 "\n", row->min_y (), row->max_y (), row->parallel_c (),
00347 row->blob_list ()->length ());
00348 }
00349 }
00350
00352 BLOBNBOX_LIST blobs;
00354 BLOBNBOX_LIST underlines;
00356 BLOBNBOX_LIST noise_blobs;
00358 BLOBNBOX_LIST small_blobs;
00360 BLOBNBOX_LIST large_blobs;
00362 BLOCK *block;
00364 PITCH_TYPE pitch_decision;
00366 float line_spacing;
00368 float line_size;
00370 float max_blob_size;
00372 float baseline_offset;
00374 float xheight;
00376 float fixed_pitch;
00378 float kern_size;
00380 float space_size;
00382 INT32 min_space;
00384 INT32 max_nonspace;
00386 float fp_space;
00388 float fp_nonsp;
00390 float pr_space;
00392 float pr_nonsp;
00394 TO_ROW *key_row;
00395
00396 NEWDELETE2 (TO_BLOCK) private:
00398 TO_ROW_LIST row_list;
00399 };
00400
00401 ELISTIZEH (TO_BLOCK)
00402 void find_blob_limits(
00403 PBLOB *blob,
00404 float leftx,
00405 float rightx,
00406 FCOORD rotation,
00407 float &ymin,
00408 float &ymax);
00409 void find_cblob_limits(
00410 C_BLOB *blob,
00411 float leftx,
00412 float rightx,
00413 FCOORD rotation,
00414 float &ymin,
00415 float &ymax);
00416 void find_cblob_vlimits(
00417 C_BLOB *blob,
00418 float leftx,
00419 float rightx,
00420 float &ymin,
00421 float &ymax);
00422 void find_cblob_hlimits(
00423 C_BLOB *blob,
00424 float bottomy,
00425 float topy,
00426 float &xmin,
00427 float &xymax);
00428 PBLOB *rotate_blob(
00429 PBLOB *blob,
00430 FCOORD rotation
00431 );
00432 PBLOB *rotate_cblob(
00433 C_BLOB *blob,
00434 float xheight,
00435 FCOORD rotation
00436 );
00437 C_BLOB *crotate_cblob(
00438 C_BLOB *blob,
00439 FCOORD rotation
00440 );
00441 BOX box_next(
00442 BLOBNBOX_IT *it
00443 );
00444 BOX box_next_pre_chopped(
00445 BLOBNBOX_IT *it
00446 );
00447 void vertical_blob_projection(
00448 PBLOB *blob,
00449 STATS *stats
00450 );
00451
00452 void vertical_outline_projection(OUTLINE *outline,
00453 STATS *stats
00454 );
00455 void vertical_cblob_projection(
00456 C_BLOB *blob,
00457 STATS *stats
00458 );
00459 void vertical_coutline_projection(
00460 C_OUTLINE *outline,
00461 STATS *stats
00462 );
00463 #endif