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

📄 intproto.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/****************************************************************************** **	Filename:    intproto.c **	Purpose:     Definition of data structures for integer protos. **	Author:      Dan Johnson **	History:     Thu Feb  7 14:38:16 1991, DSJ, Created. ** **	(c) Copyright Hewlett-Packard Company, 1988. ** 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 Files and Type Defines----------------------------------------------------------------------------**/#include "intproto.h"#include "picofeat.h"#include "debug.h"#include "mfoutline.h"#include "emalloc.h"#include "const.h"#include "ndminx.h"#include "adaptmatch.h"//extern GetPicoFeatureLength();#include <math.h>#include <stdio.h>#include <assert.h>/* match debug display constants*/#define DISPLAY_OFFSET  (0.5  * INT_CHAR_NORM_RANGE)#define PROTO_PRUNER_SCALE  (4.0)#define INT_DESCENDER (0.0  * INT_CHAR_NORM_RANGE - DISPLAY_OFFSET)#define INT_BASELINE  (0.25 * INT_CHAR_NORM_RANGE - DISPLAY_OFFSET)#define INT_XHEIGHT (0.75 * INT_CHAR_NORM_RANGE - DISPLAY_OFFSET)#define INT_CAPHEIGHT (1.0  * INT_CHAR_NORM_RANGE - DISPLAY_OFFSET)#define INT_XCENTER (0.5  * INT_CHAR_NORM_RANGE - DISPLAY_OFFSET)#define INT_YCENTER (0.5  * INT_CHAR_NORM_RANGE - DISPLAY_OFFSET)#define INT_XRADIUS (0.2  * INT_CHAR_NORM_RANGE)#define INT_YRADIUS (0.2  * INT_CHAR_NORM_RANGE)#define INT_MIN_X (- DISPLAY_OFFSET)#define INT_MIN_Y (- DISPLAY_OFFSET)#define INT_MAX_X (  DISPLAY_OFFSET)#define INT_MAX_Y (  DISPLAY_OFFSET)#define DOUBLE_OFFSET 0.095/* define pad used to snap near horiz/vertical protos to horiz/vertical */#define HV_TOLERANCE  (0.0025)   /* approx 0.9 degrees */typedef enum{ StartSwitch, EndSwitch, LastSwitch }SWITCH_TYPE;#define MAX_NUM_SWITCHES  3typedef struct{  SWITCH_TYPE Type;  INT8 X, Y;  INT16 YInit;  INT16 Delta;}FILL_SWITCH;typedef struct{  UINT8 NextSwitch;  UINT8 AngleStart, AngleEnd;  INT8 X;  INT16 YStart, YEnd;  INT16 StartDelta, EndDelta;  FILL_SWITCH Switch[MAX_NUM_SWITCHES];}TABLE_FILLER;typedef struct{  INT8 X;  INT8 YStart, YEnd;  UINT8 AngleStart, AngleEnd;}FILL_SPEC;/**----------------------------------------------------------------------------            Macros----------------------------------------------------------------------------**//* macro for performing circular increments of bucket indices */#define CircularIncrement(i,r)  (((i) < (r) - 1)?((i)++):((i) = 0))/* macro for mapping floats to ints without bounds checking */#define MapParam(P,O,N)   (floor (((P) + (O)) * (N)))/*---------------------------------------------------------------------------            Private Function Prototypes----------------------------------------------------------------------------*/FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets);FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets);void DoFill(FILL_SPEC *FillSpec,            CLASS_PRUNER Pruner,            register UINT32 ClassMask,            register UINT32 ClassCount,            register UINT32 WordIndex);BOOL8 FillerDone(TABLE_FILLER *Filler);void FillPPCircularBits (UINT32ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],int Bit, FLOAT32 Center, FLOAT32 Spread);void FillPPLinearBits (UINT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],int Bit, FLOAT32 Center, FLOAT32 Spread);#ifndef GRAPHICS_DISABLEDCLASS_ID GetClassToDebug(const char *Prompt);#endifvoid GetCPPadsForLevel(int Level,                       FLOAT32 *EndPad,                       FLOAT32 *SidePad,                       FLOAT32 *AnglePad);C_COL GetMatchColorFor(FLOAT32 Evidence);void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill);void InitTableFiller(FLOAT32 EndPad,                     FLOAT32 SidePad,                     FLOAT32 AnglePad,                     PROTO Proto,                     TABLE_FILLER *Filler);#ifndef GRAPHICS_DISABLEDvoid RenderIntFeature(void *window, INT_FEATURE Feature, C_COL Color);void RenderIntProto(void *window,                    INT_CLASS Class,                    PROTO_ID ProtoId,                    C_COL Color);#endifint TruncateParam(FLOAT32 Param, int Min, int Max, char *Id);/*#if defined(__STDC__) || defined(__cplusplus)# define	_ARGS(s) s#else# define	_ARGS(s) ()#endif*//* /users/danj/wiseowl/src/danj/microfeatures/intproto.cFLOAT32 BucketStart  _ARGS((int Bucket,  FLOAT32 Offset,  int NumBuckets));FLOAT32 BucketEnd  _ARGS((int Bucket,  FLOAT32 Offset,  int NumBuckets));void DoFill  _ARGS((FILL_SPEC *FillSpec,  CLASS_PRUNER Pruner,  UINT32 ClassMask,  UINT32 ClassCount,  UINT32 WordIndex));BOOL8 FillerDone  _ARGS((TABLE_FILLER *Filler));void FillPPCircularBits  _ARGS((UINT32 ParamTable [NUM_PP_BUCKETS ][WERDS_PER_PP_VECTOR ],  int Bit,  FLOAT32 Center,  FLOAT32 Spread));void FillPPLinearBits  _ARGS((UINT32 ParamTable [NUM_PP_BUCKETS ][WERDS_PER_PP_VECTOR ],  int Bit,  FLOAT32 Center,  FLOAT32 Spread));void GetCPPadsForLevel  _ARGS((int Level,  FLOAT32 *EndPad,  FLOAT32 *SidePad,  FLOAT32 *AnglePad));C_COL GetMatchColorFor  _ARGS((FLOAT32 Evidence));void GetNextFill  _ARGS((TABLE_FILLER *Filler,  FILL_SPEC *Fill));void InitTableFiller  _ARGS((FLOAT32 EndPad,  FLOAT32 SidePad,  FLOAT32 AnglePad,  PROTO Proto,  TABLE_FILLER *Filler));void RenderIntFeature  _ARGS((SHAPE_LIST ShapeList,  INT_FEATURE Feature,  char *Color));void RenderIntProto  _ARGS((SHAPE_LIST ShapeList,  INT_CLASS Class,  PROTO_ID ProtoId,  char *Color));int TruncateParam  _ARGS((FLOAT32 Param,  int Min,  int Max,  char *Id));#undef _ARGS*//**----------------------------------------------------------------------------        Global Data Definitions and Declarations----------------------------------------------------------------------------**//* control knobs */make_int_const (NumCPLevels, 3, MakeNumCPLevels);make_float_const (CPAnglePadLoose, 45.0, MakeCPAnglePadLoose);make_float_const (CPAnglePadMedium, 20.0, MakeCPAnglePadMedium);make_float_const (CPAnglePadTight, 10.0, MakeCPAnglePadTight);make_float_const (CPEndPadLoose, 0.5, MakeCPEndPadLoose);make_float_const (CPEndPadMedium, 0.5, MakeCPEndPadMedium);make_float_const (CPEndPadTight, 0.5, MakeCPEndPadTight);make_float_const (CPSidePadLoose, 2.5, MakeCPSidePadLoose);make_float_const (CPSidePadMedium, 1.2, MakeCPSidePadMedium);make_float_const (CPSidePadTight, 0.6, MakeCPSidePadTight);make_float_const (PPAnglePad, 45.0, MakePPAnglePad);make_float_const (PPEndPad, 0.5, MakePPEndPad);make_float_const (PPSidePad, 2.5, MakePPSidePad);/* global display lists used to display proto and feature match information*/void *IntMatchWindow = NULL;//extern int LearningDebugLevel;/**----------------------------------------------------------------------------              Public Code----------------------------------------------------------------------------**//*---------------------------------------------------------------------------*/int AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class) {/* **	Parameters: **		Templates	templates to add new class to **		ClassId		class id to associate new class with **		Class		class data structure to add to templates **	Globals: none **	Operation: This routine adds a new class structure to a set of **		templates. **	Return: The class index of the new class. **	Exceptions: none **	History: Mon Feb 11 11:52:08 1991, DSJ, Created. */  int Index;  int Pruner;  UINT32 *Word;  assert (LegalClassId (ClassId));  assert (UnusedClassIdIn (Templates, ClassId));  Index = NumClassesIn (Templates);  IndexForClassId (Templates, ClassId) = Index;  ClassIdForIndex (Templates, Index) = ClassId;  NumClassesIn (Templates)++;  ClassForIndex (Templates, Index) = Class;  if (NumClassesIn (Templates) > MaxNumClassesIn (Templates)) {    Pruner = NumClassPrunersIn (Templates);    NumClassPrunersIn (Templates)++;    Templates->ClassPruner[Pruner] =      (CLASS_PRUNER) Emalloc (sizeof (CLASS_PRUNER_STRUCT));    for (Word = (UINT32 *) (Templates->ClassPruner[Pruner]);      Word < (UINT32 *) (Templates->ClassPruner[Pruner]) + WERDS_PER_CP;      *Word++ = 0);  }  return (Index);}                                /* AddIntClass *//*---------------------------------------------------------------------------*/int AddIntConfig(INT_CLASS Class) {/* **	Parameters: **		Class	class to add new configuration to **	Globals: none **	Operation: This routine returns the index of the next free config **		in Class. **	Return: Index of next free config. **	Exceptions: none **	History: Mon Feb 11 14:44:40 1991, DSJ, Created. */  int Index;  assert (NumIntConfigsIn (Class) < MAX_NUM_CONFIGS);  Index = NumIntConfigsIn (Class);  NumIntConfigsIn (Class)++;  LengthForConfigId (Class, Index) = 0;  return (Index);}                                /* AddIntConfig *//*---------------------------------------------------------------------------*/int AddIntProto(INT_CLASS Class) {/* **	Parameters: **		Class	class to add new proto to **	Globals: none **	Operation: This routine allocates the next free proto in Class and **		returns its index. **	Return: Proto index of new proto. **	Exceptions: none **	History: Mon Feb 11 13:26:41 1991, DSJ, Created. */  int Index;  int ProtoSetId;  PROTO_SET ProtoSet;  INT_PROTO Proto;  register UINT32 *Word;  if (NumIntProtosIn (Class) >= MAX_NUM_PROTOS)    return (NO_PROTO);  Index = NumIntProtosIn (Class);  NumIntProtosIn (Class)++;  if (NumIntProtosIn (Class) > MaxNumIntProtosIn (Class)) {    ProtoSetId = NumProtoSetsIn (Class);    NumProtoSetsIn (Class)++;    ProtoSet = (PROTO_SET) Emalloc (sizeof (PROTO_SET_STRUCT));    ProtoSetIn (Class, ProtoSetId) = ProtoSet;    for (Word = (UINT32 *) (ProtoPrunerFor (ProtoSet));      Word < (UINT32 *) (ProtoPrunerFor (ProtoSet)) + WERDS_PER_PP;      *Word++ = 0);    /* reallocate space for the proto lengths and install in class */    Class->ProtoLengths = (UINT8 *) Erealloc (Class->ProtoLengths,      MaxNumIntProtosIn (Class) *      sizeof (UINT8));  }  /* initialize proto so its length is zero and it isn't in any configs */  LengthForProtoId (Class, Index) = 0;  Proto = ProtoForProtoId (Class, Index);  for (Word = Proto->Configs;    Word < Proto->Configs + WERDS_PER_CONFIG_VEC; *Word++ = 0);  return (Index);}                                /* AddIntProto *//*---------------------------------------------------------------------------*/voidAddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates)/* **	Parameters: **		Proto		floating-pt proto to add to class pruner **		ClassId		class id corresponding to Proto **		Templates	set of templates containing class pruner **	Globals: **		NumCPLevels	number of levels used in the class pruner **	Operation: This routine adds Proto to the class pruning tables **		for the specified class in Templates. **	Return: none **	Exceptions: none **	History: Wed Feb 13 08:49:54 1991, DSJ, Created. */#define MAX_LEVEL     2{  CLASS_PRUNER Pruner;  UINT32 ClassMask;  UINT32 ClassCount;  CLASS_INDEX ClassIndex;  UINT32 WordIndex;  int Level;  FLOAT32 EndPad, SidePad, AnglePad;  TABLE_FILLER TableFiller;  FILL_SPEC FillSpec;  ClassIndex = IndexForClassId (Templates, ClassId);  Pruner = CPrunerFor (Templates, ClassIndex);  WordIndex = CPrunerWordIndexFor (ClassIndex);  ClassMask = CPrunerMaskFor (MAX_LEVEL, ClassIndex);  for (Level = NumCPLevels - 1; Level >= 0; Level--) {    GetCPPadsForLevel(Level, &EndPad, &SidePad, &AnglePad);    ClassCount = CPrunerMaskFor (Level, ClassIndex);    InitTableFiller(EndPad, SidePad, AnglePad, Proto, &TableFiller);    while (!FillerDone (&TableFiller)) {      GetNextFill(&TableFiller, &FillSpec);      DoFill(&FillSpec, Pruner, ClassMask, ClassCount, WordIndex);    }  }}                                /* AddProtoToClassPruner *//*---------------------------------------------------------------------------*/void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class) {/* **	Parameters: **		Proto	floating-pt proto to be added to proto pruner **		ProtoId	id of proto **		Class	integer class that contains desired proto pruner **	Globals: none **	Operation: This routine updates the proto pruner lookup tables **		for Class to include a new proto identified by ProtoId **		and described by Proto.

⌨️ 快捷键说明

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