#include "ocrfeatures.h"
#include "emalloc.h"
#include "callcpp.h"
#include "danerror.h"
#include "freelist.h"
#include "scanutils.h"
Go to the source code of this file.
BOOL8 AddFeature | ( | FEATURE_SET | FeatureSet, | |
FEATURE | Feature | |||
) |
Add a feature to a feature set.
FeatureSet | Set of features to add Feature to | |
Feature | Feature to be added to FeatureSet |
Definition at line 47 of file ocrfeatures.cpp.
References FALSE, FeatureIn, FreeFeature(), MaxNumFeaturesIn, NumFeaturesIn, and TRUE.
Referenced by AddOutlineFeatureToSet(), ConvertSegmentToPicoFeat(), ExtractCharNormFeatures(), ExtractMicros(), and ReadFeatureSet().
00047 { 00048 if (NumFeaturesIn (FeatureSet) >= MaxNumFeaturesIn (FeatureSet)) { 00049 FreeFeature(Feature); 00050 return (FALSE); 00051 } 00052 00053 FeatureIn (FeatureSet, NumFeaturesIn (FeatureSet)) = Feature; 00054 NumFeaturesIn (FeatureSet)++; 00055 return (TRUE); 00056 00057 } /* AddFeature */
void DefaultInitFXVars | ( | ) |
Can be used by any feature extractor which does not use adjustable controls; it does nothing.
none |
Definition at line 70 of file ocrfeatures.cpp.
void FreeFeature | ( | FEATURE | Feature | ) |
Release the memory consumed by the specified feature.
Feature | Feature to be deallocated. |
Definition at line 83 of file ocrfeatures.cpp.
References c_free_struct(), and NumParamsIn.
Referenced by AddFeature(), CompareProtos(), FreeFeatureSet(), and GetIntCharNormFeatures().
00083 { 00084 if (Feature) { 00085 c_free_struct (Feature, sizeof (FEATURE_STRUCT) 00086 + sizeof (FLOAT32) * (NumParamsIn (Feature) - 1), 00087 "sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)"); 00088 } 00089 00090 } /* FreeFeature */
void FreeFeatureSet | ( | FEATURE_SET | FeatureSet | ) |
Release the memory consumed by the specified feature set; also frees the memory consumed by the features contained in the set.
FeatureSet | Set of features to be freed |
Definition at line 103 of file ocrfeatures.cpp.
References FeatureIn, FreeFeature(), memfree(), and NumFeaturesIn.
Referenced by AdaptToChar(), compare_tess_blobs(), FreeCharDescription(), FreeTrainingSamples(), GetAdaptiveFeatures(), GetBaselineFeatures(), MakeNewAdaptedClass(), and ReadTrainingSamples().
00103 { 00104 int i; 00105 00106 if (FeatureSet) { 00107 for (i = 0; i < NumFeaturesIn (FeatureSet); i++) 00108 FreeFeature (FeatureIn (FeatureSet, i)); 00109 memfree(FeatureSet); 00110 } 00111 } /* FreeFeatureSet */
FEATURE NewFeature | ( | FEATURE_DESC | FeatureDesc | ) |
Allocate and return a new feature of the specified type.
FeatureDesc | Description of feature to be created. |
Definition at line 123 of file ocrfeatures.cpp.
References c_alloc_struct(), fds::NumParams, and TypeOf.
Referenced by AddOutlineFeatureToSet(), CompareProtos(), ConvertSegmentToPicoFeat(), ConvertToMicroFeatures(), ExtractCharNormFeatures(), ExtractMicroFeature(), ExtractMicros(), GetIntCharNormFeatures(), and ReadFeature().
00123 { 00124 FEATURE Feature; 00125 00126 Feature = (FEATURE) c_alloc_struct (sizeof (FEATURE_STRUCT) + 00127 (FeatureDesc->NumParams - 1) * 00128 sizeof (FLOAT32), 00129 "sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)"); 00130 TypeOf (Feature) = FeatureDesc; 00131 return (Feature); 00132 00133 } /* NewFeature */
FEATURE_SET NewFeatureSet | ( | int | NumFeatures | ) |
Allocate and return a new feature set large enough to hold the specified number of features.
NumFeatures | Maximum number of features to be put in feature set |
Definition at line 146 of file ocrfeatures.cpp.
References Emalloc(), MaxNumFeaturesIn, and NumFeaturesIn.
Referenced by ExtractCharNormFeatures(), ExtractMicros(), ExtractOutlineFeatures(), ExtractPicoFeatures(), and ReadFeatureSet().
00146 { 00147 FEATURE_SET FeatureSet; 00148 00149 FeatureSet = (FEATURE_SET) Emalloc (sizeof (FEATURE_SET_STRUCT) + 00150 (NumFeatures - 1) * sizeof (FEATURE)); 00151 MaxNumFeaturesIn (FeatureSet) = NumFeatures; 00152 NumFeaturesIn (FeatureSet) = 0; 00153 return (FeatureSet); 00154 00155 } /* NewFeatureSet */
FEATURE ReadFeature | ( | FILE * | File, | |
FEATURE_DESC | FeatureDesc | |||
) |
Create a new feature of the specified type and read in the value of its parameters from File.
File | Open text file to read feature from | |
FeatureDesc | Specifies type of feature to read from File |
Definition at line 174 of file ocrfeatures.cpp.
References DoError(), fscanf(), ILLEGAL_FEATURE_PARAM, NewFeature(), NumParamsIn, and ParamOf.
Referenced by ReadFeatureSet().
00174 { 00175 FEATURE Feature; 00176 int i; 00177 00178 Feature = NewFeature (FeatureDesc); 00179 for (i = 0; i < NumParamsIn (Feature); i++) { 00180 if (fscanf (File, "%f", &(ParamOf (Feature, i))) != 1) 00181 DoError (ILLEGAL_FEATURE_PARAM, "Illegal feature parameter spec"); 00182 } 00183 return (Feature); 00184 00185 } /* ReadFeature */
FEATURE_SET ReadFeatureSet | ( | FILE * | File, | |
FEATURE_DESC | FeatureDesc | |||
) |
Create a new feature set of the specified type and read in the features from File.
File | Open text file to read new feature set from | |
FeatureDesc | Specifies type of feature to read from File |
Definition at line 203 of file ocrfeatures.cpp.
References AddFeature(), DoError(), fscanf(), ILLEGAL_NUM_FEATURES, NewFeatureSet(), and ReadFeature().
Referenced by ReadCharDescription().
00203 { 00204 FEATURE_SET FeatureSet; 00205 int NumFeatures; 00206 int i; 00207 00208 if (fscanf (File, "%d", &NumFeatures) != 1 || NumFeatures < 0) 00209 DoError (ILLEGAL_NUM_FEATURES, "Illegal number of features in set"); 00210 00211 FeatureSet = NewFeatureSet (NumFeatures); 00212 for (i = 0; i < NumFeatures; i++) 00213 AddFeature (FeatureSet, ReadFeature (File, FeatureDesc)); 00214 00215 return (FeatureSet); 00216 00217 } /* ReadFeatureSet */
void WriteFeature | ( | FILE * | File, | |
FEATURE | Feature | |||
) |
Write a textual representation of Feature to File.
File | Open text file to write Feature to | |
Feature | Feature to write out to File |
Definition at line 236 of file ocrfeatures.cpp.
References NumParamsIn, and ParamOf.
Referenced by ComputeNormMatch(), and WriteFeatureSet().
00236 { 00237 int i; 00238 00239 for (i = 0; i < NumParamsIn (Feature); i++) 00240 fprintf (File, " %12g", ParamOf (Feature, i)); 00241 fprintf (File, "\n"); 00242 00243 } /* WriteFeature */
void WriteFeatureSet | ( | FILE * | File, | |
FEATURE_SET | FeatureSet | |||
) |
Write a textual representation of FeatureSet to File.
File | Open text file to write FeatureSet to | |
FeatureSet | Feature set to write to File |
Definition at line 260 of file ocrfeatures.cpp.
References FeatureIn, NumFeaturesIn, and WriteFeature().
Referenced by WriteCharDescription(), and WriteTrainingSamples().
00260 { 00261 int i; 00262 00263 if (FeatureSet) { 00264 fprintf (File, "%d\n", NumFeaturesIn (FeatureSet)); 00265 for (i = 0; i < NumFeaturesIn (FeatureSet); i++) 00266 WriteFeature (File, FeatureIn (FeatureSet, i)); 00267 } 00268 } /* WriteFeatureSet */
void WriteOldParamDesc | ( | FILE * | File, | |
FEATURE_DESC | FeatureDesc | |||
) |
Write a textual representation of FeatureDesc to File in the old format; that used by the clusterer.
File | Open text file to write FeatureDesc to | |
FeatureDesc | Feature descriptor to write to File |
Number of Params Description of Param 1 ...
Definition at line 289 of file ocrfeatures.cpp.
References PARAM_DESC::Circular, PARAM_DESC::Max, PARAM_DESC::Min, PARAM_DESC::NonEssential, fds::NumParams, and fds::ParamDesc.
Referenced by WriteTrainingSamples().
00289 { 00290 int i; 00291 00292 fprintf (File, "%d\n", FeatureDesc->NumParams); 00293 for (i = 0; i < FeatureDesc->NumParams; i++) { 00294 if (FeatureDesc->ParamDesc[i].Circular) 00295 fprintf (File, "circular "); 00296 else 00297 fprintf (File, "linear "); 00298 00299 if (FeatureDesc->ParamDesc[i].NonEssential) 00300 fprintf (File, "non-essential "); 00301 else 00302 fprintf (File, "essential "); 00303 00304 fprintf (File, "%f %f\n", 00305 FeatureDesc->ParamDesc[i].Min, FeatureDesc->ParamDesc[i].Max); 00306 } 00307 } /* WriteOldParamDesc */