Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions | Variables
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) EndParamDescDefineFeature(MicroFeatureDesc
MicroFeatureParams | StartParamDesc (CharNormParams) DefineParam(0
MicroFeatureParams | DefineParam (0, 1, 0.0, 1.0) DefineParam(0
MicroFeatureParams | DefineParam (0, 0, 0.0, 1.0) EndParamDescDefineFeature(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, 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 | of

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

MicroFeatureParams CharNormParams EndParamDesc DefineFeature | ( | IntFeatDesc | ,
|  | 2 | ,
|  | 1 | ,
|  | kIntFeatureType | ,
|  | IntFeatParams |
| ) |  |

MicroFeatureParams CharNormParams EndParamDesc EndParamDesc DefineFeature | ( | GeoFeatDesc | ,
|  | 3 | ,
|  | 0 | ,
|  | kGeoFeatureType | ,
|  | GeoFeatParams |
| ) |  |

EndParamDesc DefineFeature | ( | PicoFeatDesc | ,
|  | 2 | ,
|  | 1 | ,
|  | "pf" | ,
|  | PicoFeatParams |
| ) |  |

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

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

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

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

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

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

void FreeCharDescription | ( | CHAR_DESC | CharDesc | ) |

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

Parameters:

  CharDesc | character 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.

{
int i;
if (CharDesc) {
for (i = 0; i < CharDesc->NumFeatureSets; i++)
FreeFeatureSet (CharDesc->FeatureSets[i]);
Efree(CharDesc);
}
} /* FreeCharDescription */

void InitFeatureDefs | ( | FEATURE_DEFS_STRUCT * | featuredefs | ) |

Definition at line 121 of file featdefs.cpp.

{
featuredefs->NumFeatureTypes = NUM_FEATURE_TYPES;
for (int i = 0; i < NUM_FEATURE_TYPES; ++i) {
featuredefs->FeatureDesc[i] = DescDefs[i];
}
}

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.

{
CHAR_DESC CharDesc;
int i;
CharDesc = (CHAR_DESC) Emalloc (sizeof (CHAR_DESC_STRUCT));
CharDesc->NumFeatureSets = FeatureDefs.NumFeatureTypes;
for (i = 0; i < CharDesc->NumFeatureSets; i++)
CharDesc->FeatureSets[i] = NULL;
return (CharDesc);
} /* NewCharDescription */

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:

  FeatureDefs | definitions of feature types/extractors
  File | open 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.

{
int NumSetsToRead;
char ShortName[FEAT_NAME_SIZE];
CHAR_DESC CharDesc;
int Type;
if (fscanf (File, "%d", &NumSetsToRead) != 1 ||
NumSetsToRead < 0 || NumSetsToRead > FeatureDefs.NumFeatureTypes)
DoError (ILLEGAL_NUM_SETS, "Illegal number of feature sets");
CharDesc = NewCharDescription(FeatureDefs);
for (; NumSetsToRead > 0; NumSetsToRead--) {
fscanf (File, "%s", ShortName);
Type = ShortNameToFeatureType(FeatureDefs, ShortName);
CharDesc->FeatureSets[Type] =
ReadFeatureSet (File, FeatureDefs.FeatureDesc[Type]);
}
return (CharDesc);
} // ReadCharDescription

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:

  FeatureDefs | definitions of feature types/extractors
  ShortName | short 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.

{
int i;
for (i = 0; i < FeatureDefs.NumFeatureTypes; i++)
if (!strcmp ((FeatureDefs.FeatureDesc[i]->ShortName), ShortName))
return (i);
DoError (ILLEGAL_SHORT_NAME, "Illegal short name for a feature");
return 0;
} // ShortNameToFeatureType

StartParamDesc | ( | MicroFeatureParams |  | ) |

MicroFeatureParams StartParamDesc | ( | CharNormParams |  | ) |

MicroFeatureParams CharNormParams StartParamDesc | ( | IntFeatParams |  | ) |

StartParamDesc | ( | PicoFeatParams |  | ) |

bool ValidCharDescription | ( | const FEATURE_DEFS_STRUCT & | FeatureDefs,
|  | CHAR_DESC | CharDesc
| ) |  |

Definition at line 219 of file featdefs.cpp.

{
bool anything_written = false;
bool well_formed = true;
for (int Type = 0; Type < CharDesc->NumFeatureSets; Type++) {
if (CharDesc->FeatureSets[Type]) {
for (int i = 0; i < CharDesc->FeatureSets[Type]->NumFeatures; i++) {
FEATURE feat = CharDesc->FeatureSets[Type]->Features[i];
for (int p = 0; p < feat->Type->NumParams; p++) {
if (isnan(feat->Params[p]) || isinf(feat->Params[p]))
well_formed = false;
else
anything_written = true;
}
}
}
}
return anything_written && well_formed;
} /* ValidCharDescription */

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:

  FeatureDefs | definitions of feature types/extractors
  File | open text file to write CharDesc to
  CharDesc | character 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.

{
int Type;
int NumSetsToWrite = 0;
for (Type = 0; Type < CharDesc->NumFeatureSets; Type++)
if (CharDesc->FeatureSets[Type])
NumSetsToWrite++;
fprintf (File, " %d\n", NumSetsToWrite);
for (Type = 0; Type < CharDesc->NumFeatureSets; Type++)
if (CharDesc->FeatureSets[Type]) {
fprintf (File, "%s ", (FeatureDefs.FeatureDesc[Type])->ShortName);
WriteFeatureSet (File, CharDesc->FeatureSets[Type]);
}
} /* WriteCharDescription */

## Variable Documentation

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

kMicroFeatureType = "mf"

Definition at line 41 of file featdefs.cpp.

EndParamDesc of

Definition at line 108 of file featdefs.cpp.