Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
featdefs.cpp File Reference
#include "featdefs.h"
#include "emalloc.h"
#include "danerror.h"
#include "scanutils.h"
#include <string.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define ILLEGAL_NUM_SETS   3001
 
#define PICO_FEATURE_LENGTH   0.05
 

Functions

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

Variables

const char * kMicroFeatureType = "mf"
 
const char * kCNFeatureType = "cn"
 
const char * kIntFeatureType = "if"
 
const char * kGeoFeatureType = "tb"
 
EndParamDesc EndParamDesc
EndParamDesc EndParamDesc
FLOAT32 
PicoFeatureLength = PICO_FEATURE_LENGTH
 

Macro Definition Documentation

#define ILLEGAL_NUM_SETS   3001

define errors triggered by this module

Definition at line 34 of file featdefs.cpp.

#define PICO_FEATURE_LENGTH   0.05

Definition at line 36 of file featdefs.cpp.

Function Documentation

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 */
void Efree(void *ptr)
Definition: emalloc.cpp:85
void FreeFeatureSet(FEATURE_SET FeatureSet)
Definition: ocrfeatures.cpp:79
inT32 i
Definition: cluster.cpp:805
FEATURE_SET FeatureSets[NUM_FEATURE_TYPES]
Definition: featdefs.h:44
uinT32 NumFeatureSets
Definition: featdefs.h:43
void 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 }
inT32 i
Definition: cluster.cpp:805
const FEATURE_DESC_STRUCT * FeatureDesc[NUM_FEATURE_TYPES]
Definition: featdefs.h:50
uinT32 NumFeatureTypes
Definition: featdefs.h:49
#define NUM_FEATURE_TYPES
Definition: featdefs.h:27
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 */
#define NULL
Definition: host.h:144
inT32 i
Definition: cluster.cpp:805
CHAR_DESC_STRUCT * CHAR_DESC
Definition: featdefs.h:46
FEATURE_SET FeatureSets[NUM_FEATURE_TYPES]
Definition: featdefs.h:44
void * Emalloc(size_t Size)
Definition: emalloc.cpp:35
uinT32 NumFeatureTypes
Definition: featdefs.h:49
uinT32 NumFeatureSets
Definition: featdefs.h:43
CHAR_DESC 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 261 of file featdefs.cpp.

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

Search thru 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 300 of file featdefs.cpp.

301  {
302  int i;
303 
304  for (i = 0; i < FeatureDefs.NumFeatureTypes; i++)
305  if (!strcmp ((FeatureDefs.FeatureDesc[i]->ShortName), ShortName))
306  return (i);
307  DoError (ILLEGAL_SHORT_NAME, "Illegal short name for a feature");
308  return 0;
309 
310 } // ShortNameToFeatureType
void DoError(int Error, const char *Message)
Definition: danerror.cpp:32
inT32 i
Definition: cluster.cpp:805
const FEATURE_DESC_STRUCT * FeatureDesc[NUM_FEATURE_TYPES]
Definition: featdefs.h:50
uinT32 NumFeatureTypes
Definition: featdefs.h:49
const char * ShortName
Definition: ocrfeatures.h:57
#define ILLEGAL_SHORT_NAME
Definition: featdefs.h:34
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  }
235  }
236  return anything_written && well_formed;
237 } /* ValidCharDescription */
inT32 i
Definition: cluster.cpp:805
FEATURE Features[1]
Definition: ocrfeatures.h:71
FEATURE_SET FeatureSets[NUM_FEATURE_TYPES]
Definition: featdefs.h:44
FLOAT32 Params[1]
Definition: ocrfeatures.h:64
uinT32 NumFeatureSets
Definition: featdefs.h:43
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:63
void WriteCharDescription ( const FEATURE_DEFS_STRUCT FeatureDefs,
FILE *  File,
CHAR_DESC  CharDesc 
)

Write a textual representation of CharDesc to File. 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.

Globals:

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

Definition at line 200 of file featdefs.cpp.

201  {
202  int Type;
203  int NumSetsToWrite = 0;
204 
205  for (Type = 0; Type < CharDesc->NumFeatureSets; Type++)
206  if (CharDesc->FeatureSets[Type])
207  NumSetsToWrite++;
208 
209  fprintf (File, " %d\n", NumSetsToWrite);
210  for (Type = 0; Type < CharDesc->NumFeatureSets; Type++)
211  if (CharDesc->FeatureSets[Type]) {
212  fprintf (File, "%s ", (FeatureDefs.FeatureDesc[Type])->ShortName);
213  WriteFeatureSet (File, CharDesc->FeatureSets[Type]);
214  }
215 } /* WriteCharDescription */
void WriteFeatureSet(FILE *File, FEATURE_SET FeatureSet)
FEATURE_SET FeatureSets[NUM_FEATURE_TYPES]
Definition: featdefs.h:44
const FEATURE_DESC_STRUCT * FeatureDesc[NUM_FEATURE_TYPES]
Definition: featdefs.h:50
uinT32 NumFeatureSets
Definition: featdefs.h:43

Variable Documentation

const char* kCNFeatureType = "cn"

Definition at line 42 of file featdefs.cpp.

const char* kGeoFeatureType = "tb"

Definition at line 44 of file featdefs.cpp.

const char* kIntFeatureType = "if"

Definition at line 43 of file featdefs.cpp.

const char* kMicroFeatureType = "mf"

Definition at line 41 of file featdefs.cpp.


Global Data Definitions and Declarations

Definition at line 91 of file featdefs.cpp.