tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
protos.h
1 /* -*-C-*-
2  ******************************************************************************
3  *
4  * File: protos.h
5  * Description:
6  * Author: Mark Seaman, SW Productivity
7  * Created: Fri Oct 16 14:37:00 1987
8  * Modified: Fri Jul 12 10:06:55 1991 (Dan Johnson) danj@hpgrlj
9  * Language: C
10  * Package: N/A
11  * Status: Reusable Software Component
12  *
13  * (c) Copyright 1987, Hewlett-Packard Company.
14  ** Licensed under the Apache License, Version 2.0 (the "License");
15  ** you may not use this file except in compliance with the License.
16  ** You may obtain a copy of the License at
17  ** http://www.apache.org/licenses/LICENSE-2.0
18  ** Unless required by applicable law or agreed to in writing, software
19  ** distributed under the License is distributed on an "AS IS" BASIS,
20  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  ** See the License for the specific language governing permissions and
22  ** limitations under the License.
23  *
24  *****************************************************************************/
25 
26 #ifndef PROTOS_H
27 #define PROTOS_H
28 
29 /*----------------------------------------------------------------------
30  I n c l u d e s
31 ----------------------------------------------------------------------*/
32 #include "bitvec.h"
33 #include "params.h"
34 #include "unichar.h"
35 #include "unicity_table.h"
36 
37 /*----------------------------------------------------------------------
38  T y p e s
39 ----------------------------------------------------------------------*/
40 using CONFIGS = BIT_VECTOR*;
41 
42 typedef struct {
43  float A;
44  float B;
45  float C;
46  float X;
47  float Y;
48  float Angle;
49  float Length;
50 } PROTO_STRUCT;
51 using PROTO = PROTO_STRUCT*;
52 
53 struct CLASS_STRUCT {
55  : NumProtos(0),
56  MaxNumProtos(0),
57  Prototypes(nullptr),
58  NumConfigs(0),
59  MaxNumConfigs(0),
60  Configurations(nullptr) {}
61  int16_t NumProtos;
62  int16_t MaxNumProtos;
64  int16_t NumConfigs;
65  int16_t MaxNumConfigs;
66  CONFIGS Configurations;
68 };
69 using CLASS_TYPE = CLASS_STRUCT*;
70 using CLASSES = CLASS_STRUCT*;
71 
72 /*----------------------------------------------------------------------
73  C o n s t a n t s
74 ----------------------------------------------------------------------*/
75 #define NUMBER_OF_CLASSES MAX_NUM_CLASSES
76 #define Y_OFFSET -40.0
77 #define FEATURE_SCALE 100.0
78 
79 /*----------------------------------------------------------------------
80  V a r i a b l e s
81 ----------------------------------------------------------------------*/
82 extern CLASS_STRUCT TrainingData[];
83 
84 extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file");
85 
86 /*----------------------------------------------------------------------
87  M a c r o s
88 ----------------------------------------------------------------------*/
95 #define AddProtoToConfig(Pid, Config) (SET_BIT(Config, Pid))
96 
103 #define RemoveProtoFromConfig(Pid, Config) (reset_bit(Config, Pid))
104 
111 #define ClassOfChar(Char) \
112  ((TrainingData[Char].NumProtos) ? (&TrainingData[Char]) : NO_CLASS)
113 
121 #define ProtoIn(Class, Pid) (&(Class)->Prototypes[Pid])
122 
130 #define PrintProto(Proto) \
131  (tprintf("X=%4.2f, Y=%4.2f, Length=%4.2f, Angle=%4.2f", Proto->X, Proto->Y, \
132  Proto->Length, Proto->Angle))
133 
141 #define PrintProtoLine(Proto) \
142  (cprintf("A=%4.2f, B=%4.2f, C=%4.2f", Proto->A, Proto->B, Proto->C))
143 
144 /*----------------------------------------------------------------------
145  F u n c t i o n s
146 ----------------------------------------------------------------------*/
147 int AddConfigToClass(CLASS_TYPE Class);
148 
149 int AddProtoToClass(CLASS_TYPE Class);
150 
151 float ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config);
152 
153 float ClassProtoLength(CLASS_TYPE Class);
154 
155 void CopyProto(PROTO Src, PROTO Dest);
156 
157 void FillABC(PROTO Proto);
158 
159 void FreeClass(CLASS_TYPE Class);
160 
161 void FreeClassFields(CLASS_TYPE Class);
162 
163 void InitPrototypes();
164 
165 CLASS_TYPE NewClass(int NumProtos, int NumConfigs);
166 
167 void PrintProtos(CLASS_TYPE Class);
168 
169 #endif
int16_t MaxNumConfigs
Definition: protos.h:65
float Y
Definition: protos.h:47
float Length
Definition: protos.h:49
CLASS_STRUCT()
Definition: protos.h:54
int16_t MaxNumProtos
Definition: protos.h:62
UnicityTableEqEq< int > font_set
Definition: protos.h:67
float B
Definition: protos.h:44
CONFIGS Configurations
Definition: protos.h:66
float X
Definition: protos.h:46
Definition: protos.h:42
float C
Definition: protos.h:45
int16_t NumProtos
Definition: protos.h:61
float A
Definition: protos.h:43
Definition: protos.h:53
int16_t NumConfigs
Definition: protos.h:64
PROTO Prototypes
Definition: protos.h:63
float Angle
Definition: protos.h:48