Tesseract
3.02
|
00001 /* -*-C-*- 00002 ******************************************************************************** 00003 * 00004 * File: protos.h (Formerly protos.h) 00005 * Description: 00006 * Author: Mark Seaman, SW Productivity 00007 * Created: Fri Oct 16 14:37:00 1987 00008 * Modified: Fri Jul 12 10:06:55 1991 (Dan Johnson) danj@hpgrlj 00009 * Language: C 00010 * Package: N/A 00011 * Status: Reusable Software Component 00012 * 00013 * (c) Copyright 1987, Hewlett-Packard Company. 00014 ** Licensed under the Apache License, Version 2.0 (the "License"); 00015 ** you may not use this file except in compliance with the License. 00016 ** You may obtain a copy of the License at 00017 ** http://www.apache.org/licenses/LICENSE-2.0 00018 ** Unless required by applicable law or agreed to in writing, software 00019 ** distributed under the License is distributed on an "AS IS" BASIS, 00020 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00021 ** See the License for the specific language governing permissions and 00022 ** limitations under the License. 00023 * 00024 *********************************************************************************/ 00025 #ifndef PROTOS_H 00026 #define PROTOS_H 00027 00028 /*---------------------------------------------------------------------- 00029 I n c l u d e s 00030 ----------------------------------------------------------------------*/ 00031 #include "bitvec.h" 00032 #include "cutil.h" 00033 #include "unichar.h" 00034 #include "unicity_table.h" 00035 #include "params.h" 00036 00037 /*---------------------------------------------------------------------- 00038 T y p e s 00039 ----------------------------------------------------------------------*/ 00040 typedef BIT_VECTOR *CONFIGS; 00041 00042 typedef struct 00043 { 00044 FLOAT32 A; 00045 FLOAT32 B; 00046 FLOAT32 C; 00047 FLOAT32 X; 00048 FLOAT32 Y; 00049 FLOAT32 Angle; 00050 FLOAT32 Length; 00051 } PROTO_STRUCT; 00052 typedef PROTO_STRUCT *PROTO; 00053 00054 struct CLASS_STRUCT { 00055 CLASS_STRUCT() 00056 : NumProtos(0), MaxNumProtos(0), Prototypes(NULL), 00057 NumConfigs(0), MaxNumConfigs(0), Configurations(NULL) { 00058 } 00059 inT16 NumProtos; 00060 inT16 MaxNumProtos; 00061 PROTO Prototypes; 00062 inT16 NumConfigs; 00063 inT16 MaxNumConfigs; 00064 CONFIGS Configurations; 00065 UnicityTableEqEq<int> font_set; 00066 }; 00067 typedef CLASS_STRUCT *CLASS_TYPE; 00068 typedef CLASS_STRUCT *CLASSES; 00069 00070 /*---------------------------------------------------------------------- 00071 C o n s t a n t s 00072 ----------------------------------------------------------------------*/ 00073 #define NUMBER_OF_CLASSES MAX_NUM_CLASSES 00074 #define Y_OFFSET -40.0 00075 #define FEATURE_SCALE 100.0 00076 00077 /*---------------------------------------------------------------------- 00078 V a r i a b l e s 00079 ----------------------------------------------------------------------*/ 00080 extern CLASS_STRUCT TrainingData[]; 00081 00082 extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file"); 00083 00084 /*---------------------------------------------------------------------- 00085 M a c r o s 00086 ----------------------------------------------------------------------*/ 00093 #define AddProtoToConfig(Pid,Config) \ 00094 (SET_BIT (Config, Pid)) 00095 00102 #define RemoveProtoFromConfig(Pid,Config) \ 00103 (reset_bit (Config, Pid)) 00104 00111 #define ClassOfChar(Char) \ 00112 ((TrainingData [Char].NumProtos) ? \ 00113 (& TrainingData [Char]) : \ 00114 NO_CLASS) 00115 00123 #define ProtoIn(Class,Pid) \ 00124 (& (Class)->Prototypes [Pid]) 00125 00133 #define PrintProto(Proto) \ 00134 (cprintf ("X=%4.2f, Y=%4.2f, Angle=%4.2f", \ 00135 Proto->X, \ 00136 Proto->Y, \ 00137 Proto->Length, \ 00138 Proto->Angle)) \ 00139 00140 00148 #define PrintProtoLine(Proto) \ 00149 (cprintf ("A=%4.2f, B=%4.2f, C=%4.2f", \ 00150 Proto->A, \ 00151 Proto->B, \ 00152 Proto->C)) \ 00153 00154 /*---------------------------------------------------------------------- 00155 F u n c t i o n s 00156 ----------------------------------------------------------------------*/ 00157 int AddConfigToClass(CLASS_TYPE Class); 00158 00159 int AddProtoToClass(CLASS_TYPE Class); 00160 00161 FLOAT32 ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config); 00162 00163 FLOAT32 ClassProtoLength(CLASS_TYPE Class); 00164 00165 void CopyProto(PROTO Src, PROTO Dest); 00166 00167 void FillABC(PROTO Proto); 00168 00169 void FreeClass(CLASS_TYPE Class); 00170 00171 void FreeClassFields(CLASS_TYPE Class); 00172 00173 void InitPrototypes(); 00174 00175 CLASS_TYPE NewClass(int NumProtos, int NumConfigs); 00176 00177 void PrintProtos(CLASS_TYPE Class); 00178 00179 void ReadClassFromFile(FILE *File, UNICHAR_ID unichar_id); 00180 00181 void ReadConfigs(register FILE *File, CLASS_TYPE Class); 00182 00183 void ReadProtos(register FILE *File, CLASS_TYPE Class); 00184 00185 int SplitProto(CLASS_TYPE Class, int OldPid); 00186 00187 void WriteOldConfigFile(FILE *File, CLASS_TYPE Class); 00188 00189 void WriteOldProtoFile(FILE *File, CLASS_TYPE Class); 00190 00191 #endif