tesseract  3.05.02
featdefs.h File Reference
#include "ocrfeatures.h"

Go to the source code of this file.

Classes

struct  CHAR_DESC_STRUCT
 
struct  FEATURE_DEFS_STRUCT
 

Macros

#define NUM_FEATURE_TYPES   4
 
#define ILLEGAL_SHORT_NAME   2000
 

Typedefs

typedef CHAR_DESC_STRUCTCHAR_DESC
 
typedef FEATURE_DEFS_STRUCTFEATURE_DEFS
 

Functions

void TESS_API InitFeatureDefs (FEATURE_DEFS_STRUCT *featuredefs)
 
void FreeCharDescription (CHAR_DESC CharDesc)
 
CHAR_DESC NewCharDescription (const FEATURE_DEFS_STRUCT &FeatureDefs)
 
bool ValidCharDescription (const FEATURE_DEFS_STRUCT &FeatureDefs, CHAR_DESC CharDesc)
 
void WriteCharDescription (const FEATURE_DEFS_STRUCT &FeatureDefs, CHAR_DESC CharDesc, STRING *str)
 
CHAR_DESC TESS_API ReadCharDescription (const FEATURE_DEFS_STRUCT &FeatureDefs, FILE *File)
 
int TESS_API ShortNameToFeatureType (const FEATURE_DEFS_STRUCT &FeatureDefs, const char *ShortName)
 

Variables

const char * kMicroFeatureType
 
const char * kCNFeatureType
 
const char * kIntFeatureType
 
const char * kGeoFeatureType
 
const FEATURE_DESC_STRUCT MicroFeatureDesc
 
TESS_API const FEATURE_DESC_STRUCT PicoFeatDesc
 
const FEATURE_DESC_STRUCT CharNormDesc
 
const FEATURE_DESC_STRUCT OutlineFeatDesc
 
const FEATURE_DESC_STRUCT IntFeatDesc
 
const FEATURE_DESC_STRUCT GeoFeatDesc
 

Macro Definition Documentation

◆ ILLEGAL_SHORT_NAME

#define ILLEGAL_SHORT_NAME   2000

Definition at line 34 of file featdefs.h.

◆ NUM_FEATURE_TYPES

#define NUM_FEATURE_TYPES   4

Include Files and Type Defines

Definition at line 27 of file featdefs.h.

Typedef Documentation

◆ CHAR_DESC

Definition at line 46 of file featdefs.h.

◆ FEATURE_DEFS

Definition at line 53 of file featdefs.h.

Function Documentation

◆ FreeCharDescription()

void FreeCharDescription ( CHAR_DESC  CharDesc)

Release the memory consumed by the specified character description and all of the features in that description.

Parameters
CharDesccharacter description to be deallocated

Globals:

  • none
Note
Exceptions: none
History: Wed May 23 13:52:19 1990, DSJ, Created.

Definition at line 141 of file featdefs.cpp.

141  {
142  int i;
143 
144  if (CharDesc) {
145  for (i = 0; i < CharDesc->NumFeatureSets; i++)
146  FreeFeatureSet (CharDesc->FeatureSets[i]);
147  Efree(CharDesc);
148  }
149 } /* FreeCharDescription */
FEATURE_SET FeatureSets[NUM_FEATURE_TYPES]
Definition: featdefs.h:44
void Efree(void *ptr)
Definition: emalloc.cpp:79
uinT32 NumFeatureSets
Definition: featdefs.h:43
void FreeFeatureSet(FEATURE_SET FeatureSet)
Definition: ocrfeatures.cpp:77

◆ InitFeatureDefs()

void TESS_API InitFeatureDefs ( FEATURE_DEFS_STRUCT featuredefs)

Definition at line 121 of file featdefs.cpp.

121  {
122  featuredefs->NumFeatureTypes = NUM_FEATURE_TYPES;
123  for (int i = 0; i < NUM_FEATURE_TYPES; ++i) {
124  featuredefs->FeatureDesc[i] = DescDefs[i];
125  }
126 }
const FEATURE_DESC_STRUCT * FeatureDesc[NUM_FEATURE_TYPES]
Definition: featdefs.h:50
inT32 NumFeatureTypes
Definition: featdefs.h:49
#define NUM_FEATURE_TYPES
Definition: featdefs.h:27

◆ NewCharDescription()

CHAR_DESC NewCharDescription ( const FEATURE_DEFS_STRUCT FeatureDefs)

Allocate a new character description, initialize its feature sets to be empty, and return it.

Globals:

  • none
Returns
New character description structure.
Note
Exceptions: none
History: Wed May 23 15:27:10 1990, DSJ, Created.

Definition at line 164 of file featdefs.cpp.

164  {
165  CHAR_DESC CharDesc;
166  int i;
167 
168  CharDesc = (CHAR_DESC) Emalloc (sizeof (CHAR_DESC_STRUCT));
169  CharDesc->NumFeatureSets = FeatureDefs.NumFeatureTypes;
170 
171  for (i = 0; i < CharDesc->NumFeatureSets; i++)
172  CharDesc->FeatureSets[i] = NULL;
173 
174  return (CharDesc);
175 
176 } /* NewCharDescription */
FEATURE_SET FeatureSets[NUM_FEATURE_TYPES]
Definition: featdefs.h:44
CHAR_DESC_STRUCT * CHAR_DESC
Definition: featdefs.h:46
uinT32 NumFeatureSets
Definition: featdefs.h:43
inT32 NumFeatureTypes
Definition: featdefs.h:49
void * Emalloc(int Size)
Definition: emalloc.cpp:47

◆ ReadCharDescription()

CHAR_DESC TESS_API ReadCharDescription ( const FEATURE_DEFS_STRUCT FeatureDefs,
FILE *  File 
)

Read a character description from File, and return a data structure containing this information. The data is formatted as follows:

  NumberOfSets
          ShortNameForSet1 Set1
          ShortNameForSet2 Set2
          ...

Globals:

  • none
Parameters
FeatureDefsdefinitions of feature types/extractors
Fileopen text file to read character description from
Returns
Character description read from File.
Note
Exceptions:
  • ILLEGAL_NUM_SETS
History: Wed May 23 17:32:48 1990, DSJ, Created.

Definition at line 263 of file featdefs.cpp.

264  {
265  int NumSetsToRead;
266  char ShortName[FEAT_NAME_SIZE];
267  CHAR_DESC CharDesc;
268  int Type;
269 
270  if (tfscanf(File, "%d", &NumSetsToRead) != 1 ||
271  NumSetsToRead < 0 || NumSetsToRead > FeatureDefs.NumFeatureTypes)
272  DoError (ILLEGAL_NUM_SETS, "Illegal number of feature sets");
273 
274  CharDesc = NewCharDescription(FeatureDefs);
275  for (; NumSetsToRead > 0; NumSetsToRead--) {
276  tfscanf(File, "%s", ShortName);
277  Type = ShortNameToFeatureType(FeatureDefs, ShortName);
278  CharDesc->FeatureSets[Type] =
279  ReadFeatureSet (File, FeatureDefs.FeatureDesc[Type]);
280  }
281  return (CharDesc);
282 
283 } // ReadCharDescription
int ShortNameToFeatureType(const FEATURE_DEFS_STRUCT &FeatureDefs, const char *ShortName)
Definition: featdefs.cpp:302
FEATURE_SET FeatureSets[NUM_FEATURE_TYPES]
Definition: featdefs.h:44
CHAR_DESC NewCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs)
Definition: featdefs.cpp:164
const FEATURE_DESC_STRUCT * FeatureDesc[NUM_FEATURE_TYPES]
Definition: featdefs.h:50
int tfscanf(FILE *stream, const char *format,...)
Definition: scanutils.cpp:228
#define ILLEGAL_NUM_SETS
Definition: featdefs.cpp:34
inT32 NumFeatureTypes
Definition: featdefs.h:49
void DoError(int Error, const char *Message)
Definition: danerror.cpp:42
#define FEAT_NAME_SIZE
Definition: ocrfeatures.h:33
FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc)

◆ ShortNameToFeatureType()

int TESS_API ShortNameToFeatureType ( const FEATURE_DEFS_STRUCT FeatureDefs,
const char *  ShortName 
)

Search through all features currently defined and return the feature type for the feature with the specified short name. Trap an error if the specified name is not found.

Globals:

  • none
Parameters
FeatureDefsdefinitions of feature types/extractors
ShortNameshort name of a feature type
Returns
Feature type which corresponds to ShortName.
Note
Exceptions:
  • ILLEGAL_SHORT_NAME
History: Wed May 23 15:36:05 1990, DSJ, Created.

Definition at line 302 of file featdefs.cpp.

303  {
304  int i;
305 
306  for (i = 0; i < FeatureDefs.NumFeatureTypes; i++)
307  if (!strcmp ((FeatureDefs.FeatureDesc[i]->ShortName), ShortName))
308  return (i);
309  DoError (ILLEGAL_SHORT_NAME, "Illegal short name for a feature");
310  return 0;
311 
312 } // ShortNameToFeatureType
const FEATURE_DESC_STRUCT * FeatureDesc[NUM_FEATURE_TYPES]
Definition: featdefs.h:50
inT32 NumFeatureTypes
Definition: featdefs.h:49
void DoError(int Error, const char *Message)
Definition: danerror.cpp:42
const char * ShortName
Definition: ocrfeatures.h:58
#define ILLEGAL_SHORT_NAME
Definition: featdefs.h:34

◆ ValidCharDescription()

bool ValidCharDescription ( const FEATURE_DEFS_STRUCT FeatureDefs,
CHAR_DESC  CharDesc 
)

Definition at line 219 of file featdefs.cpp.

220  {
221  bool anything_written = false;
222  bool well_formed = true;
223  for (int Type = 0; Type < CharDesc->NumFeatureSets; Type++) {
224  if (CharDesc->FeatureSets[Type]) {
225  for (int i = 0; i < CharDesc->FeatureSets[Type]->NumFeatures; i++) {
226  FEATURE feat = CharDesc->FeatureSets[Type]->Features[i];
227  for (int p = 0; p < feat->Type->NumParams; p++) {
228  if (isnan(feat->Params[p]) || isinf(feat->Params[p]))
229  well_formed = false;
230  else
231  anything_written = true;
232  }
233  }
234  } else {
235  return false;
236  }
237  }
238  return anything_written && well_formed;
239 } /* ValidCharDescription */
FEATURE_SET FeatureSets[NUM_FEATURE_TYPES]
Definition: featdefs.h:44
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
uinT32 NumFeatureSets
Definition: featdefs.h:43
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:64
FEATURE Features[1]
Definition: ocrfeatures.h:72

◆ WriteCharDescription()

void WriteCharDescription ( const FEATURE_DEFS_STRUCT FeatureDefs,
CHAR_DESC  CharDesc,
STRING str 
)

Appends a textual representation of CharDesc to str. The format used is to write out the number of feature sets which will be written followed by a representation of each feature set.

Each set starts with the short name for that feature followed by a description of the feature set. Feature sets which are not present are not written.

Parameters
FeatureDefsdefinitions of feature types/extractors
strstring to append CharDesc to
CharDesccharacter description to write to File
Note
Exceptions: none
History: Wed May 23 17:21:18 1990, DSJ, Created.

Definition at line 197 of file featdefs.cpp.

198  {
199  int Type;
200  int NumSetsToWrite = 0;
201 
202  for (Type = 0; Type < CharDesc->NumFeatureSets; Type++)
203  if (CharDesc->FeatureSets[Type])
204  NumSetsToWrite++;
205 
206  str->add_str_int(" ", NumSetsToWrite);
207  *str += "\n";
208  for (Type = 0; Type < CharDesc->NumFeatureSets; Type++) {
209  if (CharDesc->FeatureSets[Type]) {
210  *str += FeatureDefs.FeatureDesc[Type]->ShortName;
211  *str += " ";
212  WriteFeatureSet(CharDesc->FeatureSets[Type], str);
213  }
214  }
215 } /* WriteCharDescription */
FEATURE_SET FeatureSets[NUM_FEATURE_TYPES]
Definition: featdefs.h:44
const FEATURE_DESC_STRUCT * FeatureDesc[NUM_FEATURE_TYPES]
Definition: featdefs.h:50
void add_str_int(const char *str, int number)
Definition: strngs.cpp:384
uinT32 NumFeatureSets
Definition: featdefs.h:43
void WriteFeatureSet(FEATURE_SET FeatureSet, STRING *str)
const char * ShortName
Definition: ocrfeatures.h:58

Variable Documentation

◆ CharNormDesc

const FEATURE_DESC_STRUCT CharNormDesc

◆ GeoFeatDesc

const FEATURE_DESC_STRUCT GeoFeatDesc

◆ IntFeatDesc

const FEATURE_DESC_STRUCT IntFeatDesc

◆ kCNFeatureType

const char* kCNFeatureType

Definition at line 42 of file featdefs.cpp.

◆ kGeoFeatureType

const char* kGeoFeatureType

Definition at line 44 of file featdefs.cpp.

◆ kIntFeatureType

const char* kIntFeatureType

Definition at line 43 of file featdefs.cpp.

◆ kMicroFeatureType

const char* kMicroFeatureType

Definition at line 41 of file featdefs.cpp.

◆ MicroFeatureDesc

const FEATURE_DESC_STRUCT MicroFeatureDesc

Global Data Definitions and Declarations

◆ OutlineFeatDesc

const FEATURE_DESC_STRUCT OutlineFeatDesc

◆ PicoFeatDesc

TESS_API const FEATURE_DESC_STRUCT PicoFeatDesc