tesseract 4.1.1
Loading...
Searching...
No Matches
intproto.h
Go to the documentation of this file.
1/******************************************************************************
2 ** Filename: intproto.h
3 ** Purpose: Definition of data structures for integer protos.
4 ** Author: Dan Johnson
5 ** History: Thu Feb 7 12:58:45 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
19#ifndef INTPROTO_H
20#define INTPROTO_H
21
25#include "genericvector.h"
26#include "matchdefs.h"
27#include "mfoutline.h"
28#include "protos.h"
29#include "scrollview.h"
30#include "unicharset.h"
31
32class FCOORD;
33
34/* define order of params in pruners */
35#define PRUNER_X 0
36#define PRUNER_Y 1
37#define PRUNER_ANGLE 2
38
39/* definition of coordinate system offsets for each table parameter */
40#define ANGLE_SHIFT (0.0)
41#define X_SHIFT (0.5)
42#define Y_SHIFT (0.5)
43
44#define MAX_PROTO_INDEX 24
45#define BITS_PER_WERD static_cast<int>(8 * sizeof(uint32_t))
46/* Script detection: increase this number to 128 */
47#define MAX_NUM_CONFIGS 64
48#define MAX_NUM_PROTOS 512
49#define PROTOS_PER_PROTO_SET 64
50#define MAX_NUM_PROTO_SETS (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET)
51#define NUM_PP_PARAMS 3
52#define NUM_PP_BUCKETS 64
53#define NUM_CP_BUCKETS 24
54#define CLASSES_PER_CP 32
55#define NUM_BITS_PER_CLASS 2
56#define CLASS_PRUNER_CLASS_MASK (~(~0u << NUM_BITS_PER_CLASS))
57#define CLASSES_PER_CP_WERD (CLASSES_PER_CP / NUM_BITS_PER_CLASS)
58#define PROTOS_PER_PP_WERD BITS_PER_WERD
59#define BITS_PER_CP_VECTOR (CLASSES_PER_CP * NUM_BITS_PER_CLASS)
60#define MAX_NUM_CLASS_PRUNERS \
61 ((MAX_NUM_CLASSES + CLASSES_PER_CP - 1) / CLASSES_PER_CP)
62#define WERDS_PER_CP_VECTOR (BITS_PER_CP_VECTOR / BITS_PER_WERD)
63#define WERDS_PER_PP_VECTOR \
64 ((PROTOS_PER_PROTO_SET + BITS_PER_WERD - 1) / BITS_PER_WERD)
65#define WERDS_PER_PP (NUM_PP_PARAMS * NUM_PP_BUCKETS * WERDS_PER_PP_VECTOR)
66#define WERDS_PER_CP \
67 (NUM_CP_BUCKETS * NUM_CP_BUCKETS * NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR)
68#define WERDS_PER_CONFIG_VEC \
69 ((MAX_NUM_CONFIGS + BITS_PER_WERD - 1) / BITS_PER_WERD)
70
71/* The first 3 dimensions of the CLASS_PRUNER_STRUCT are the
72 * 3 axes of the quantized feature space.
73 * The position of the the bits recorded for each class in the
74 * 4th dimension is determined by using CPrunerWordIndexFor(c),
75 * where c is the corresponding class id. */
79};
80
81typedef struct {
82 int8_t A;
83 uint8_t B;
84 int8_t C;
85 uint8_t Angle;
86 uint32_t Configs[WERDS_PER_CONFIG_VEC];
87}
88
91
94
95typedef struct {
98}
99
102
104
105typedef struct {
106 uint16_t NumProtos;
108 uint8_t NumConfigs;
110 uint8_t* ProtoLengths;
111 uint16_t ConfigLengths[MAX_NUM_CONFIGS];
112 int font_set_id; // FontSet id, see above
113}
114
117
118typedef struct {
123}
124
127
128/* definitions of integer features*/
129#define MAX_NUM_INT_FEATURES 512
130#define INT_CHAR_NORM_RANGE 256
131
133 INT_FEATURE_STRUCT() : X(0), Y(0), Theta(0), CP_misses(0) {}
134 // Builds a feature from an FCOORD for position with all the necessary
135 // clipping and rounding.
136 INT_FEATURE_STRUCT(const FCOORD& pos, uint8_t theta);
137 // Builds a feature from ints with all the necessary clipping and casting.
138 INT_FEATURE_STRUCT(int x, int y, int theta);
139
140 uint8_t X;
141 uint8_t Y;
142 uint8_t Theta;
143 int8_t CP_misses;
144
145 void print() const {
146 tprintf("(%d,%d):%d\n", X, Y, Theta);
147 }
148};
149
151
153
160
165#define MaxNumIntProtosIn(C) (C->NumProtoSets * PROTOS_PER_PROTO_SET)
166#define SetForProto(P) (P / PROTOS_PER_PROTO_SET)
167#define IndexForProto(P) (P % PROTOS_PER_PROTO_SET)
168#define ProtoForProtoId(C, P) \
169 (&((C->ProtoSets[SetForProto(P)])->Protos[IndexForProto(P)]))
170#define PPrunerWordIndexFor(I) \
171 (((I) % PROTOS_PER_PROTO_SET) / PROTOS_PER_PP_WERD)
172#define PPrunerBitIndexFor(I) ((I) % PROTOS_PER_PP_WERD)
173#define PPrunerMaskFor(I) (1 << PPrunerBitIndexFor(I))
174
175#define MaxNumClassesIn(T) (T->NumClassPruners * CLASSES_PER_CP)
176#define LegalClassId(c) ((c) >= 0 && (c) <= MAX_CLASS_ID)
177#define UnusedClassIdIn(T, c) ((T)->Class[c] == nullptr)
178#define ClassForClassId(T, c) ((T)->Class[c])
179#define ClassPrunersFor(T) ((T)->ClassPruner)
180#define CPrunerIdFor(c) ((c) / CLASSES_PER_CP)
181#define CPrunerFor(T, c) ((T)->ClassPruners[CPrunerIdFor(c)])
182#define CPrunerWordIndexFor(c) (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD)
183#define CPrunerBitIndexFor(c) (((c) % CLASSES_PER_CP) % CLASSES_PER_CP_WERD)
184#define CPrunerMaskFor(L, c) \
185 (((L) + 1) << CPrunerBitIndexFor(c) * NUM_BITS_PER_CLASS)
186
187/* DEBUG macros*/
188#define PRINT_MATCH_SUMMARY 0x001
189#define DISPLAY_FEATURE_MATCHES 0x002
190#define DISPLAY_PROTO_MATCHES 0x004
191#define PRINT_FEATURE_MATCHES 0x008
192#define PRINT_PROTO_MATCHES 0x010
193#define CLIP_MATCH_EVIDENCE 0x020
194
195#define MatchDebuggingOn(D) (D)
196#define PrintMatchSummaryOn(D) ((D)&PRINT_MATCH_SUMMARY)
197#define DisplayFeatureMatchesOn(D) ((D)&DISPLAY_FEATURE_MATCHES)
198#define DisplayProtoMatchesOn(D) ((D)&DISPLAY_PROTO_MATCHES)
199#define PrintFeatureMatchesOn(D) ((D)&PRINT_FEATURE_MATCHES)
200#define PrintProtoMatchesOn(D) ((D)&PRINT_PROTO_MATCHES)
201#define ClipMatchEvidenceOn(D) ((D)&CLIP_MATCH_EVIDENCE)
202
206void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class);
207
208int AddIntConfig(INT_CLASS Class);
209
210int AddIntProto(INT_CLASS Class);
211
212void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId,
213 INT_TEMPLATES Templates);
214
215void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class,
216 bool debug);
217
218uint8_t Bucket8For(float param, float offset, int num_buckets);
219uint16_t Bucket16For(float param, float offset, int num_buckets);
220
221uint8_t CircBucketFor(float param, float offset, int num_buckets);
222
223void UpdateMatchDisplay();
224
225void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class);
226
227void DisplayIntFeature(const INT_FEATURE_STRUCT* Feature, float Evidence);
228
229void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, float Evidence);
230
231INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs);
232
234
235void free_int_templates(INT_TEMPLATES templates);
236
238
239namespace tesseract {
240
241// Clears the given window and draws the featurespace guides for the
242// appropriate normalization method.
243void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView* window);
244
245} // namespace tesseract.
246
247/*----------------------------------------------------------------------------*/
248#ifndef GRAPHICS_DISABLED
249void RenderIntFeature(ScrollView* window, const INT_FEATURE_STRUCT* Feature,
250 ScrollView::Color color);
251
253
255
257
258// Creates a window of the appropriate size for displaying elements
259// in feature space.
260ScrollView* CreateFeatureSpaceWindow(const char* name, int xpos, int ypos);
261#endif // GRAPHICS_DISABLED
262
263#endif
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35
INT_TEMPLATES NewIntTemplates()
Definition: intproto.cpp:682
void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, float Evidence)
Definition: intproto.cpp:590
void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates)
Definition: intproto.cpp:328
void InitIntMatchWindowIfReqd()
Definition: intproto.cpp:1722
struct INT_PROTO_STRUCT * INT_PROTO
#define MAX_NUM_PROTO_SETS
Definition: intproto.h:50
#define NUM_PP_PARAMS
Definition: intproto.h:51
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1763
void UpdateMatchDisplay()
Definition: intproto.cpp:447
uint32_t CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4]
Definition: intproto.h:103
uint8_t Bucket8For(float param, float offset, int num_buckets)
Definition: intproto.cpp:418
void InitFeatureDisplayWindowIfReqd()
Definition: intproto.cpp:1754
int AddIntProto(INT_CLASS Class)
Definition: intproto.cpp:282
#define MAX_NUM_INT_FEATURES
Definition: intproto.h:129
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
Definition: intproto.h:152
int AddIntConfig(INT_CLASS Class)
Definition: intproto.cpp:261
#define WERDS_PER_PP_VECTOR
Definition: intproto.h:63
void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class)
Definition: intproto.cpp:463
#define MAX_NUM_CONFIGS
Definition: intproto.h:47
struct INT_TEMPLATES_STRUCT * INT_TEMPLATES
void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class)
Definition: intproto.cpp:231
void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, float Evidence)
Definition: intproto.cpp:608
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
Definition: intproto.cpp:1602
#define WERDS_PER_CONFIG_VEC
Definition: intproto.h:68
uint8_t CircBucketFor(float param, float offset, int num_buckets)
Definition: intproto.cpp:432
struct INT_CLASS_STRUCT * INT_CLASS
void ShowMatchDisplay()
uint16_t Bucket16For(float param, float offset, int num_buckets)
Definition: intproto.cpp:422
#define NUM_CP_BUCKETS
Definition: intproto.h:53
#define MAX_NUM_CLASS_PRUNERS
Definition: intproto.h:60
IntmatcherDebugAction
Definition: intproto.h:154
@ IDA_BOTH
Definition: intproto.h:158
@ IDA_STATIC
Definition: intproto.h:156
@ IDA_SHAPE_INDEX
Definition: intproto.h:157
@ IDA_ADAPTIVE
Definition: intproto.h:155
#define WERDS_PER_CP_VECTOR
Definition: intproto.h:62
#define PROTOS_PER_PROTO_SET
Definition: intproto.h:49
void InitProtoDisplayWindowIfReqd()
Definition: intproto.cpp:1743
struct PROTO_SET_STRUCT * PROTO_SET
uint32_t PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR]
Definition: intproto.h:93
#define NUM_PP_BUCKETS
Definition: intproto.h:52
void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class, bool debug)
Definition: intproto.cpp:367
void free_int_templates(INT_TEMPLATES templates)
Definition: intproto.cpp:698
INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs)
Definition: intproto.cpp:626
NORM_METHOD
Definition: mfoutline.h:63
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
UNICHAR_ID CLASS_ID
Definition: matchdefs.h:34
int16_t PROTO_ID
Definition: matchdefs.h:40
#define MAX_NUM_CLASSES
Definition: matchdefs.h:30
CLUSTERCONFIG Config
void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView *window)
Definition: intproto.cpp:987
Definition: points.h:189
uint32_t p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR]
Definition: intproto.h:78
uint8_t Angle
Definition: intproto.h:85
PROTO_PRUNER ProtoPruner
Definition: intproto.h:96
uint8_t NumProtoSets
Definition: intproto.h:107
uint16_t NumProtos
Definition: intproto.h:106
uint8_t * ProtoLengths
Definition: intproto.h:110
uint8_t NumConfigs
Definition: intproto.h:108
void print() const
Definition: intproto.h:145