tesseract  4.1.1
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  **
6  ** (c) Copyright Hewlett-Packard Company, 1988.
7  ** Licensed under the Apache License, Version 2.0 (the "License");
8  ** you may not use this file except in compliance with the License.
9  ** You may obtain a copy of the License at
10  ** http://www.apache.org/licenses/LICENSE-2.0
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  ******************************************************************************/
17 #ifndef ADAPTIVE_H
18 #define ADAPTIVE_H
19 
20 /*----------------------------------------------------------------------------
21  Include Files and Type Defines
22 ----------------------------------------------------------------------------*/
23 #include <cstdio>
24 #include "intproto.h"
25 #include "oldlist.h"
26 
27 typedef struct {
28  uint16_t ProtoId;
29  PROTO_STRUCT Proto;
30 }
31 
34 
35 typedef struct {
36  uint8_t NumTimesSeen;
37  uint8_t ProtoVectorSize;
40  int FontinfoId; // font information inferred from pre-trained templates
43 
44 typedef struct {
46  int FontinfoId; // font information inferred from pre-trained templates
49 
50 typedef union {
54 
55 typedef struct {
56  uint8_t NumPermConfigs;
57  uint8_t MaxNumTimesSeen; // maximum number of times any TEMP_CONFIG was seen
58  // (cut at matcher_min_examples_for_prototyping)
65 
66 typedef struct {
69  uint8_t NumPermClasses;
73 
74 /*----------------------------------------------------------------------------
75  Public Function Prototypes
76 ----------------------------------------------------------------------------*/
77 #define NumNonEmptyClassesIn(Template) ((Template)->NumNonEmptyClasses)
78 
79 #define IsEmptyAdaptedClass(Class) \
80  ((Class)->NumPermConfigs == 0 && (Class)->TempProtos == NIL_LIST)
81 
82 #define ConfigIsPermanent(Class, ConfigId) \
83  (test_bit((Class)->PermConfigs, ConfigId))
84 
85 #define MakeConfigPermanent(Class, ConfigId) \
86  (SET_BIT((Class)->PermConfigs, ConfigId))
87 
88 #define MakeProtoPermanent(Class, ProtoId) \
89  (SET_BIT((Class)->PermProtos, ProtoId))
90 
91 #define TempConfigFor(Class, ConfigId) ((Class)->Config[ConfigId].Temp)
92 
93 #define PermConfigFor(Class, ConfigId) ((Class)->Config[ConfigId].Perm)
94 
95 #define IncreaseConfidence(TempConfig) ((TempConfig)->NumTimesSeen++)
96 
97 void AddAdaptedClass(ADAPT_TEMPLATES Templates, ADAPT_CLASS Class,
98  CLASS_ID ClassId);
99 
100 void FreeTempProto(void* arg);
101 
103 
105 
106 void free_adapted_class(ADAPT_CLASS adapt_class);
107 
109 
110 TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId);
111 
113 
115 
117 
119 
120 void WriteAdaptedClass(FILE* File, ADAPT_CLASS Class, int NumConfigs);
121 
122 void WritePermConfig(FILE* File, PERM_CONFIG Config);
123 
124 void WriteTempConfig(FILE* File, TEMP_CONFIG Config);
125 
126 #endif
MAX_NUM_CLASSES
#define MAX_NUM_CLASSES
Definition: matchdefs.h:30
MAX_NUM_CONFIGS
#define MAX_NUM_CONFIGS
Definition: intproto.h:47
TEMP_CONFIG_STRUCT::NumTimesSeen
uint8_t NumTimesSeen
Definition: adaptive.h:36
PERM_CONFIG_STRUCT::Ambigs
UNICHAR_ID * Ambigs
Definition: adaptive.h:45
ADAPTED_CONFIG
Definition: adaptive.h:50
ADAPT_TEMPLATES_STRUCT::Templates
INT_TEMPLATES Templates
Definition: adaptive.h:67
ADAPT_CLASS_STRUCT::MaxNumTimesSeen
uint8_t MaxNumTimesSeen
Definition: adaptive.h:57
BIT_VECTOR
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
WritePermConfig
void WritePermConfig(FILE *File, PERM_CONFIG Config)
Definition: adaptive.cpp:481
ADAPT_TEMPLATES_STRUCT::NumNonEmptyClasses
int NumNonEmptyClasses
Definition: adaptive.h:68
NewAdaptedClass
ADAPT_CLASS NewAdaptedClass()
Definition: adaptive.cpp:102
ADAPT_CLASS_STRUCT::TempProtos
LIST TempProtos
Definition: adaptive.h:61
FreeTempConfig
void FreeTempConfig(TEMP_CONFIG Config)
Definition: adaptive.cpp:74
ADAPT_CLASS_STRUCT::NumPermConfigs
uint8_t NumPermConfigs
Definition: adaptive.h:56
UNICHAR_ID
int UNICHAR_ID
Definition: unichar.h:34
AddAdaptedClass
void AddAdaptedClass(ADAPT_TEMPLATES Templates, ADAPT_CLASS Class, CLASS_ID ClassId)
Definition: adaptive.cpp:45
WriteTempConfig
void WriteTempConfig(FILE *File, TEMP_CONFIG Config)
Definition: adaptive.cpp:503
TEMP_CONFIG_STRUCT::Protos
BIT_VECTOR Protos
Definition: adaptive.h:39
WriteAdaptedClass
void WriteAdaptedClass(FILE *File, ADAPT_CLASS Class, int NumConfigs)
Definition: adaptive.cpp:409
ADAPT_TEMPLATES_STRUCT
Definition: adaptive.h:66
PERM_CONFIG_STRUCT::FontinfoId
int FontinfoId
Definition: adaptive.h:46
ReadTempConfig
TEMP_CONFIG ReadTempConfig(tesseract::TFile *File)
Definition: adaptive.cpp:386
ReadPermConfig
PERM_CONFIG ReadPermConfig(tesseract::TFile *File)
Definition: adaptive.cpp:362
ADAPT_CLASS_STRUCT::PermConfigs
BIT_VECTOR PermConfigs
Definition: adaptive.h:60
ReadAdaptedClass
ADAPT_CLASS ReadAdaptedClass(tesseract::TFile *File)
Definition: adaptive.cpp:281
TEMP_CONFIG_STRUCT::FontinfoId
int FontinfoId
Definition: adaptive.h:40
ADAPT_CLASS_STRUCT
Definition: adaptive.h:55
TEMP_CONFIG_STRUCT::MaxProtoId
PROTO_ID MaxProtoId
Definition: adaptive.h:38
NewTempProto
TEMP_PROTO NewTempProto()
Definition: adaptive.cpp:228
FreeTempProto
void FreeTempProto(void *arg)
Definition: adaptive.cpp:81
ADAPT_TEMPLATES_STRUCT::NumPermClasses
uint8_t NumPermClasses
Definition: adaptive.h:69
TEMP_CONFIG_STRUCT::ProtoVectorSize
uint8_t ProtoVectorSize
Definition: adaptive.h:37
intproto.h
ADAPT_CLASS_STRUCT::PermProtos
BIT_VECTOR PermProtos
Definition: adaptive.h:59
PERM_CONFIG_STRUCT
Definition: adaptive.h:44
free_adapted_templates
void free_adapted_templates(ADAPT_TEMPLATES templates)
Definition: adaptive.cpp:182
free_adapted_class
void free_adapted_class(ADAPT_CLASS adapt_class)
Definition: adaptive.cpp:124
TEMP_PROTO_STRUCT
Definition: adaptive.h:27
PROTO_ID
int16_t PROTO_ID
Definition: matchdefs.h:40
PROTO_STRUCT
Definition: protos.h:36
TEMP_CONFIG_STRUCT
Definition: adaptive.h:35
CLASS_ID
UNICHAR_ID CLASS_ID
Definition: matchdefs.h:34
list_rec
Definition: oldlist.h:81
oldlist.h
INT_TEMPLATES_STRUCT
Definition: intproto.h:118
tesseract::TFile
Definition: serialis.h:76
ADAPTED_CONFIG::Perm
PERM_CONFIG Perm
Definition: adaptive.h:52
ADAPTED_CONFIG::Temp
TEMP_CONFIG Temp
Definition: adaptive.h:51
NewTempConfig
TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId)
Definition: adaptive.cpp:203
Config
CLUSTERCONFIG Config
Definition: commontraining.cpp:88