📄 werd.cpp
字号:
for (cblob_it.mark_cycle_pt (); !cblob_it.cycled_list (); cblob_it.forward ()) cblob_it.data ()->move (vec);}/********************************************************************** * WERD::scale * * Scale WERD by multiplier **********************************************************************/void WERD::scale( // scale WERD const float f // by multiplier ) { PBLOB_IT blob_it ((PBLOB_LIST *) & cblobs); // blob iterator // LARC_BLOB_IT lblob_it((LARC_BLOB_LIST*)&cblobs); if (flags.bit (W_POLYGON)) for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) blob_it.data ()->scale (f); // else if (flags.bit(W_LINEARC)) // for (lblob_it.mark_cycle_pt(); // !lblob_it.cycled_list(); // lblob_it.forward() ) // lblob_it.data()->scale( f ); else CANT_SCALE_EDGESTEPS.error ("WERD::scale", ABORT, NULL);}/********************************************************************** * WERD::join_on * * Join other word onto this one. Delete the old word. **********************************************************************/void WERD::join_on( // join WERD WERD *&other //other word ) { PBLOB_IT blob_it ((PBLOB_LIST *) & cblobs); // blob iterator PBLOB_IT src_it ((PBLOB_LIST *) & other->cblobs); C_BLOB_IT rej_cblob_it(&rej_cblobs); C_BLOB_IT src_rej_it (&other->rej_cblobs); while (!src_it.empty ()) { blob_it.add_to_end (src_it.extract ()); src_it.forward (); } while (!src_rej_it.empty ()) { rej_cblob_it.add_to_end (src_rej_it.extract ()); src_rej_it.forward (); }}/********************************************************************** * WERD::copy_on * * Copy blobs from other word onto this one. **********************************************************************/void WERD::copy_on( //copy blobs WERD *&other //from other ) { if (flags.bit (W_POLYGON)) { PBLOB_IT blob_it ((PBLOB_LIST *) & cblobs); // blob iterator PBLOB_LIST blobs; blobs.deep_copy ((PBLOB_LIST *) (&other->cblobs)); blob_it.move_to_last (); blob_it.add_list_after (&blobs); } // else if (flags.bit(W_LINEARC)) // { // LARC_BLOB_IT larc_blob_it( (LARC_BLOB_LIST*)&cblobs ); // LARC_BLOB_LIST larc_blobs; // larc_blobs.deep_copy((LARC_BLOB_LIST*)(&other->cblobs)); // larc_blob_it.move_to_last(); // larc_blob_it.add_list_after( &larc_blobs ); // } else { C_BLOB_IT c_blob_it(&cblobs); C_BLOB_LIST c_blobs; c_blobs.deep_copy (&other->cblobs); c_blob_it.move_to_last (); c_blob_it.add_list_after (&c_blobs); } if (!other->rej_cblobs.empty ()) { C_BLOB_IT rej_c_blob_it(&rej_cblobs); C_BLOB_LIST new_rej_c_blobs; new_rej_c_blobs.deep_copy (&other->rej_cblobs); rej_c_blob_it.move_to_last (); rej_c_blob_it.add_list_after (&new_rej_c_blobs); }}/********************************************************************** * WERD::baseline_normalise * * Baseline Normalise the word in Tesseract style. (I.e origin at centre of * word at bottom. x-height region scaled to region y = * (bln_baseline_offset)..(bln_baseline_offset + bln_x_height) * - usually 64..192) **********************************************************************/void WERD::baseline_normalise( // Tess style BL Norm ROW *row, DENORM *denorm //antidote ) { baseline_normalise_x (row, row->x_height (), denorm); //Use standard x ht}/********************************************************************** * WERD::baseline_normalise_x * * Baseline Normalise the word in Tesseract style. (I.e origin at centre of * word at bottom. x-height region scaled to region y = * (bln_baseline_offset)..(bln_baseline_offset + bln_x_height) * - usually 64..192) * USE A SPECIFIED X-HEIGHT - NOT NECESSARILY THE ONE IN row **********************************************************************/void WERD::baseline_normalise_x( // Tess style BL Norm ROW *row, float x_height, //non standard value DENORM *denorm //antidote ) { BOOL8 using_row; //as baseline float blob_x_centre; //middle of blob float blob_offset; //bottom miss float top_offset; //top miss float blob_x_height; //xh for this blob INT16 segments; //no of segments INT16 segment; //current segment DENORM_SEG *segs; //array of segments float mean_x; //mean xheight INT32 x_count; //no of xs BOX word_box = bounding_box ();//word bounding box BOX blob_box; //blob bounding box PBLOB_IT blob_it ((PBLOB_LIST *) & cblobs); // blob iterator PBLOB *blob; LLSQ line; //fitted line double line_m, line_c; //fitted line //inverse norm DENORM antidote (word_box.left () + (word_box.right () - word_box.left ()) / 2.0, bln_x_height / x_height, row); if (!flags.bit (W_POLYGON)) { WRONG_WORD.error ("WERD::baseline_normalise", ABORT, "Need to poly approx"); } if (flags.bit (W_NORMALIZED)) { WRONG_WORD.error ("WERD::baseline_normalise", ABORT, "Baseline unnormalised"); } if (bln_numericmode) { segs = new DENORM_SEG[blob_it.length ()]; segments = 0; float factor; // For scaling to baseline normalised size. for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) { blob = blob_it.data (); blob_box = blob->bounding_box (); blob->move (FCOORD (-antidote.origin (), -blob_box.bottom ())); factor = bln_x_height * 4.0f / (3 * blob_box.height ()); // Constrain the scale factor as target numbers should be either // cap height already or xheight. if (factor < antidote.scale()) factor = antidote.scale(); else if (factor > antidote.scale() * 1.5f) factor = antidote.scale() * 1.5f; blob->scale (factor); blob->move (FCOORD (0.0, bln_baseline_offset)); segs[segments].xstart = blob->bounding_box().left(); segs[segments].ycoord = blob_box.bottom(); segs[segments++].scale_factor = factor; } antidote = DENORM (antidote.origin (), antidote.scale (), 0.0f, 0.0f, segments, segs, true, row); delete [] segs; //Repeat for rej blobs blob_it.set_to_list ((PBLOB_LIST *) & rej_cblobs); for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) { blob = blob_it.data (); blob_box = blob->bounding_box (); blob->move (FCOORD (-antidote.origin (), -blob_box.bottom ())); blob->scale (bln_x_height * 4.0f / (3 * blob_box.height ())); blob->move (FCOORD (0.0, bln_baseline_offset)); } } else if (bln_blshift_maxshift < 0) { for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) { blob = blob_it.data (); blob_box = blob->bounding_box (); blob_x_centre = blob_box.left () + (blob_box.right () - blob_box.left ()) / 2.0; blob->move (FCOORD (-antidote.origin (), -(row->base_line (blob_x_centre)))); blob->scale (antidote.scale ()); blob->move (FCOORD (0.0, bln_baseline_offset)); } //Repeat for rej blobs blob_it.set_to_list ((PBLOB_LIST *) & rej_cblobs); for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) { blob = blob_it.data (); blob_box = blob->bounding_box (); blob_x_centre = blob_box.left () + (blob_box.right () - blob_box.left ()) / 2.0; blob->move (FCOORD (-antidote.origin (), -(row->base_line (blob_x_centre)))); blob->scale (antidote.scale ()); blob->move (FCOORD (0.0, bln_baseline_offset)); } } else { mean_x = x_height; x_count = 1; segs = new DENORM_SEG[blob_it.length ()]; segments = 0; for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) { blob = blob_it.data (); blob_box = blob->bounding_box (); if (blob_box.height () > bln_blshift_xfraction * x_height) { blob_x_centre = blob_box.left () + (blob_box.right () - blob_box.left ()) / 2.0; blob_offset = blob_box.bottom () - row->base_line (blob_x_centre); top_offset = blob_offset + blob_box.height () - x_height - 1; blob_x_height = top_offset + x_height; if (top_offset < 0) top_offset = -top_offset; if (blob_offset < 0) blob_offset = -blob_offset; if (blob_offset < bln_blshift_maxshift * x_height) { segs[segments].ycoord = blob_box.bottom (); line.add (blob_x_centre, blob_box.bottom ()); if (top_offset < bln_blshift_maxshift * x_height) { segs[segments].scale_factor = blob_box.height () - 1.0f; x_count++; } else segs[segments].scale_factor = 0.0f; //fix it later } else { //not a goer segs[segments].ycoord = -MAX_INT32; if (top_offset < bln_blshift_maxshift * x_height) { segs[segments].scale_factor = blob_x_height; x_count++; } else segs[segments].scale_factor = 0.0f; //fix it later } } else { segs[segments].scale_factor = 0.0f; segs[segments].ycoord = -MAX_INT32; } segs[segments].xstart = blob_box.left (); segments++; } using_row = line.count () <= 1; if (!using_row) { line_m = line.m (); line_c = line.c (line_m); } else line_m = line_c = 0; segments = 0; for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) { blob = blob_it.data (); blob_box = blob->bounding_box (); blob_x_centre = blob_box.left () + (blob_box.right () - blob_box.left ()) / 2.0; if (segs[segments].ycoord == -MAX_INT32 && segs[segments].scale_factor != 0 && !using_row) { blob_offset = line_m * blob_x_centre + line_c; segs[segments].scale_factor = blob_box.top () - blob_offset; } if (segs[segments].scale_factor != 0) mean_x += segs[segments].scale_factor; segments++; } mean_x /= x_count; // printf("mean x=%g, count=%d, line_m=%g, line_c=%g\n", // mean_x,x_count,line_m,line_c); segments = 0; for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) { blob = blob_it.data (); blob_box = blob->bounding_box (); blob_x_centre = blob_box.left () + (blob_box.right () - blob_box.left ()) / 2.0; if (segs[segments].ycoord != -MAX_INT32) blob_offset = (float) segs[segments].ycoord; else if (using_row) blob_offset = row->base_line (blob_x_centre); else blob_offset = line_m * blob_x_centre + line_c; if (segs[segments].scale_factor == 0) segs[segments].scale_factor = mean_x; segs[segments].scale_factor = bln_x_height / segs[segments].scale_factor; // printf("Blob sf=%g, top=%d, bot=%d, base=%g\n", // segs[segments].scale_factor,blob_box.top(),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -