tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
adaptive.h
1 /******************************************************************************
2  ** Filename: adaptive.h
3  ** Purpose: Interface to adaptive matcher.
4  ** Author: Dan Johnson
5  ** History: Fri Mar 8 10:00:49 1991, DSJ, Created.
6  **
7  ** (c) Copyright Hewlett-Packard Company, 1988.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  ******************************************************************************/
18 #ifndef ADAPTIVE_H
19 #define ADAPTIVE_H
20 
21 /*----------------------------------------------------------------------------
22  Include Files and Type Defines
23 ----------------------------------------------------------------------------*/
24 #include "oldlist.h"
25 #include "intproto.h"
26 #include <cstdio>
27 
28 typedef struct
29 {
30  uint16_t ProtoId;
31  uint16_t dummy;
33 }
34 
35 
38 
39 typedef struct
40 {
41  uint8_t NumTimesSeen;
42  uint8_t ProtoVectorSize;
43  PROTO_ID MaxProtoId;
44  BIT_VECTOR Protos;
45  int FontinfoId; // font information inferred from pre-trained templates
48 
49 typedef struct
50 {
51  UNICHAR_ID *Ambigs;
52  int FontinfoId; // font information inferred from pre-trained templates
55 
56 typedef union
57 {
61 
62 typedef struct
63 {
64  uint8_t NumPermConfigs;
65  uint8_t MaxNumTimesSeen; // maximum number of times any TEMP_CONFIG was seen
66  uint8_t dummy[2]; // (cut at matcher_min_examples_for_prototyping)
67  BIT_VECTOR PermProtos;
68  BIT_VECTOR PermConfigs;
70  ADAPTED_CONFIG Config[MAX_NUM_CONFIGS];
73 
74 typedef struct
75 {
78  uint8_t NumPermClasses;
79  uint8_t dummy[3];
80  ADAPT_CLASS Class[MAX_NUM_CLASSES];
83 
84 /*----------------------------------------------------------------------------
85  Public Function Prototypes
86 ----------------------------------------------------------------------------*/
87 #define NumNonEmptyClassesIn(Template) ((Template)->NumNonEmptyClasses)
88 
89 #define IsEmptyAdaptedClass(Class) ((Class)->NumPermConfigs == 0 && \
90 (Class)->TempProtos == NIL_LIST)
91 
92 #define ConfigIsPermanent(Class,ConfigId) \
93 (test_bit ((Class)->PermConfigs, ConfigId))
94 
95 #define MakeConfigPermanent(Class,ConfigId) \
96 (SET_BIT ((Class)->PermConfigs, ConfigId))
97 
98 #define MakeProtoPermanent(Class,ProtoId) \
99 (SET_BIT ((Class)->PermProtos, ProtoId))
100 
101 #define TempConfigFor(Class,ConfigId) \
102 ((Class)->Config[ConfigId].Temp)
103 
104 #define PermConfigFor(Class,ConfigId) \
105 ((Class)->Config[ConfigId].Perm)
106 
107 #define IncreaseConfidence(TempConfig) \
108 ((TempConfig)->NumTimesSeen++)
109 
110 void AddAdaptedClass(ADAPT_TEMPLATES Templates,
111  ADAPT_CLASS Class,
112  CLASS_ID ClassId);
113 
114 void FreeTempProto(void *arg);
115 
116 void FreeTempConfig(TEMP_CONFIG Config);
117 
118 ADAPT_CLASS NewAdaptedClass();
119 
120 void free_adapted_class(ADAPT_CLASS adapt_class);
121 
122 void free_adapted_templates(ADAPT_TEMPLATES templates);
123 
124 TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId);
125 
126 TEMP_PROTO NewTempProto();
127 
128 ADAPT_CLASS ReadAdaptedClass(tesseract::TFile *File);
129 
130 PERM_CONFIG ReadPermConfig(tesseract::TFile *File);
131 
132 TEMP_CONFIG ReadTempConfig(tesseract::TFile *File);
133 
134 void WriteAdaptedClass(FILE *File, ADAPT_CLASS Class, int NumConfigs);
135 
136 void WritePermConfig(FILE *File, PERM_CONFIG Config);
137 
138 void WriteTempConfig(FILE *File, TEMP_CONFIG Config);
139 
140 #endif
int NumNonEmptyClasses
Definition: adaptive.h:77
PROTO_STRUCT Proto
Definition: adaptive.h:32
Definition: adaptive.h:39
uint8_t NumPermClasses
Definition: adaptive.h:78
uint8_t MaxNumTimesSeen
Definition: adaptive.h:65
TEMP_CONFIG Temp
Definition: adaptive.h:58
Definition: intproto.h:118
BIT_VECTOR PermConfigs
Definition: adaptive.h:68
BIT_VECTOR Protos
Definition: adaptive.h:44
uint8_t NumPermConfigs
Definition: adaptive.h:64
uint16_t ProtoId
Definition: adaptive.h:30
uint16_t dummy
Definition: adaptive.h:31
Definition: serialis.h:77
Definition: adaptive.h:74
Definition: adaptive.h:28
PROTO_ID MaxProtoId
Definition: adaptive.h:43
LIST TempProtos
Definition: adaptive.h:69
Definition: protos.h:42
int FontinfoId
Definition: adaptive.h:45
Definition: adaptive.h:49
Definition: adaptive.h:62
Definition: adaptive.h:56
uint8_t NumTimesSeen
Definition: adaptive.h:41
UNICHAR_ID * Ambigs
Definition: adaptive.h:51
PERM_CONFIG Perm
Definition: adaptive.h:59
int FontinfoId
Definition: adaptive.h:52
Definition: oldlist.h:124
BIT_VECTOR PermProtos
Definition: adaptive.h:67
uint8_t ProtoVectorSize
Definition: adaptive.h:42
INT_TEMPLATES Templates
Definition: adaptive.h:76