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

📄 adaptive.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** **	Filename:    adaptive.c **	Purpose:     Adaptive matcher. **	Author:      Dan Johnson **	History:     Fri Mar  8 10:00:21 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 "adaptive.h"#include "emalloc.h"#include "freelist.h"#ifdef __UNIX__#include <assert.h>#endif#include <stdio.h>/**----------------------------------------------------------------------------              Public Code----------------------------------------------------------------------------**//*---------------------------------------------------------------------------*/int AddAdaptedClass(ADAPT_TEMPLATES Templates,                    ADAPT_CLASS Class,                    CLASS_ID ClassId) {/* **	Parameters: **		Templates	set of templates to add new class to **		Class		new class to add to templates **		ClassId		class id to associate with new class **	Globals: none **	Operation: This routine adds a new adapted class to an existing **		set of adapted templates. **	Return: The class index of the new class. **	Exceptions: none **	History: Thu Mar 14 13:06:09 1991, DSJ, Created. */  INT_CLASS IntClass;  CLASS_INDEX ClassIndex;  assert (Templates != NULL);  assert (Class != NULL);  assert (LegalClassId (ClassId));  assert (UnusedClassIdIn (Templates->Templates, ClassId));  assert (Class->NumPermConfigs == 0);  IntClass = NewIntClass (1, 1);  ClassIndex = AddIntClass (Templates->Templates, ClassId, IntClass);  assert (Templates->Class[ClassIndex] == NULL);  Templates->Class[ClassIndex] = Class;  return (ClassIndex);}                                /* AddAdaptedClass *//*---------------------------------------------------------------------------*/void FreeTempConfig(TEMP_CONFIG Config) { /* **	Parameters: **		Config	config to be freed **	Globals: none **	Operation: This routine frees all memory consumed by a temporary **		configuration. **	Return: none **	Exceptions: none **	History: Thu Mar 14 13:34:23 1991, DSJ, Created. */  assert (Config != NULL);  destroy_nodes (Config->ContextsSeen, memfree);  FreeBitVector (Config->Protos);  c_free_struct (Config, sizeof (TEMP_CONFIG_STRUCT), "TEMP_CONFIG_STRUCT");}                                /* FreeTempConfig *//*---------------------------------------------------------------------------*/void FreeTempProto(void *arg) {   PROTO proto = (PROTO) arg;  c_free_struct (proto, sizeof (TEMP_PROTO_STRUCT), "TEMP_PROTO_STRUCT");}/*---------------------------------------------------------------------------*/ADAPT_CLASS NewAdaptedClass() { /* **	Parameters: none **	Globals: none **	Operation: This operation allocates and initializes a new adapted **		class data structure and returns a ptr to it. **	Return: Ptr to new class data structure. **	Exceptions: none **	History: Thu Mar 14 12:58:13 1991, DSJ, Created. */  ADAPT_CLASS Class;  int i;  Class = (ADAPT_CLASS) Emalloc (sizeof (ADAPT_CLASS_STRUCT));  Class->NumPermConfigs = 0;  Class->TempProtos = NIL;  Class->PermProtos = NewBitVector (MAX_NUM_PROTOS);  Class->PermConfigs = NewBitVector (MAX_NUM_CONFIGS);  zero_all_bits (Class->PermProtos, WordsInVectorOfSize (MAX_NUM_PROTOS));  zero_all_bits (Class->PermConfigs, WordsInVectorOfSize (MAX_NUM_CONFIGS));  for (i = 0; i < MAX_NUM_CONFIGS; i++)    TempConfigFor (Class, i) = NULL;  return (Class);}                                /* NewAdaptedClass *//*-------------------------------------------------------------------------*/void free_adapted_class(ADAPT_CLASS adapt_class) {   int i;  for (i = 0; i < MAX_NUM_CONFIGS; i++) {    if (ConfigIsPermanent (adapt_class, i)      && PermConfigFor (adapt_class, i) != NULL)      Efree (PermConfigFor (adapt_class, i));    else if (!ConfigIsPermanent (adapt_class, i)      && TempConfigFor (adapt_class, i) != NULL)      FreeTempConfig (TempConfigFor (adapt_class, i));  }  FreeBitVector (adapt_class->PermProtos);  FreeBitVector (adapt_class->PermConfigs);  destroy_nodes (adapt_class->TempProtos, FreeTempProto);  Efree(adapt_class); }/*---------------------------------------------------------------------------*/ADAPT_TEMPLATES NewAdaptedTemplates() { /* **	Parameters: none **	Globals: none **	Operation: **	Return: none **	Exceptions: none **	History: Fri Mar  8 10:15:28 1991, DSJ, Created. */  ADAPT_TEMPLATES Templates;  int i;  Templates = (ADAPT_TEMPLATES) Emalloc (sizeof (ADAPT_TEMPLATES_STRUCT));  Templates->Templates = NewIntTemplates ();  Templates->NumPermClasses = 0;  for (i = 0; i < MAX_NUM_CLASSES; i++)    Templates->Class[i] = NULL;  return (Templates);}                                /* NewAdaptedTemplates *//*-------------------------------------------------------------------------------*/void free_adapted_templates(ADAPT_TEMPLATES templates) {   if (templates != NULL) {    int i;    for (i = 0; i < NumClassesIn (templates->Templates); i++)      free_adapted_class (templates->Class[i]);    free_int_templates (templates->Templates);    Efree(templates);   }}/*---------------------------------------------------------------------------*/TEMP_CONFIG NewTempConfig(int MaxProtoId) { /* **	Parameters: **		MaxProtoId	max id of any proto in new config **	Globals: none **	Operation: This routine allocates and returns a new temporary **		config. **	Return: Ptr to new temp config. **	Exceptions: none **	History: Thu Mar 14 13:28:21 1991, DSJ, Created. */  TEMP_CONFIG Config;  int NumProtos = MaxProtoId + 1;  Config =    (TEMP_CONFIG) c_alloc_struct (sizeof (TEMP_CONFIG_STRUCT),    "TEMP_CONFIG_STRUCT");  Config->Protos = NewBitVector (NumProtos);  Config->NumTimesSeen = 1;  Config->MaxProtoId = MaxProtoId;  Config->ProtoVectorSize = WordsInVectorOfSize (NumProtos);  Config->ContextsSeen = NIL;  zero_all_bits (Config->Protos, Config->ProtoVectorSize);  return (Config);}                                /* NewTempConfig *//*---------------------------------------------------------------------------*/TEMP_PROTO NewTempProto() { /* **	Parameters: none **	Globals: none **	Operation: This routine allocates and returns a new temporary proto. **	Return: Ptr to new temporary proto. **	Exceptions: none **	History: Thu Mar 14 13:31:31 1991, DSJ, Created. */  return ((TEMP_PROTO)    c_alloc_struct (sizeof (TEMP_PROTO_STRUCT), "TEMP_PROTO_STRUCT"));}                                /* NewTempProto *//*---------------------------------------------------------------------------*/void PrintAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates) { /* **	Parameters: **		File		open text file to print Templates to **		Templates	adapted templates to print to File **	Globals: none **	Operation: This routine prints a summary of the adapted templates **		in Templates to File. **	Return: none **	Exceptions: none **	History: Wed Mar 20 13:35:29 1991, DSJ, Created. */  int i;  INT_CLASS IClass;  ADAPT_CLASS AClass;  #ifndef SECURE_NAMES  fprintf (File, "\n\nSUMMARY OF ADAPTED TEMPLATES:\n\n");  fprintf (File, "Num classes = %d;  Num permanent classes = %d\n\n",    NumClassesIn (Templates->Templates), Templates->NumPermClasses);  fprintf (File, "Index Id  NC NPC  NP NPP\n");  fprintf (File, "------------------------\n");  for (i = 0; i < NumClassesIn (Templates->Templates); i++) {    IClass = ClassForIndex (Templates->Templates, i);    AClass = Templates->Class[i];    fprintf (File, "%5d  %c %3d %3d %3d %3d\n",      i, ClassIdForIndex (Templates->Templates, i),      NumIntConfigsIn (IClass), AClass->NumPermConfigs,      NumIntProtosIn (IClass),      NumIntProtosIn (IClass) - count (AClass->TempProtos));  }

⌨️ 快捷键说明

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