tesseract  3.05.02
ocrfeatures.h File Reference
#include "blobs.h"
#include <stdio.h>

Go to the source code of this file.

Classes

struct  PARAM_DESC
 
struct  FEATURE_DESC_STRUCT
 
struct  FEATURE_STRUCT
 
struct  FEATURE_SET_STRUCT
 

Macros

#define FEAT_NAME_SIZE   80
 
#define ILLEGAL_FEATURE_PARAM   1000
 
#define ILLEGAL_NUM_FEATURES   1001
 
#define StartParamDesc(Name)   const PARAM_DESC Name[] = {
 
#define DefineParam(Circular, NonEssential, Min, Max)
 
#define EndParamDesc   };
 
#define DefineFeature(Name, NL, NC, SN, PN)
 

Typedefs

typedef FEATURE_DESC_STRUCTFEATURE_DESC
 
typedef FEATURE_STRUCTFEATURE
 
typedef FEATURE_SET_STRUCTFEATURE_SET
 
typedef char * CHAR_FEATURES
 

Functions

BOOL8 AddFeature (FEATURE_SET FeatureSet, FEATURE Feature)
 
void FreeFeature (FEATURE Feature)
 
void TESS_API FreeFeatureSet (FEATURE_SET FeatureSet)
 
FEATURE NewFeature (const FEATURE_DESC_STRUCT *FeatureDesc)
 
FEATURE_SET NewFeatureSet (int NumFeatures)
 
FEATURE ReadFeature (FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc)
 
FEATURE_SET ReadFeatureSet (FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc)
 
void WriteFeature (FEATURE Feature, STRING *str)
 
void WriteFeatureSet (FEATURE_SET FeatureSet, STRING *str)
 

Macro Definition Documentation

◆ DefineFeature

#define DefineFeature (   Name,
  NL,
  NC,
  SN,
  PN 
)
Value:
const FEATURE_DESC_STRUCT Name = { \
((NL) + (NC)), SN, PN};

Definition at line 100 of file ocrfeatures.h.

◆ DefineParam

#define DefineParam (   Circular,
  NonEssential,
  Min,
  Max 
)
Value:
{Circular, NonEssential, Min, Max, \
(Max) - (Min), (((Max) - (Min))/2.0), (((Max) + (Min))/2.0)},

Definition at line 88 of file ocrfeatures.h.

◆ EndParamDesc

#define EndParamDesc   };

Definition at line 92 of file ocrfeatures.h.

◆ FEAT_NAME_SIZE

#define FEAT_NAME_SIZE   80

Definition at line 33 of file ocrfeatures.h.

◆ ILLEGAL_FEATURE_PARAM

#define ILLEGAL_FEATURE_PARAM   1000

Definition at line 36 of file ocrfeatures.h.

◆ ILLEGAL_NUM_FEATURES

#define ILLEGAL_NUM_FEATURES   1001

Definition at line 37 of file ocrfeatures.h.

◆ StartParamDesc

#define StartParamDesc (   Name)    const PARAM_DESC Name[] = {

Definition at line 85 of file ocrfeatures.h.

Typedef Documentation

◆ CHAR_FEATURES

typedef char* CHAR_FEATURES

Definition at line 80 of file ocrfeatures.h.

◆ FEATURE

Definition at line 67 of file ocrfeatures.h.

◆ FEATURE_DESC

Definition at line 61 of file ocrfeatures.h.

◆ FEATURE_SET

Definition at line 74 of file ocrfeatures.h.

Function Documentation

◆ AddFeature()

BOOL8 AddFeature ( FEATURE_SET  FeatureSet,
FEATURE  Feature 
)

Add a feature to a feature set. If the feature set is already full, FALSE is returned to indicate that the feature could not be added to the set; otherwise, TRUE is returned.

Parameters
FeatureSetset of features to add Feature to
Featurefeature to be added to FeatureSet
Returns
TRUE if feature added to set, FALSE if set is already full.
Note
History: Tue May 22 17:22:23 1990, DSJ, Created.

Definition at line 44 of file ocrfeatures.cpp.

44  {
45  if (FeatureSet->NumFeatures >= FeatureSet->MaxNumFeatures) {
46  FreeFeature(Feature);
47  return FALSE;
48  }
49 
50  FeatureSet->Features[FeatureSet->NumFeatures++] = Feature;
51  return TRUE;
52 } /* AddFeature */
#define TRUE
Definition: capi.h:45
void FreeFeature(FEATURE Feature)
Definition: ocrfeatures.cpp:60
#define FALSE
Definition: capi.h:46
FEATURE Features[1]
Definition: ocrfeatures.h:72

◆ FreeFeature()

void FreeFeature ( FEATURE  Feature)

Release the memory consumed by the specified feature.

Parameters
Featurefeature to be deallocated.
Returns
none
Note
History: Mon May 21 13:33:27 1990, DSJ, Created.

Definition at line 60 of file ocrfeatures.cpp.

60  {
61  if (Feature) {
62  free_struct (Feature, sizeof (FEATURE_STRUCT)
63  + sizeof (FLOAT32) * (Feature->Type->NumParams - 1),
64  "sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)");
65  }
66 
67 } /* FreeFeature */
void free_struct(void *deadstruct, inT32, const char *)
Definition: memry.cpp:43
float FLOAT32
Definition: host.h:44
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:64

◆ FreeFeatureSet()

void TESS_API FreeFeatureSet ( FEATURE_SET  FeatureSet)

Release the memory consumed by the specified feature set. This routine also frees the memory consumed by the features contained in the set.

Parameters
FeatureSetset of features to be freed
Returns
none
Note
History: Mon May 21 13:59:46 1990, DSJ, Created.

Definition at line 77 of file ocrfeatures.cpp.

77  {
78  int i;
79 
80  if (FeatureSet) {
81  for (i = 0; i < FeatureSet->NumFeatures; i++)
82  FreeFeature(FeatureSet->Features[i]);
83  memfree(FeatureSet);
84  }
85 } /* FreeFeatureSet */
void FreeFeature(FEATURE Feature)
Definition: ocrfeatures.cpp:60
void memfree(void *element)
Definition: freelist.cpp:30
FEATURE Features[1]
Definition: ocrfeatures.h:72

◆ NewFeature()

FEATURE NewFeature ( const FEATURE_DESC_STRUCT FeatureDesc)

Allocate and return a new feature of the specified type.

Parameters
FeatureDescdescription of feature to be created.
Returns
New FEATURE.
Note
History: Mon May 21 14:06:42 1990, DSJ, Created.

Definition at line 94 of file ocrfeatures.cpp.

94  {
95  FEATURE Feature;
96 
97  Feature = (FEATURE) alloc_struct (sizeof (FEATURE_STRUCT) +
98  (FeatureDesc->NumParams - 1) *
99  sizeof (FLOAT32),
100  "sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)");
101  Feature->Type = FeatureDesc;
102  return (Feature);
103 
104 } /* NewFeature */
FEATURE_STRUCT * FEATURE
Definition: ocrfeatures.h:67
float FLOAT32
Definition: host.h:44
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:64
void * alloc_struct(inT32 count, const char *)
Definition: memry.cpp:39

◆ NewFeatureSet()

FEATURE_SET NewFeatureSet ( int  NumFeatures)

Allocate and return a new feature set large enough to hold the specified number of features.

Parameters
NumFeaturesmaximum # of features to be put in feature set
Returns
New FEATURE_SET.
Note
History: Mon May 21 14:22:40 1990, DSJ, Created.

Definition at line 113 of file ocrfeatures.cpp.

113  {
114  FEATURE_SET FeatureSet;
115 
116  FeatureSet = (FEATURE_SET) Emalloc (sizeof (FEATURE_SET_STRUCT) +
117  (NumFeatures - 1) * sizeof (FEATURE));
118  FeatureSet->MaxNumFeatures = NumFeatures;
119  FeatureSet->NumFeatures = 0;
120  return (FeatureSet);
121 
122 } /* NewFeatureSet */
FEATURE_SET_STRUCT * FEATURE_SET
Definition: ocrfeatures.h:74
void * Emalloc(int Size)
Definition: emalloc.cpp:47

◆ ReadFeature()

FEATURE ReadFeature ( FILE *  File,
const FEATURE_DESC_STRUCT FeatureDesc 
)

Create a new feature of the specified type and read in the value of its parameters from File. The extra penalty for the feature is also computed by calling the appropriate function for the specified feature type. The correct text representation for a feature is a list of N floats where N is the number of parameters in the feature.

Parameters
Fileopen text file to read feature from
FeatureDescspecifies type of feature to read from File
Returns
New FEATURE read from File.
Note
Exceptions: ILLEGAL_FEATURE_PARAM if text file doesn't match expected format
History: Wed May 23 08:53:16 1990, DSJ, Created.

Definition at line 138 of file ocrfeatures.cpp.

138  {
139  FEATURE Feature;
140  int i;
141 
142  Feature = NewFeature (FeatureDesc);
143  for (i = 0; i < Feature->Type->NumParams; i++) {
144  if (tfscanf(File, "%f", &(Feature->Params[i])) != 1)
145  DoError (ILLEGAL_FEATURE_PARAM, "Illegal feature parameter spec");
146 #ifndef _WIN32
147  assert (!isnan(Feature->Params[i]));
148 #endif
149  }
150  return (Feature);
151 } /* ReadFeature */
int tfscanf(FILE *stream, const char *format,...)
Definition: scanutils.cpp:228
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
void DoError(int Error, const char *Message)
Definition: danerror.cpp:42
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:94
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:64
#define ILLEGAL_FEATURE_PARAM
Definition: ocrfeatures.h:36

◆ ReadFeatureSet()

FEATURE_SET ReadFeatureSet ( FILE *  File,
const FEATURE_DESC_STRUCT FeatureDesc 
)

Create a new feature set of the specified type and read in the features from File. The correct text representation for a feature set is an integer which specifies the number (N) of features in a set followed by a list of N feature descriptions.

Parameters
Fileopen text file to read new feature set from
FeatureDescspecifies type of feature to read from File
Returns
New feature set read from File.
Note
History: Wed May 23 09:17:31 1990, DSJ, Created.

Definition at line 164 of file ocrfeatures.cpp.

164  {
165  FEATURE_SET FeatureSet;
166  int NumFeatures;
167  int i;
168 
169  if (tfscanf(File, "%d", &NumFeatures) != 1 || NumFeatures < 0)
170  DoError(ILLEGAL_NUM_FEATURES, "Illegal number of features in set");
171 
172  FeatureSet = NewFeatureSet(NumFeatures);
173  for (i = 0; i < NumFeatures; i++)
174  AddFeature(FeatureSet, ReadFeature (File, FeatureDesc));
175 
176  return (FeatureSet);
177 } /* ReadFeatureSet */
int tfscanf(FILE *stream, const char *format,...)
Definition: scanutils.cpp:228
#define ILLEGAL_NUM_FEATURES
Definition: ocrfeatures.h:37
BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:44
void DoError(int Error, const char *Message)
Definition: danerror.cpp:42
FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc)
FEATURE_SET NewFeatureSet(int NumFeatures)

◆ WriteFeature()

void WriteFeature ( FEATURE  Feature,
STRING str 
)

Appends a textual representation of Feature to str. This representation is simply a list of the N parameters of the feature, terminated with a newline. It is assumed that the ExtraPenalty field can be reconstructed from the parameters of the feature. It is also assumed that the feature type information is specified or assumed elsewhere.

Parameters
Featurefeature to write out to str
strstring to write Feature to
Returns
none
Note
History: Wed May 23 09:28:18 1990, DSJ, Created.

Definition at line 191 of file ocrfeatures.cpp.

191  {
192  for (int i = 0; i < Feature->Type->NumParams; i++) {
193 #ifndef WIN32
194  assert(!isnan(Feature->Params[i]));
195 #endif
196  str->add_str_double(" ", Feature->Params[i]);
197  }
198  *str += "\n";
199 } /* WriteFeature */
void add_str_double(const char *str, double number)
Definition: strngs.cpp:394
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:64

◆ WriteFeatureSet()

void WriteFeatureSet ( FEATURE_SET  FeatureSet,
STRING str 
)

Write a textual representation of FeatureSet to File. This representation is an integer specifying the number of features in the set, followed by a newline, followed by text representations for each feature in the set.

Parameters
FeatureSetfeature set to write to File
strstring to write Feature to
Returns
none
Note
History: Wed May 23 10:06:03 1990, DSJ, Created.

Definition at line 211 of file ocrfeatures.cpp.

211  {
212  if (FeatureSet) {
213  str->add_str_int("", FeatureSet->NumFeatures);
214  *str += "\n";
215  for (int i = 0; i < FeatureSet->NumFeatures; i++) {
216  WriteFeature(FeatureSet->Features[i], str);
217  }
218  }
219 } /* WriteFeatureSet */
void WriteFeature(FEATURE Feature, STRING *str)
void add_str_int(const char *str, int number)
Definition: strngs.cpp:384
FEATURE Features[1]
Definition: ocrfeatures.h:72