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

📄 tstruct.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/********************************************************************** * File:        tstruct.cpp  (Formerly tstruct.c) * Description: Code to manipulate the structures of the C++/C interface. * Author:		Ray Smith * Created:		Thu Apr 23 15:49:29 BST 1992 * * (C) Copyright 1992, 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          "tfacep.h"#include          "tstruct.h"//#include "structures.h"static ERRCODE BADFRAGMENTS = "Couldn't find matching fragment ends";ELISTIZE (FRAGMENT)//extern /*"C"*/ oldoutline(TESSLINE*);/********************************************************************** * FRAGMENT::FRAGMENT * * Constructor for fragments. **********************************************************************/FRAGMENT::FRAGMENT (             //constructorEDGEPT * head_pt,                //start pointEDGEPT * tail_pt                 //end point):head (head_pt->pos.x, head_pt->pos.y), tail (tail_pt->pos.x,tail_pt->pos.y) {  headpt = head_pt;              //save ptrs  tailpt = tail_pt;}/********************************************************************** * make_ed_word * * Make an editor format word from the tess style word. **********************************************************************/WERD *make_ed_word(                  //construct word                   TWERD *tessword,  //word to convert                   WERD *clone       //clone this one                  ) {  WERD *word;                    //converted word  TBLOB *tblob;                  //current blob  PBLOB *blob;                   //new blob  PBLOB_LIST blobs;              //list of blobs  PBLOB_IT blob_it = &blobs;     //iterator  for (tblob = tessword->blobs; tblob != NULL; tblob = tblob->next) {    blob = make_ed_blob (tblob);    if (blob != NULL)      blob_it.add_after_then_move (blob);  }  if (!blobs.empty ())    word = new WERD (&blobs, clone);  else    word = NULL;  return word;}/********************************************************************** * make_ed_blob * * Make an editor format blob from the tess style blob. **********************************************************************/PBLOB *make_ed_blob(                 //construct blob                    TBLOB *tessblob  //blob to convert                   ) {  TESSLINE *tessol;              //tess outline  FRAGMENT_LIST fragments;       //list of fragments  OUTLINE *outline;              //current outline  OUTLINE_LIST out_list;         //list of outlines  OUTLINE_IT out_it = &out_list; //iterator  for (tessol = tessblob->outlines; tessol != NULL; tessol = tessol->next) {                                 //stick in list    register_outline(tessol, &fragments);  }  while (!fragments.empty ()) {    outline = make_ed_outline (&fragments);    if (outline != NULL)      out_it.add_after_then_move (outline);  }  if (out_it.empty())    return NULL;                 //couldn't do it  return new PBLOB (&out_list);  //turn to blob}/********************************************************************** * make_ed_outline * * Make an editor format outline from the list of fragments. **********************************************************************/OUTLINE *make_ed_outline(                     //constructoutline                         FRAGMENT_LIST *list  //list of fragments                        ) {  FRAGMENT *fragment;            //current fragment  EDGEPT *edgept;                //current point  ICOORD headpos;                //coords of head  ICOORD tailpos;                //coords of tail  FCOORD pos;                    //coords of edgept  FCOORD vec;                    //empty  POLYPT *polypt;                //current point  POLYPT_LIST poly_list;         //list of point  POLYPT_IT poly_it = &poly_list;//iterator  FRAGMENT_IT fragment_it = list;//fragment  headpos = fragment_it.data ()->head;  do {    fragment = fragment_it.data ();    edgept = fragment->headpt;   //start of segment    do {      pos = FCOORD (edgept->pos.x, edgept->pos.y);      vec = FCOORD (edgept->vec.x, edgept->vec.y);      polypt = new POLYPT (pos, vec);                                 //add to list      poly_it.add_after_then_move (polypt);      edgept = edgept->next;    }    while (edgept != fragment->tailpt);    tailpos = ICOORD (edgept->pos.x, edgept->pos.y);                                 //get rid of it    delete fragment_it.extract ();    if (tailpos != headpos) {      if (fragment_it.empty ()) {        //                              tprintf("Bad tailpos (%d,%d), Head=(%d,%d), no fragments.\n",        //                                      fragment->head.x(),fragment->head.y(),        //                                      headpos.x(),headpos.y());        return NULL;      }      fragment_it.forward ();                                 //find next segment      for (fragment_it.mark_cycle_pt (); !fragment_it.cycled_list () && fragment_it.data ()->head != tailpos;        fragment_it.forward ());      if (fragment_it.data ()->head != tailpos) {        //                              tprintf("Bad tailpos (%d,%d), Fragments are:\n",        //                                      tailpos.x(),tailpos.y());        for (fragment_it.mark_cycle_pt ();        !fragment_it.cycled_list (); fragment_it.forward ()) {          fragment = fragment_it.extract ();          //                                      tprintf("Head=(%d,%d), tail=(%d,%d)\n",          //                                              fragment->head.x(),fragment->head.y(),          //                                              fragment->tail.x(),fragment->tail.y());          delete fragment;        }        return NULL;             //can't do it        //                              BADFRAGMENTS.error("make_ed_blob",ABORT,NULL);      }    }  }  while (tailpos != headpos);  return new OUTLINE (&poly_it); //turn to outline}/********************************************************************** * register_outline * * Add the fragments in the given outline to the list **********************************************************************/void register_outline(                     //add fragments                      TESSLINE *outline,   //tess format                      FRAGMENT_LIST *list  //list to add to                     ) {  EDGEPT *startpt;               //start of outline  EDGEPT *headpt;                //start of fragment  EDGEPT *tailpt;                //end of fragment  FRAGMENT *fragment;            //new fragment  FRAGMENT_IT it = list;         //iterator  startpt = outline->loop;  do {    startpt = startpt->next;    if (startpt == NULL)      return;                    //illegal!  }  while (startpt->flags[0] == 0 && startpt != outline->loop);  headpt = startpt;  do  startpt = startpt->next;  while (startpt->flags[0] != 0 && startpt != headpt);  if (startpt->flags[0] != 0)    return;                      //all hidden!  headpt = startpt;  do {    tailpt = headpt;    do    tailpt = tailpt->next;    while (tailpt->flags[0] == 0 && tailpt != startpt);    fragment = new FRAGMENT (headpt, tailpt);    it.add_after_then_move (fragment);    while (tailpt->flags[0] != 0)      tailpt = tailpt->next;    headpt = tailpt;  }  while (tailpt != startpt);}/********************************************************************** * convert_choice_lists * * Convert the ARRAY of TESS_LIST of TESS_CHOICEs into a BLOB_CHOICE_LIST. **********************************************************************/void convert_choice_lists(                                 //convert lists                          ARRAY tessarray,                 //list from tess                          BLOB_CHOICE_LIST_CLIST *ratings  //list of results                         ) {  INT32 length;                  //elements in array  INT32 index;                   //index to array  LIST result;                   //tess output                                 //iterator  BLOB_CHOICE_LIST_C_IT it = ratings;  BLOB_CHOICE_LIST *choice;      //created choice  if (tessarray != NULL) {    length = array_count (tessarray);    for (index = 0; index < length; index++) {      result = (LIST) array_value (tessarray, index);                                 //make one      choice = new BLOB_CHOICE_LIST;                                 //convert blob choices      convert_choice_list(result, *choice);                                 //add to super list      it.add_after_then_move (choice);    }    free_mem(tessarray);  //lists already freed  }}/********************************************************************** * convert_choice_list * * Convert the LIST of TESS_CHOICEs into a BLOB_CHOICE_LIST. **********************************************************************/void convert_choice_list(                           //convert lists

⌨️ 快捷键说明

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