Tesseract  3.02
tesseract-ocr/classify/adaptive.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  **     Filename:    adaptive.h
00003  **     Purpose:     Interface to adaptive matcher.
00004  **     Author:      Dan Johnson
00005  **     History:     Fri Mar  8 10:00:49 1991, DSJ, Created.
00006  **
00007  **     (c) Copyright Hewlett-Packard Company, 1988.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  ******************************************************************************/
00018 #ifndef ADAPTIVE_H
00019 #define ADAPTIVE_H
00020 
00021 /*----------------------------------------------------------------------------
00022           Include Files and Type Defines
00023 ----------------------------------------------------------------------------*/
00024 #include "oldlist.h"
00025 #include "intproto.h"
00026 #include <stdio.h>
00027 
00028 typedef struct
00029 {
00030   uinT16 ProtoId;
00031   uinT16 dummy;
00032   PROTO_STRUCT Proto;
00033 }
00034 
00035 
00036 TEMP_PROTO_STRUCT;
00037 typedef TEMP_PROTO_STRUCT *TEMP_PROTO;
00038 
00039 typedef struct
00040 {
00041   uinT8 NumTimesSeen;
00042   uinT8 ProtoVectorSize;
00043   PROTO_ID MaxProtoId;
00044   LIST ContextsSeen;
00045   BIT_VECTOR Protos;
00046   int FontinfoId;  // font information inferred from pre-trained templates
00047 } TEMP_CONFIG_STRUCT;
00048 typedef TEMP_CONFIG_STRUCT *TEMP_CONFIG;
00049 
00050 typedef struct
00051 {
00052   UNICHAR_ID *Ambigs;
00053   int FontinfoId;  // font information inferred from pre-trained templates
00054 } PERM_CONFIG_STRUCT;
00055 typedef PERM_CONFIG_STRUCT *PERM_CONFIG;
00056 
00057 typedef union
00058 {
00059   TEMP_CONFIG Temp;
00060   PERM_CONFIG Perm;
00061 } ADAPTED_CONFIG;
00062 
00063 typedef struct
00064 {
00065   uinT8 NumPermConfigs;
00066   uinT8 MaxNumTimesSeen;  // maximum number of times any TEMP_CONFIG was seen
00067   uinT8 dummy[2];         // (cut at matcher_min_examples_for_prototyping)
00068   BIT_VECTOR PermProtos;
00069   BIT_VECTOR PermConfigs;
00070   LIST TempProtos;
00071   ADAPTED_CONFIG Config[MAX_NUM_CONFIGS];
00072 } ADAPT_CLASS_STRUCT;
00073 typedef ADAPT_CLASS_STRUCT *ADAPT_CLASS;
00074 
00075 typedef struct
00076 {
00077   INT_TEMPLATES Templates;
00078   int NumNonEmptyClasses;
00079   uinT8 NumPermClasses;
00080   uinT8 dummy[3];
00081   ADAPT_CLASS Class[MAX_NUM_CLASSES];
00082 } ADAPT_TEMPLATES_STRUCT;
00083 typedef ADAPT_TEMPLATES_STRUCT *ADAPT_TEMPLATES;
00084 
00085 /*----------------------------------------------------------------------------
00086           Public Function Prototypes
00087 ----------------------------------------------------------------------------*/
00088 #define NumNonEmptyClassesIn(Template) ((Template)->NumNonEmptyClasses)
00089 
00090 #define IsEmptyAdaptedClass(Class) ((Class)->NumPermConfigs == 0 &&      \
00091 (Class)->TempProtos == NIL_LIST)
00092 
00093 #define ConfigIsPermanent(Class,ConfigId)               \
00094 (test_bit ((Class)->PermConfigs, ConfigId))
00095 
00096 #define MakeConfigPermanent(Class,ConfigId)     \
00097 (SET_BIT ((Class)->PermConfigs, ConfigId))
00098 
00099 #define MakeProtoPermanent(Class,ProtoId)       \
00100 (SET_BIT ((Class)->PermProtos, ProtoId))
00101 
00102 #define TempConfigFor(Class,ConfigId)   \
00103 ((Class)->Config[ConfigId].Temp)
00104 
00105 #define PermConfigFor(Class,ConfigId)   \
00106 ((Class)->Config[ConfigId].Perm)
00107 
00108 #define IncreaseConfidence(TempConfig)  \
00109 ((TempConfig)->NumTimesSeen++)
00110 
00111 void AddAdaptedClass(ADAPT_TEMPLATES Templates,
00112                     ADAPT_CLASS Class,
00113                     CLASS_ID ClassId);
00114 
00115 void FreeTempProto(void *arg);
00116 
00117 void FreeTempConfig(TEMP_CONFIG Config);
00118 
00119 ADAPT_CLASS NewAdaptedClass();
00120 
00121 void free_adapted_class(ADAPT_CLASS adapt_class);
00122 
00123 void free_adapted_templates(ADAPT_TEMPLATES templates);
00124 
00125 TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId);
00126 
00127 TEMP_PROTO NewTempProto();
00128 
00129 ADAPT_CLASS ReadAdaptedClass(FILE *File);
00130 
00131 PERM_CONFIG ReadPermConfig(FILE *File);
00132 
00133 TEMP_CONFIG ReadTempConfig(FILE *File);
00134 
00135 void WriteAdaptedClass(FILE *File, ADAPT_CLASS Class, int NumConfigs);
00136 
00137 void WritePermConfig(FILE *File, PERM_CONFIG Config);
00138 
00139 void WriteTempConfig(FILE *File, TEMP_CONFIG Config);
00140 
00141 #endif