|
tesseract 3.04.01
|
#include "blobs.h"#include <stdio.h>Go to the source code of this file.
| #define DefineFeature | ( | Name, | |
| NL, | |||
| NC, | |||
| SN, | |||
| PN | |||
| ) |
const FEATURE_DESC_STRUCT Name = { \ ((NL) + (NC)), SN, PN};
Definition at line 100 of file ocrfeatures.h.
| #define DefineParam | ( | Circular, | |
| NonEssential, | |||
| Min, | |||
| Max | |||
| ) |
{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 char* CHAR_FEATURES |
Definition at line 80 of file ocrfeatures.h.
| typedef FEATURE_STRUCT* FEATURE |
Definition at line 67 of file ocrfeatures.h.
| typedef FEATURE_DESC_STRUCT* FEATURE_DESC |
Definition at line 61 of file ocrfeatures.h.
| typedef FEATURE_SET_STRUCT* FEATURE_SET |
Definition at line 74 of file ocrfeatures.h.
| 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.
| FeatureSet | set of features to add Feature to |
| Feature | feature to be added to FeatureSet |
Definition at line 44 of file ocrfeatures.cpp.
{
if (FeatureSet->NumFeatures >= FeatureSet->MaxNumFeatures) {
FreeFeature(Feature);
return FALSE;
}
FeatureSet->Features[FeatureSet->NumFeatures++] = Feature;
return TRUE;
} /* AddFeature */
| void FreeFeature | ( | FEATURE | Feature | ) |
Release the memory consumed by the specified feature.
| Feature | feature to be deallocated. |
Definition at line 60 of file ocrfeatures.cpp.
{
if (Feature) {
free_struct (Feature, sizeof (FEATURE_STRUCT)
+ sizeof (FLOAT32) * (Feature->Type->NumParams - 1),
"sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)");
}
} /* FreeFeature */
| void 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.
| FeatureSet | set of features to be freed |
Definition at line 78 of file ocrfeatures.cpp.
{
int i;
if (FeatureSet) {
for (i = 0; i < FeatureSet->NumFeatures; i++)
FreeFeature(FeatureSet->Features[i]);
memfree(FeatureSet);
}
} /* FreeFeatureSet */
| FEATURE NewFeature | ( | const FEATURE_DESC_STRUCT * | FeatureDesc | ) |
Allocate and return a new feature of the specified type.
| FeatureDesc | description of feature to be created. |
Definition at line 96 of file ocrfeatures.cpp.
{
FEATURE Feature;
Feature = (FEATURE) alloc_struct (sizeof (FEATURE_STRUCT) +
(FeatureDesc->NumParams - 1) *
sizeof (FLOAT32),
"sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)");
Feature->Type = FeatureDesc;
return (Feature);
} /* NewFeature */
| FEATURE_SET NewFeatureSet | ( | int | NumFeatures | ) |
Allocate and return a new feature set large enough to hold the specified number of features.
| NumFeatures | maximum # of features to be put in feature set |
Definition at line 116 of file ocrfeatures.cpp.
{
FEATURE_SET FeatureSet;
FeatureSet = (FEATURE_SET) Emalloc (sizeof (FEATURE_SET_STRUCT) +
(NumFeatures - 1) * sizeof (FEATURE));
FeatureSet->MaxNumFeatures = NumFeatures;
FeatureSet->NumFeatures = 0;
return (FeatureSet);
} /* NewFeatureSet */
| 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.
| File | open text file to read feature from |
| FeatureDesc | specifies type of feature to read from File |
Definition at line 141 of file ocrfeatures.cpp.
{
FEATURE Feature;
int i;
Feature = NewFeature (FeatureDesc);
for (i = 0; i < Feature->Type->NumParams; i++) {
if (tfscanf(File, "%f", &(Feature->Params[i])) != 1)
DoError (ILLEGAL_FEATURE_PARAM, "Illegal feature parameter spec");
#ifndef _WIN32
assert (!isnan(Feature->Params[i]));
#endif
}
return (Feature);
} /* ReadFeature */
| 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.
| File | open text file to read new feature set from |
| FeatureDesc | specifies type of feature to read from File |
Definition at line 168 of file ocrfeatures.cpp.
{
FEATURE_SET FeatureSet;
int NumFeatures;
int i;
if (tfscanf(File, "%d", &NumFeatures) != 1 || NumFeatures < 0)
DoError(ILLEGAL_NUM_FEATURES, "Illegal number of features in set");
FeatureSet = NewFeatureSet(NumFeatures);
for (i = 0; i < NumFeatures; i++)
AddFeature(FeatureSet, ReadFeature (File, FeatureDesc));
return (FeatureSet);
} /* ReadFeatureSet */
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.
| Feature | feature to write out to str |
| str | string to write Feature to |
Definition at line 196 of file ocrfeatures.cpp.
{
for (int i = 0; i < Feature->Type->NumParams; i++) {
#ifndef WIN32
assert(!isnan(Feature->Params[i]));
#endif
str->add_str_double(" ", Feature->Params[i]);
}
*str += "\n";
} /* WriteFeature */
| 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.
| FeatureSet | feature set to write to File |
| str | string to write Feature to |
Definition at line 217 of file ocrfeatures.cpp.
{
if (FeatureSet) {
str->add_str_int("", FeatureSet->NumFeatures);
*str += "\n";
for (int i = 0; i < FeatureSet->NumFeatures; i++) {
WriteFeature(FeatureSet->Features[i], str);
}
}
} /* WriteFeatureSet */