classify/ocrfeatures.cpp File Reference

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

Functions


Function Documentation

BOOL8 AddFeature ( FEATURE_SET  FeatureSet,
FEATURE  Feature 
)

Add a feature to a feature set.

Parameters:
FeatureSet Set of features to add Feature to
Feature Feature to be added to FeatureSet
Returns:
TRUE if feature added to 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.
Note:
Exceptions: none
Date:
Tue May 22 17:22:23 1990, DSJ, Created.

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.

Parameters:
none 
Returns:
none
Note:
Exceptions: none
Date:
Wed May 23 16:37:45 1990, DSJ, Created.

Definition at line 70 of file ocrfeatures.cpp.

00070                          { 
00071 }                                /* DefaultInitFXVars */

void FreeFeature ( FEATURE  Feature  ) 

Release the memory consumed by the specified feature.

Parameters:
Feature Feature to be deallocated.
Returns:
none
Note:
Exceptions: none
Date:
Mon May 21 13:33:27 1990, DSJ, Created.

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.

Parameters:
FeatureSet Set of features to be freed
Returns:
none
Note:
Exceptions: none
Date:
Mon May 21 13:59:46 1990, DSJ, Created.

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.

Parameters:
FeatureDesc Description of feature to be created.
Returns:
New feature.
Note:
Exceptions: none
Date:
Mon May 21 14:06:42 1990, DSJ, 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.

Parameters:
NumFeatures Maximum number of features to be put in feature set
Returns:
New feature set.
Note:
Exceptions: none
Date:
Mon May 21 14:22:40 1990, DSJ, Created.

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.

Parameters:
File Open text file to read feature from
FeatureDesc Specifies type of feature to read from File
Returns:
New feature read 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.
Note:
Exceptions: ILLEGAL_FEATURE_PARAM if text file doesn't match expected format
Date:
Wed May 23 08:53:16 1990, DSJ, Created.

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.

Parameters:
File Open text file to read new feature set from
FeatureDesc Specifies type of feature to read from File
Returns:
New feature set read 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.
Note:
Exceptions: none
Date:
Wed May 23 09:17:31 1990, DSJ, Created.

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.

Parameters:
File Open text file to write Feature to
Feature Feature to write out to File
Returns:
none
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.
Note:
Exceptions: none
Date:
Wed May 23 09:28:18 1990, DSJ, Created.

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.

Parameters:
File Open text file to write FeatureSet to
FeatureSet Feature set to write to File
Returns:
none
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.
Note:
Exceptions: none
Date:
Wed May 23 10:06:03 1990, DSJ, Created.

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.

Parameters:
File Open text file to write FeatureDesc to
FeatureDesc Feature descriptor to write to File
Returns:
none
This format is:
   Number of Params
   Description of Param 1
   ...
Note:
Exceptions: none
Date:
Fri May 25 15:27:18 1990, DSJ, Created.

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 */


Generated on Wed Feb 28 19:49:21 2007 for Tesseract by  doxygen 1.5.1