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

📄 edgblob.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/********************************************************************** * File:        edgblob.c  (Formerly edgeloop.c) * Description: Functions to clean up an outline before approximation. * Author:		Ray Smith * Created:		Tue Mar 26 16:56:25 GMT 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                                      "dirtab.h"#include          "scanedg.h"#include          "drawedg.h"#include          "edgloop.h"#include          "edgblob.h"#define EXTERNEXTERN INT_VAR (edges_children_per_grandchild, 10,"Importance ratio for chucking outlines");EXTERN INT_VAR (edges_children_count_limit, 45, "Max holes allowed in blob");EXTERN BOOL_VAR (edges_children_fix, FALSE,"Remove boxy parents of char-like children");EXTERN INT_VAR (edges_min_nonhole, 12,"Min pixels for potential char in box");EXTERN INT_VAR (edges_patharea_ratio, 40,"Max lensq/area for acceptable child outline");EXTERN double_VAR (edges_childarea, 0.5,"Max area fraction of child outline");EXTERN double_VAR (edges_boxarea, 0.8,"Min area fraction of grandchild for box");/********************************************************************** * OL_BUCKETS::OL_BUCKETS * * Construct an array of buckets for associating outlines into blobs. **********************************************************************/OL_BUCKETS::OL_BUCKETS (////constructorICOORD bleft,                    //cornersICOORD tright):         bl (bleft), tr (tright) {  bxdim = (tright.x () - bleft.x ()) / BUCKETSIZE + 1;  bydim = (tright.y () - bleft.y ()) / BUCKETSIZE + 1;                                 //make array  buckets = new C_OUTLINE_LIST[bxdim * bydim];  index = 0;}/********************************************************************** * OL_BUCKETS::operator( * * Return a pointer to a list of C_OUTLINEs corresponding to the * given pixel coordinates. **********************************************************************/C_OUTLINE_LIST *OL_BUCKETS::operator () (        //array accessINT16 x,                         //image coordsINT16 y) {  return &buckets[(y - bl.y ()) / BUCKETSIZE * bxdim +    (x - bl.x ()) / BUCKETSIZE];}/********************************************************************** * OL_BUCKETS::count_children * * Find number of descendants of this outline. **********************************************************************/INT32 OL_BUCKETS::count_children(                     //recursive count                                 C_OUTLINE *outline,  //parent outline                                 INT32 max_count      //max output                                ) {  BOOL8 parent_box;              //could it be boxy  INT16 xmin, xmax;              //coord limits  INT16 ymin, ymax;  INT16 xindex, yindex;          //current bucket  C_OUTLINE *child;              //current child  INT32 child_count;             //no of children  INT32 grandchild_count;        //no of grandchildren  INT32 parent_area;             //potential box  FLOAT32 max_parent_area;       //potential box  INT32 child_area;              //current child  INT32 child_length;            //current child  BOX olbox;  C_OUTLINE_IT child_it;         //search iterator  olbox = outline->bounding_box ();  xmin = (olbox.left () - bl.x ()) / BUCKETSIZE;  xmax = (olbox.right () - bl.x ()) / BUCKETSIZE;  ymin = (olbox.bottom () - bl.y ()) / BUCKETSIZE;  ymax = (olbox.top () - bl.y ()) / BUCKETSIZE;  child_count = 0;  grandchild_count = 0;  parent_area = 0;  max_parent_area = 0;  parent_box = TRUE;  for (yindex = ymin; yindex <= ymax; yindex++) {    for (xindex = xmin; xindex <= xmax; xindex++) {      child_it.set_to_list (&buckets[yindex * bxdim + xindex]);      if (child_it.empty ())        continue;      for (child_it.mark_cycle_pt (); !child_it.cycled_list ();      child_it.forward ()) {        child = child_it.data ();        if (child != outline && *child < *outline) {          child_count++;          if (child_count <= max_count)            grandchild_count += count_children (child,              (max_count -              child_count) /              edges_children_per_grandchild)              * edges_children_per_grandchild;          if (child_count + grandchild_count > max_count) {            /*						err.log(RESULT_OKAY,E_LOC,ERR_OCR,                            ERR_SCROLLING,ERR_CONTINUE,ERR_DEBUG,                            "Discarding parent with child count=%d, gc=%d",                            child_count,grandchild_count);*/            return child_count + grandchild_count;          }          if (parent_area == 0) {            parent_area = outline->outer_area ();            if (parent_area < 0)              parent_area = -parent_area;            max_parent_area = outline->bounding_box ().width ()              * outline->bounding_box ().height () * edges_boxarea;            if (parent_area < max_parent_area)              parent_box = FALSE;          }          if (parent_box            && (!edges_children_fix            || child->bounding_box ().height () >          edges_min_nonhole) /**/) {            child_area = child->outer_area ();            if (child_area < 0)              child_area = -child_area;            if (edges_children_fix) {              if (parent_area - child_area < max_parent_area) {                parent_box = FALSE;                continue;              }              if (grandchild_count > 0) {                /*								err.log(RESULT_OKAY,E_LOC,ERR_OCR,                                    ERR_SCROLLING,ERR_CONTINUE,ERR_DEBUG,                                    "Discarding parent of area %d, child area=%d, max%g with gc=%d",                                    parent_area,child_area,max_parent_area,grandchild_count);*/                return max_count + 1;              }              child_length = child->pathlength ();              if (child_length * child_length >              child_area * edges_patharea_ratio) {                /*/								err.log(RESULT_OKAY,E_LOC,ERR_OCR,                                    ERR_SCROLLING,ERR_CONTINUE,ERR_DEBUG,                                    "Discarding parent of area %d, child area=%d, max%g with child length=%d",                                    parent_area,child_area,max_parent_area,child_length);*/                return max_count + 1;              }            }            if (child_area < child->bounding_box ().width ()              * child->bounding_box ().height () *            edges_childarea) {              /*							err.log(RESULT_OKAY,E_LOC,ERR_OCR,                                ERR_SCROLLING,ERR_CONTINUE,ERR_DEBUG,                                "Discarding parent of area %d, child area=%d, max%g with child rect=%d",                                parent_area,child_area,max_parent_area,child->bounding_box().width()                                *child->bounding_box().height()); */              return max_count + 1;            }          }        }      }    }  }  return child_count + grandchild_count;}/********************************************************************** * OL_BUCKETS::extract_children * * Find number of descendants of this outline. **********************************************************************/void OL_BUCKETS::extract_children(                     //recursive count                                  C_OUTLINE *outline,  //parent outline                                  C_OUTLINE_IT *it     //destination iterator                                 ) {  INT16 xmin, xmax;              //coord limits  INT16 ymin, ymax;  INT16 xindex, yindex;          //current bucket

⌨️ 快捷键说明

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