tesseract  5.0.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  **
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 #include "intproto.h"
21 #include "oldlist.h"
22 
23 #include <cstdio>
24 
25 namespace tesseract {
26 
28  uint16_t ProtoId;
30 };
31 
33  TEMP_CONFIG_STRUCT() = default;
36  uint8_t NumTimesSeen;
37  uint8_t ProtoVectorSize;
40  int FontinfoId; // font information inferred from pre-trained templates
41 };
42 
44  PERM_CONFIG_STRUCT() = default;
47  int FontinfoId; // font information inferred from pre-trained templates
48 };
49 
53 };
54 
58  uint8_t NumPermConfigs;
59  uint8_t MaxNumTimesSeen; // maximum number of times any TEMP_CONFIG_STRUCT was seen
60  // (cut at matcher_min_examples_for_prototyping)
65 };
66 
68 public:
74  uint8_t NumPermClasses;
76 };
77 
78 /*----------------------------------------------------------------------------
79  Public Function Prototypes
80 ----------------------------------------------------------------------------*/
81 #define NumNonEmptyClassesIn(Template) ((Template)->NumNonEmptyClasses)
82 
83 #define IsEmptyAdaptedClass(Class) ((Class)->NumPermConfigs == 0 && (Class)->TempProtos == NIL_LIST)
84 
85 #define ConfigIsPermanent(Class, ConfigId) (test_bit((Class)->PermConfigs, ConfigId))
86 
87 #define MakeConfigPermanent(Class, ConfigId) (SET_BIT((Class)->PermConfigs, ConfigId))
88 
89 #define MakeProtoPermanent(Class, ProtoId) (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_STRUCT *Templates, ADAPT_CLASS_STRUCT *Class, CLASS_ID ClassId);
98 
99 ADAPT_CLASS_STRUCT *ReadAdaptedClass(tesseract::TFile *File);
100 
101 PERM_CONFIG_STRUCT *ReadPermConfig(tesseract::TFile *File);
102 
103 TEMP_CONFIG_STRUCT *ReadTempConfig(tesseract::TFile *File);
104 
105 void WriteAdaptedClass(FILE *File, ADAPT_CLASS_STRUCT *Class, int NumConfigs);
106 
107 void WritePermConfig(FILE *File, PERM_CONFIG_STRUCT *Config);
108 
109 void WriteTempConfig(FILE *File, TEMP_CONFIG_STRUCT *Config);
110 
111 } // namespace tesseract
112 
113 #endif
#define MAX_NUM_CONFIGS
Definition: intproto.h:47
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
#define MAX_NUM_CLASSES
Definition: matchdefs.h:31
void WriteAdaptedClass(FILE *File, ADAPT_CLASS_STRUCT *Class, int NumConfigs)
Definition: adaptive.cpp:307
ADAPT_CLASS_STRUCT * ReadAdaptedClass(TFile *fp)
Definition: adaptive.cpp:186
void WritePermConfig(FILE *File, PERM_CONFIG_STRUCT *Config)
Definition: adaptive.cpp:368
PERM_CONFIG_STRUCT * ReadPermConfig(TFile *fp)
Definition: adaptive.cpp:262
CLUSTERCONFIG Config
int UNICHAR_ID
Definition: unichar.h:36
int16_t PROTO_ID
Definition: matchdefs.h:40
void AddAdaptedClass(ADAPT_TEMPLATES_STRUCT *Templates, ADAPT_CLASS_STRUCT *Class, CLASS_ID ClassId)
Definition: adaptive.cpp:41
TEMP_CONFIG_STRUCT * ReadTempConfig(TFile *fp)
Definition: adaptive.cpp:285
void WriteTempConfig(FILE *File, TEMP_CONFIG_STRUCT *Config)
Definition: adaptive.cpp:391
UNICHAR_ID CLASS_ID
Definition: matchdefs.h:34
PERM_CONFIG_STRUCT * Perm
Definition: adaptive.h:52
TEMP_CONFIG_STRUCT * Temp
Definition: adaptive.h:51
ADAPTED_CONFIG Config[MAX_NUM_CONFIGS]
Definition: adaptive.h:64
ADAPT_CLASS_STRUCT * Class[MAX_NUM_CLASSES]
Definition: adaptive.h:75
INT_TEMPLATES_STRUCT * Templates
Definition: adaptive.h:72