⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 werd.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/********************************************************************** * File:        werd.cpp  (Formerly word.c) * Description: Code for the WERD class. * Author:		Ray Smith * Created:		Tue Oct 08 14:32:12 BST 1991 * * (C) Copyright 1991, Hewlett-Packard Ltd. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. * **********************************************************************/#include "mfcpch.h"#include          "blckerr.h"#include          "linlsq.h"#include          "werd.h"#define FIRST_COLOUR    RED      //first rainbow colour                                 //last rainbow colour#define LAST_COLOUR     AQUAMARINE#define CHILD_COLOUR    BROWN    //colour of childrenconst ERRCODE CANT_SCALE_EDGESTEPS ="Attempted to scale an edgestep format word";#define EXTERNEXTERN BOOL_VAR (bln_numericmode, 0, "Optimize for numbers");EXTERN INT_VAR (bln_x_height, 128, "Baseline Normalisation X-height");EXTERN INT_VAR (bln_baseline_offset, 64, "Baseline Norm. offset of baseline");EXTERN double_VAR (bln_blshift_maxshift, -1.0,"Fraction of xh before shifting");EXTERN double_VAR (bln_blshift_xfraction, 0.75,"Size fraction of xh before shifting");ELISTIZE_S (WERD)/********************************************************************** * WERD::WERD * * Constructor to build a WERD from a list of C_BLOBs. * The C_BLOBs are not copied so the source list is emptied. **********************************************************************/WERD::WERD (                     //constructorC_BLOB_LIST * blob_list,         //in word orderUINT8 blank_count,               //blanks in frontconst char *text                 //correct text):flags (0),correct(text) {   C_BLOB_IT start_it = blob_list;//iterator  C_BLOB_IT end_it = blob_list;  //another                                 //rejected blobs in wd  C_BLOB_IT rej_cblob_it = &rej_cblobs;  C_OUTLINE_IT c_outline_it;     //coutline iterator  BOOL8 blob_inverted;  BOOL8 reject_blob;  INT16 inverted_vote = 0;  INT16 non_inverted_vote = 0;  while (!end_it.at_last ())    end_it.forward ();           //move to last                                 //move to our list  cblobs.assign_to_sublist (&start_it, &end_it);  blanks = blank_count;  /*    Set white on black flag for the WERD, moving any duff blobs onto the    rej_cblobs list.    First, walk the cblobs checking the inverse flag for each outline of each    cblob. If a cblob has inconsistent flag settings for its different    outlines, move the blob to the reject list. Otherwise, increment the    appropriate w-on-b or b-on-w vote for the word.    Now set the inversion flag for the WERD by maximum vote.    Walk the blobs again, moving any blob whose inversion flag does not agree    with the concencus onto the reject list.  */  start_it.set_to_list (&cblobs);  if (start_it.empty ())    return;  for (start_it.mark_cycle_pt ();  !start_it.cycled_list (); start_it.forward ()) {    c_outline_it.set_to_list (start_it.data ()->out_list ());    blob_inverted = c_outline_it.data ()->flag (COUT_INVERSE);    reject_blob = FALSE;    for (c_outline_it.mark_cycle_pt ();      !c_outline_it.cycled_list () && !reject_blob;    c_outline_it.forward ()) {      reject_blob =        c_outline_it.data ()->flag (COUT_INVERSE) != blob_inverted;    }    if (reject_blob)      rej_cblob_it.add_after_then_move (start_it.extract ());    else {      if (blob_inverted)        inverted_vote++;      else        non_inverted_vote++;    }  }  flags.set_bit (W_INVERSE, (inverted_vote > non_inverted_vote));  start_it.set_to_list (&cblobs);  if (start_it.empty ())    return;  for (start_it.mark_cycle_pt ();  !start_it.cycled_list (); start_it.forward ()) {    c_outline_it.set_to_list (start_it.data ()->out_list ());    if (c_outline_it.data ()->flag (COUT_INVERSE) != flags.bit (W_INVERSE))      rej_cblob_it.add_after_then_move (start_it.extract ());  }}/********************************************************************** * WERD::WERD * * Constructor to build a WERD from a list of BLOBs. * The BLOBs are not copied so the source list is emptied. **********************************************************************/WERD::WERD (                     //constructorPBLOB_LIST * blob_list,          //in word orderUINT8 blank_count,               //blanks in frontconst char *text                 //correct text):flags (0),correct(text) {   PBLOB_IT start_it = blob_list; //iterator  PBLOB_IT end_it = blob_list;   //another  while (!end_it.at_last ())    end_it.forward ();           //move to last  ((PBLOB_LIST *) (&cblobs))->assign_to_sublist (&start_it, &end_it);  //move to our list                                 //it's a polygon  flags.set_bit (W_POLYGON, TRUE);  blanks = blank_count;  //      fprintf(stderr,"Wrong constructor!!!!\n");}/********************************************************************** * WERD::WERD * * Constructor to build a WERD from a list of BLOBs. * The BLOBs are not copied so the source list is emptied. **********************************************************************/WERD::WERD (                     //constructorPBLOB_LIST * blob_list,          //in word orderWERD * clone                     //sorce of flags):flags (clone->flags), correct (clone->correct) {  PBLOB_IT start_it = blob_list; //iterator  PBLOB_IT end_it = blob_list;   //another  while (!end_it.at_last ())    end_it.forward ();           //move to last  ((PBLOB_LIST *) (&cblobs))->assign_to_sublist (&start_it, &end_it);  //move to our list  blanks = clone->blanks;  //      fprintf(stderr,"Wrong constructor!!!!\n");}/********************************************************************** * WERD::WERD * * Constructor to build a WERD from a list of C_BLOBs. * The C_BLOBs are not copied so the source list is emptied. **********************************************************************/WERD::WERD (                     //constructorC_BLOB_LIST * blob_list,         //in word orderWERD * clone                     //sorce of flags):flags (clone->flags), correct (clone->correct) {  C_BLOB_IT start_it = blob_list;//iterator  C_BLOB_IT end_it = blob_list;  //another  while (!end_it.at_last ())    end_it.forward ();           //move to last  ((C_BLOB_LIST *) (&cblobs))->assign_to_sublist (&start_it, &end_it);  //move to our list  blanks = clone->blanks;  //      fprintf(stderr,"Wrong constructor!!!!\n");}/********************************************************************** * WERD::poly_copy * * Make a copy of a WERD in polygon format. * The source WERD is untouched. **********************************************************************/WERD *WERD::poly_copy(               //make a poly copy                      float xheight  //row height                     ) {  PBLOB *blob;                   //new blob  WERD *result = new WERD;       //output word  C_BLOB_IT src_it = &cblobs;    //iterator  //      LARC_BLOB_IT                            larc_it=(LARC_BLOB_LIST*)(&cblobs);  PBLOB_IT dest_it = (PBLOB_LIST *) (&result->cblobs);  //another  if (flags.bit (W_POLYGON)) {    *result = *this;             //just copy it  }  else {    result->flags = flags;    result->correct = correct;   //copy info    result->dummy = dummy;    if (!src_it.empty ()) {      //                      if (flags.bit(W_LINEARC))      //                      {      //                              do      //                              {      //                                      blob=new PBLOB;      //                                      poly_linearc_outlines(larc_it.data()->out_list(),      //                                                                                              blob->out_list());      //convert outlines      //                                      dest_it.add_after_then_move(blob);                      //add to dest list      //                                      larc_it.forward();      //                              }      //                              while (!larc_it.at_first());      //                      }      //                      else      //                      {      do {        blob = new PBLOB (src_it.data (), xheight);        //convert blob                                 //add to dest list        dest_it.add_after_then_move (blob);        src_it.forward ();      }      while (!src_it.at_first ());      //                      }    }    if (!rej_cblobs.empty ()) {      /* Polygonal approx of reject blobs */      src_it.set_to_list (&rej_cblobs);      dest_it = (PBLOB_LIST *) (&result->rej_cblobs);      do {                                 //convert blob        blob = new PBLOB (src_it.data (), xheight);                                 //add to dest list        dest_it.add_after_then_move (blob);        src_it.forward ();      }      while (!src_it.at_first ());    }                                 //polygon now    result->flags.set_bit (W_POLYGON, TRUE);    result->blanks = blanks;  }  return result;}/********************************************************************** * WERD::bounding_box * * Return the bounding box of the WERD. * This is quite a mess to compute! * ORIGINALLY, REJECT CBLOBS WERE EXCLUDED, however, this led to bugs when the * words on the row were re-sorted. The original words were built with reject * blobs included. The FUZZY SPACE flags were set accordingly. If ALL the * blobs in a word are rejected the BB for the word is NULL, causing the sort * to screw up, leading to the erroneous possibility of the first word in a * row being marked as FUZZY space. **********************************************************************/BOX WERD::bounding_box() {  //bounding box  BOX box;                       //box being built                                 //rejected blobs in wd  C_BLOB_IT rej_cblob_it = &rej_cblobs;  for (rej_cblob_it.mark_cycle_pt ();  !rej_cblob_it.cycled_list (); rej_cblob_it.forward ()) {    box += rej_cblob_it.data ()->bounding_box ();  }  if (flags.bit (W_POLYGON)) {                                 //polygons    PBLOB_IT it = (PBLOB_LIST *) (&cblobs);    for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {      box += it.data ()->bounding_box ();    }  }  else {    C_BLOB_IT it = &cblobs;      //blobs of WERD    for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {      box += it.data ()->bounding_box ();    }  }  return box;}/********************************************************************** * WERD::move * * Reposition WERD by vector * NOTE!! REJECT CBLOBS ARE NOT MOVED **********************************************************************/void WERD::move(                  // reposition WERD                const ICOORD vec  // by vector               ) {  PBLOB_IT blob_it ((PBLOB_LIST *) & cblobs);  // blob iterator  //      LARC_BLOB_IT                            lblob_it((LARC_BLOB_LIST*)&cblobs);  C_BLOB_IT cblob_it(&cblobs);  // cblob iterator  if (flags.bit (W_POLYGON))    for (blob_it.mark_cycle_pt ();    !blob_it.cycled_list (); blob_it.forward ())  blob_it.data ()->move (vec);  //      else if (flags.bit(W_LINEARC))  //              for( lblob_it.mark_cycle_pt();  //                      !lblob_it.cycled_list();  //                      lblob_it.forward() )  //                      lblob_it.data()->move( vec );  else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -