tesseract  4.1.0
adaptive.h
Go to the documentation of this file.
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 <cstdio>
25 #include "intproto.h"
26 #include "oldlist.h"
27 
28 typedef struct {
29  uint16_t ProtoId;
30  uint16_t dummy;
32 }
33 
36 
37 typedef struct {
38  uint8_t NumTimesSeen;
39  uint8_t ProtoVectorSize;
42  int FontinfoId; // font information inferred from pre-trained templates
45 
46 typedef struct {
48  int FontinfoId; // font information inferred from pre-trained templates
51 
52 typedef union {
56 
57 typedef struct {
58  uint8_t NumPermConfigs;
59  uint8_t MaxNumTimesSeen; // maximum number of times any TEMP_CONFIG was seen
60  uint8_t dummy[2]; // (cut at matcher_min_examples_for_prototyping)
67 
68 typedef struct {
71  uint8_t NumPermClasses;
72  uint8_t dummy[3];
76 
77 /*----------------------------------------------------------------------------
78  Public Function Prototypes
79 ----------------------------------------------------------------------------*/
80 #define NumNonEmptyClassesIn(Template) ((Template)->NumNonEmptyClasses)
81 
82 #define IsEmptyAdaptedClass(Class) \
83  ((Class)->NumPermConfigs == 0 && (Class)->TempProtos == NIL_LIST)
84 
85 #define ConfigIsPermanent(Class, ConfigId) \
86  (test_bit((Class)->PermConfigs, ConfigId))
87 
88 #define MakeConfigPermanent(Class, ConfigId) \
89  (SET_BIT((Class)->PermConfigs, ConfigId))
90 
91 #define MakeProtoPermanent(Class, ProtoId) \
92  (SET_BIT((Class)->PermProtos, ProtoId))
93 
94 #define TempConfigFor(Class, ConfigId) ((Class)->Config[ConfigId].Temp)
95 
96 #define PermConfigFor(Class, ConfigId) ((Class)->Config[ConfigId].Perm)
97 
98 #define IncreaseConfidence(TempConfig) ((TempConfig)->NumTimesSeen++)
99 
100 void AddAdaptedClass(ADAPT_TEMPLATES Templates, ADAPT_CLASS Class,
101  CLASS_ID ClassId);
102 
103 void FreeTempProto(void* arg);
104 
106 
108 
109 void free_adapted_class(ADAPT_CLASS adapt_class);
110 
112 
113 TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId);
114 
116 
118 
120 
122 
123 void WriteAdaptedClass(FILE* File, ADAPT_CLASS Class, int NumConfigs);
124 
125 void WritePermConfig(FILE* File, PERM_CONFIG Config);
126 
127 void WriteTempConfig(FILE* File, TEMP_CONFIG Config);
128 
129 #endif
#define MAX_NUM_CONFIGS
Definition: intproto.h:47
void WriteAdaptedClass(FILE *File, ADAPT_CLASS Class, int NumConfigs)
Definition: adaptive.cpp:409
uint8_t NumPermConfigs
Definition: adaptive.h:58
BIT_VECTOR PermConfigs
Definition: adaptive.h:62
void FreeTempProto(void *arg)
Definition: adaptive.cpp:81
#define MAX_NUM_CLASSES
Definition: matchdefs.h:30
PERM_CONFIG ReadPermConfig(tesseract::TFile *File)
Definition: adaptive.cpp:362
void WritePermConfig(FILE *File, PERM_CONFIG Config)
Definition: adaptive.cpp:481
UNICHAR_ID * Ambigs
Definition: adaptive.h:47
uint8_t NumTimesSeen
Definition: adaptive.h:38
uint8_t NumPermClasses
Definition: adaptive.h:71
void free_adapted_templates(ADAPT_TEMPLATES templates)
Definition: adaptive.cpp:182
void WriteTempConfig(FILE *File, TEMP_CONFIG Config)
Definition: adaptive.cpp:503
PERM_CONFIG Perm
Definition: adaptive.h:54
TEMP_CONFIG Temp
Definition: adaptive.h:53
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
INT_TEMPLATES Templates
Definition: adaptive.h:69
TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId)
Definition: adaptive.cpp:203
void free_adapted_class(ADAPT_CLASS adapt_class)
Definition: adaptive.cpp:124
ADAPT_CLASS NewAdaptedClass()
Definition: adaptive.cpp:102
BIT_VECTOR PermProtos
Definition: adaptive.h:61
void FreeTempConfig(TEMP_CONFIG Config)
Definition: adaptive.cpp:74
TEMP_CONFIG ReadTempConfig(tesseract::TFile *File)
Definition: adaptive.cpp:386
void AddAdaptedClass(ADAPT_TEMPLATES Templates, ADAPT_CLASS Class, CLASS_ID ClassId)
Definition: adaptive.cpp:45
UNICHAR_ID CLASS_ID
Definition: matchdefs.h:34
int UNICHAR_ID
Definition: unichar.h:34
uint16_t dummy
Definition: adaptive.h:30
uint8_t ProtoVectorSize
Definition: adaptive.h:39
int16_t PROTO_ID
Definition: matchdefs.h:40
PROTO_STRUCT Proto
Definition: adaptive.h:31
uint16_t ProtoId
Definition: adaptive.h:29
BIT_VECTOR Protos
Definition: adaptive.h:41
TEMP_PROTO NewTempProto()
Definition: adaptive.cpp:228
PROTO_ID MaxProtoId
Definition: adaptive.h:40
CLUSTERCONFIG Config
ADAPT_CLASS ReadAdaptedClass(tesseract::TFile *File)
Definition: adaptive.cpp:281
uint8_t MaxNumTimesSeen
Definition: adaptive.h:59