tesseract  3.04.00
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 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

#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.

#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.

#define EndParamDesc   };

Definition at line 92 of file ocrfeatures.h.

#define FEAT_NAME_SIZE   80

Definition at line 33 of file ocrfeatures.h.

#define ILLEGAL_FEATURE_PARAM   1000

Definition at line 36 of file ocrfeatures.h.

#define ILLEGAL_NUM_FEATURES   1001

Definition at line 37 of file ocrfeatures.h.

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

Definition at line 85 of file ocrfeatures.h.

Typedef Documentation

typedef char* CHAR_FEATURES

Definition at line 80 of file ocrfeatures.h.

Definition at line 67 of file ocrfeatures.h.

Definition at line 61 of file ocrfeatures.h.

Definition at line 74 of file ocrfeatures.h.

Function Documentation

BOOL8 AddFeature ( FEATURE_SET  FeatureSet,
FEATURE  Feature 
)

Include Files and Type Defines

Public Code

Definition at line 35 of file ocrfeatures.cpp.

35  {
36 /*
37  ** Parameters:
38  ** FeatureSet set of features to add Feature to
39  ** Feature feature to be added to FeatureSet
40  ** Globals: none
41  ** Operation: Add a feature to a feature set. If the feature set is
42  ** already full, FALSE is returned to indicate that the
43  ** feature could not be added to the set; otherwise, TRUE is
44  ** returned.
45  ** Return: TRUE if feature added to set, FALSE if set is already full.
46  ** Exceptions: none
47  ** History: Tue May 22 17:22:23 1990, DSJ, Created.
48  */
49  if (FeatureSet->NumFeatures >= FeatureSet->MaxNumFeatures) {
50  FreeFeature(Feature);
51  return FALSE;
52  }
53 
54  FeatureSet->Features[FeatureSet->NumFeatures++] = Feature;
55  return TRUE;
56 } /* AddFeature */
FEATURE Features[1]
Definition: ocrfeatures.h:72
#define FALSE
Definition: capi.h:29
#define TRUE
Definition: capi.h:28
void FreeFeature(FEATURE Feature)
Definition: ocrfeatures.cpp:59
void FreeFeature ( FEATURE  Feature)

Definition at line 59 of file ocrfeatures.cpp.

59  {
60 /*
61  ** Parameters:
62  ** Feature feature to be deallocated.
63  ** Globals: none
64  ** Operation: Release the memory consumed by the specified feature.
65  ** Return: none
66  ** Exceptions: none
67  ** History: Mon May 21 13:33:27 1990, DSJ, Created.
68  */
69  if (Feature) {
70  free_struct (Feature, sizeof (FEATURE_STRUCT)
71  + sizeof (FLOAT32) * (Feature->Type->NumParams - 1),
72  "sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)");
73  }
74 
75 } /* FreeFeature */
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:64
void free_struct(void *deadstruct, inT32, const char *)
Definition: memry.cpp:43
float FLOAT32
Definition: host.h:111
void FreeFeatureSet ( FEATURE_SET  FeatureSet)

Definition at line 79 of file ocrfeatures.cpp.

79  {
80 /*
81  ** Parameters:
82  ** FeatureSet set of features to be freed
83  ** Globals: none
84  ** Operation: Release the memory consumed by the specified feature
85  ** set. This routine also frees the memory consumed by the
86  ** features contained in the set.
87  ** Return: none
88  ** Exceptions: none
89  ** History: Mon May 21 13:59:46 1990, DSJ, Created.
90  */
91  int i;
92 
93  if (FeatureSet) {
94  for (i = 0; i < FeatureSet->NumFeatures; i++)
95  FreeFeature(FeatureSet->Features[i]);
96  memfree(FeatureSet);
97  }
98 } /* FreeFeatureSet */
FEATURE Features[1]
Definition: ocrfeatures.h:72
void memfree(void *element)
Definition: freelist.cpp:30
void FreeFeature(FEATURE Feature)
Definition: ocrfeatures.cpp:59
FEATURE NewFeature ( const FEATURE_DESC_STRUCT FeatureDesc)

Definition at line 102 of file ocrfeatures.cpp.

102  {
103 /*
104  ** Parameters:
105  ** FeatureDesc description of feature to be created.
106  ** Globals: none
107  ** Operation: Allocate and return a new feature of the specified
108  ** type.
109  ** Return: New feature.
110  ** Exceptions: none
111  ** History: Mon May 21 14:06:42 1990, DSJ, Created.
112  */
113  FEATURE Feature;
114 
115  Feature = (FEATURE) alloc_struct (sizeof (FEATURE_STRUCT) +
116  (FeatureDesc->NumParams - 1) *
117  sizeof (FLOAT32),
118  "sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)");
119  Feature->Type = FeatureDesc;
120  return (Feature);
121 
122 } /* NewFeature */
FEATURE_STRUCT * FEATURE
Definition: ocrfeatures.h:67
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:64
void * alloc_struct(inT32 count, const char *)
Definition: memry.cpp:39
float FLOAT32
Definition: host.h:111
FEATURE_SET NewFeatureSet ( int  NumFeatures)

Definition at line 126 of file ocrfeatures.cpp.

126  {
127 /*
128  ** Parameters:
129  ** NumFeatures maximum # of features to be put in feature set
130  ** Globals: none
131  ** Operation: Allocate and return a new feature set large enough to
132  ** hold the specified number of features.
133  ** Return: New feature set.
134  ** Exceptions: none
135  ** History: Mon May 21 14:22:40 1990, DSJ, Created.
136  */
137  FEATURE_SET FeatureSet;
138 
139  FeatureSet = (FEATURE_SET) Emalloc (sizeof (FEATURE_SET_STRUCT) +
140  (NumFeatures - 1) * sizeof (FEATURE));
141  FeatureSet->MaxNumFeatures = NumFeatures;
142  FeatureSet->NumFeatures = 0;
143  return (FeatureSet);
144 
145 } /* NewFeatureSet */
FEATURE_SET_STRUCT * FEATURE_SET
Definition: ocrfeatures.h:74
void * Emalloc(int Size)
Definition: emalloc.cpp:35
FEATURE ReadFeature ( FILE *  File,
const FEATURE_DESC_STRUCT FeatureDesc 
)

Definition at line 149 of file ocrfeatures.cpp.

149  {
150 /*
151  ** Parameters:
152  ** File open text file to read feature from
153  ** FeatureDesc specifies type of feature to read from File
154  ** Globals: none
155  ** Operation: Create a new feature of the specified type and read in
156  ** the value of its parameters from File. The extra penalty
157  ** for the feature is also computed by calling the appropriate
158  ** function for the specified feature type. The correct text
159  ** representation for a feature is a list of N floats where
160  ** N is the number of parameters in the feature.
161  ** Return: New feature read from File.
162  ** Exceptions: ILLEGAL_FEATURE_PARAM if text file doesn't match expected format
163  ** History: Wed May 23 08:53:16 1990, DSJ, Created.
164  */
165  FEATURE Feature;
166  int i;
167 
168  Feature = NewFeature (FeatureDesc);
169  for (i = 0; i < Feature->Type->NumParams; i++) {
170  if (tfscanf(File, "%f", &(Feature->Params[i])) != 1)
171  DoError (ILLEGAL_FEATURE_PARAM, "Illegal feature parameter spec");
172 #ifndef _WIN32
173  assert (!isnan(Feature->Params[i]));
174 #endif
175  }
176  return (Feature);
177 } /* ReadFeature */
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:64
#define ILLEGAL_FEATURE_PARAM
Definition: ocrfeatures.h:36
#define isnan(x)
Definition: mathfix.h:31
void DoError(int Error, const char *Message)
Definition: danerror.cpp:32
int tfscanf(FILE *stream, const char *format,...)
Definition: scanutils.cpp:229
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
FEATURE_SET ReadFeatureSet ( FILE *  File,
const FEATURE_DESC_STRUCT FeatureDesc 
)

Definition at line 181 of file ocrfeatures.cpp.

181  {
182 /*
183  ** Parameters:
184  ** File open text file to read new feature set from
185  ** FeatureDesc specifies type of feature to read from File
186  ** Globals: none
187  ** Operation: Create a new feature set of the specified type and read in
188  ** the features from File. The correct text representation
189  ** for a feature set is an integer which specifies the number (N)
190  ** of features in a set followed by a list of N feature
191  ** descriptions.
192  ** Return: New feature set read from File.
193  ** Exceptions: none
194  ** History: Wed May 23 09:17:31 1990, DSJ, Created.
195  */
196  FEATURE_SET FeatureSet;
197  int NumFeatures;
198  int i;
199 
200  if (tfscanf(File, "%d", &NumFeatures) != 1 || NumFeatures < 0)
201  DoError(ILLEGAL_NUM_FEATURES, "Illegal number of features in set");
202 
203  FeatureSet = NewFeatureSet(NumFeatures);
204  for (i = 0; i < NumFeatures; i++)
205  AddFeature(FeatureSet, ReadFeature (File, FeatureDesc));
206 
207  return (FeatureSet);
208 } /* ReadFeatureSet */
BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:35
void DoError(int Error, const char *Message)
Definition: danerror.cpp:32
#define ILLEGAL_NUM_FEATURES
Definition: ocrfeatures.h:37
FEATURE_SET NewFeatureSet(int NumFeatures)
int tfscanf(FILE *stream, const char *format,...)
Definition: scanutils.cpp:229
FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc)
void WriteFeature ( FEATURE  Feature,
STRING str 
)

Definition at line 226 of file ocrfeatures.cpp.

226  {
227  for (int i = 0; i < Feature->Type->NumParams; i++) {
228 #ifndef WIN32
229  assert(!isnan(Feature->Params[i]));
230 #endif
231  str->add_str_double(" ", Feature->Params[i]);
232  }
233  *str += "\n";
234 } /* WriteFeature */
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:64
void add_str_double(const char *str, double number)
Definition: strngs.cpp:386
#define isnan(x)
Definition: mathfix.h:31
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
void WriteFeatureSet ( FEATURE_SET  FeatureSet,
STRING str 
)

Definition at line 251 of file ocrfeatures.cpp.

251  {
252  if (FeatureSet) {
253  str->add_str_int("", FeatureSet->NumFeatures);
254  *str += "\n";
255  for (int i = 0; i < FeatureSet->NumFeatures; i++) {
256  WriteFeature(FeatureSet->Features[i], str);
257  }
258  }
259 } /* WriteFeatureSet */
FEATURE Features[1]
Definition: ocrfeatures.h:72
void WriteFeature(FEATURE Feature, STRING *str)
void add_str_int(const char *str, int number)
Definition: strngs.cpp:376