tesseract  4.00.00dev
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

 StartParamDesc (MicroFeatureParams) DefineParam(0
 
 DefineParam (0, 0, -0.25, 0.75) DefineParam(0
 
 DefineParam (1, 0, 0.0, 1.0) DefineParam(0
 
 DefineParam (0, 1, -0.5, 0.5) EndParamDesc DefineFeature(MicroFeatureDesc
 
MicroFeatureParams StartParamDesc (CharNormParams) DefineParam(0
 
MicroFeatureParams DefineParam (0, 1, 0.0, 1.0) DefineParam(0
 
MicroFeatureParams DefineParam (0, 0, 0.0, 1.0) EndParamDesc DefineFeature(CharNormDesc
 
MicroFeatureParams CharNormParams StartParamDesc (IntFeatParams) DefineParam(0
 
MicroFeatureParams CharNormParams DefineParam (0, 0, 0.0, 255.0) DefineParam(1
 
MicroFeatureParams CharNormParams EndParamDesc DefineFeature (IntFeatDesc, 2, 1, kIntFeatureType, IntFeatParams) StartParamDesc(GeoFeatParams) DefineParam(0
 
MicroFeatureParams CharNormParams EndParamDesc EndParamDesc DefineFeature (GeoFeatDesc, 3, 0, kGeoFeatureType, GeoFeatParams) FLOAT32 PicoFeatureLength
 
 StartParamDesc (PicoFeatParams) DefineParam(0
 
EndParamDesc DefineFeature (PicoFeatDesc, 2, 1, "pf", PicoFeatParams) StartParamDesc(OutlineFeatParams) DefineParam(0
 
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, CHAR_DESC CharDesc, STRING *str)
 
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 of
 

Macro Definition Documentation

◆ ILLEGAL_NUM_SETS

#define ILLEGAL_NUM_SETS   3001

define errors triggered by this module

Definition at line 34 of file featdefs.cpp.

◆ PICO_FEATURE_LENGTH

#define PICO_FEATURE_LENGTH   0.05

Definition at line 36 of file featdefs.cpp.

Function Documentation

◆ DefineFeature() [1/3]

MicroFeatureParams CharNormParams EndParamDesc DefineFeature ( IntFeatDesc  ,
,
,
kIntFeatureType  ,
IntFeatParams   
)

◆ DefineFeature() [2/3]

MicroFeatureParams CharNormParams EndParamDesc EndParamDesc DefineFeature ( GeoFeatDesc  ,
,
,
kGeoFeatureType  ,
GeoFeatParams   
)

◆ DefineFeature() [3/3]

EndParamDesc DefineFeature ( PicoFeatDesc  ,
,
,
"pf"  ,
PicoFeatParams   
)

◆ DefineParam() [1/6]

EndParamDesc DefineParam ( ,
,
-0.  25,
0.  75 
)

◆ DefineParam() [2/6]

EndParamDesc DefineParam ( ,
,
0.  0,
1.  0 
)

◆ DefineParam() [3/6]

DefineParam ( ,
,
-0.  5,
0.  5 
)

◆ DefineParam() [4/6]

MicroFeatureParams DefineParam ( ,
,
0.  0,
1.  0 
)

◆ DefineParam() [5/6]

MicroFeatureParams DefineParam ( ,
,
0.  0,
1.  0 
)

◆ DefineParam() [6/6]

MicroFeatureParams CharNormParams EndParamDesc DefineParam ( ,
,
0.  0,
255.  0 
)

◆ 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  if (CharDesc) {
143  for (size_t i = 0; i < CharDesc->NumFeatureSets; i++)
144  FreeFeatureSet (CharDesc->FeatureSets[i]);
145  Efree(CharDesc);
146  }
147 } /* FreeCharDescription */
void FreeFeatureSet(FEATURE_SET FeatureSet)
Definition: ocrfeatures.cpp:71
FEATURE_SET FeatureSets[NUM_FEATURE_TYPES]
Definition: featdefs.h:44
uinT32 NumFeatureSets
Definition: featdefs.h:43
void Efree(void *ptr)
Definition: emalloc.cpp:79

◆ InitFeatureDefs()

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 }
#define NUM_FEATURE_TYPES
Definition: featdefs.h:27
const FEATURE_DESC_STRUCT * FeatureDesc[NUM_FEATURE_TYPES]
Definition: featdefs.h:50
inT32 NumFeatureTypes
Definition: featdefs.h:49

◆ 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 162 of file featdefs.cpp.

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

◆ ReadCharDescription()

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 258 of file featdefs.cpp.

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

◆ ShortNameToFeatureType()

int 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 297 of file featdefs.cpp.

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

◆ StartParamDesc() [1/4]

StartParamDesc ( MicroFeatureParams  )

◆ StartParamDesc() [2/4]

MicroFeatureParams StartParamDesc ( CharNormParams  )

◆ StartParamDesc() [3/4]

MicroFeatureParams CharNormParams StartParamDesc ( IntFeatParams  )

◆ StartParamDesc() [4/4]

StartParamDesc ( PicoFeatParams  )

◆ ValidCharDescription()

bool ValidCharDescription ( const FEATURE_DEFS_STRUCT FeatureDefs,
CHAR_DESC  CharDesc 
)

Definition at line 214 of file featdefs.cpp.

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

◆ 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 193 of file featdefs.cpp.

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

Variable Documentation

◆ kCNFeatureType

MicroFeatureParams kCNFeatureType = "cn"

Definition at line 42 of file featdefs.cpp.

◆ kGeoFeatureType

const char* kGeoFeatureType = "tb"

Definition at line 44 of file featdefs.cpp.

◆ kIntFeatureType

const char* kIntFeatureType = "if"

Definition at line 43 of file featdefs.cpp.

◆ kMicroFeatureType

kMicroFeatureType = "mf"

Definition at line 41 of file featdefs.cpp.

◆ of

Definition at line 108 of file featdefs.cpp.