FEATURE_SET Classify::ExtractPicoFeatures(TBLOB *Blob) { /* ** Parameters: ** Blob blob to extract pico-features from ** LineStats statistics on text row blob is in ** Globals: ** classify_norm_method normalization method currently specified ** Operation: Dummy for now. ** Return: Pico-features for Blob. ** Exceptions: none ** History: 9/4/90, DSJ, Created. */ LIST Outlines; LIST RemainingOutlines; MFOUTLINE Outline; FEATURE_SET FeatureSet; FLOAT32 XScale, YScale; FeatureSet = NewFeatureSet(MAX_PICO_FEATURES); Outlines = ConvertBlob(Blob); NormalizeOutlines(Outlines, &XScale, &YScale); RemainingOutlines = Outlines; iterate(RemainingOutlines) { Outline = (MFOUTLINE) first_node (RemainingOutlines); ConvertToPicoFeatures2(Outline, FeatureSet); } if (classify_norm_method == baseline) NormalizePicoX(FeatureSet); FreeOutlines(Outlines); return (FeatureSet); } /* ExtractPicoFeatures */
/*---------------------------------------------------------------------------*/ FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT* FeatureDesc) { /* ** Parameters: ** File open text file to read new feature set from ** FeatureDesc specifies type of feature to read from File ** Globals: none ** Operation: 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. ** Return: New feature set read from File. ** Exceptions: none ** History: Wed May 23 09:17:31 1990, DSJ, Created. */ FEATURE_SET FeatureSet; int NumFeatures; int i; if (fscanf (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 */
/** * 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. * @param File open text file to read new feature set from * @param FeatureDesc specifies type of feature to read from File * @return New feature set read from File. */ FEATURE_SET ReadFeatureSet(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) { int NumFeatures; ASSERT_HOST(tfscanf(File, "%d", &NumFeatures) == 1); ASSERT_HOST(NumFeatures >= 0); FEATURE_SET FeatureSet = NewFeatureSet(NumFeatures); for (int i = 0; i < NumFeatures; i++) AddFeature(FeatureSet, ReadFeature (File, FeatureDesc)); return FeatureSet; }
/*---------------------------------------------------------------------------*/ FEATURE_SET ExtractMicros(TBLOB* Blob, const DENORM& cn_denorm) { /* ** Parameters: ** Blob blob to extract micro-features from ** denorm control parameter to feature extractor. ** Globals: none ** Operation: Call the old micro-feature extractor and then copy ** the features into the new format. Then deallocate the ** old micro-features. ** Return: Micro-features for Blob. ** Exceptions: none ** History: Wed May 23 18:06:38 1990, DSJ, Created. */ int NumFeatures; MICROFEATURES Features, OldFeatures; FEATURE_SET FeatureSet; FEATURE Feature; MICROFEATURE OldFeature; OldFeatures = BlobMicroFeatures(Blob, cn_denorm); if (OldFeatures == NULL) return NULL; NumFeatures = count (OldFeatures); FeatureSet = NewFeatureSet (NumFeatures); Features = OldFeatures; iterate(Features) { OldFeature = (MICROFEATURE) first_node (Features); Feature = NewFeature (&MicroFeatureDesc); Feature->Params[MFDirection] = OldFeature[ORIENTATION]; Feature->Params[MFXPosition] = OldFeature[XPOSITION]; Feature->Params[MFYPosition] = OldFeature[YPOSITION]; Feature->Params[MFLength] = OldFeature[MFLENGTH]; // Bulge features are deprecated and should not be used. Set to 0. Feature->Params[MFBulge1] = 0.0f; Feature->Params[MFBulge2] = 0.0f; #ifndef _WIN32 // Assert that feature parameters are well defined. int i; for (i = 0; i < Feature->Type->NumParams; i++) { ASSERT_HOST(!isnan(Feature->Params[i])); } #endif AddFeature(FeatureSet, Feature); } FreeMicroFeatures(OldFeatures); return FeatureSet; } /* ExtractMicros */
/** * Operation: Dummy for now. * * Globals: * - classify_norm_method normalization method currently specified * @param Blob blob to extract pico-features from * @return Pico-features for Blob. * @note Exceptions: none * @note History: 9/4/90, DSJ, Created. */ FEATURE_SET Classify::ExtractPicoFeatures(TBLOB * Blob) { LIST Outlines; LIST RemainingOutlines; MFOUTLINE Outline; FEATURE_SET FeatureSet; FLOAT32 XScale, YScale; FeatureSet = NewFeatureSet(MAX_PICO_FEATURES); Outlines = ConvertBlob(Blob); NormalizeOutlines(Outlines, &XScale, &YScale); RemainingOutlines = Outlines; iterate(RemainingOutlines) { Outline = (MFOUTLINE) first_node(RemainingOutlines); ConvertToPicoFeatures2(Outline, FeatureSet); } if (classify_norm_method == baseline) NormalizePicoX(FeatureSet); FreeOutlines(Outlines); return (FeatureSet); } /* ExtractPicoFeatures */
FEATURE_SET Classify::ExtractOutlineFeatures(TBLOB *Blob) { /* ** Parameters: ** Blob blob to extract pico-features from ** LineStats statistics on text row blob is in ** Globals: none ** Operation: Convert each segment in the outline to a feature ** and return the features. ** Return: Outline-features for Blob. ** Exceptions: none ** History: 11/13/90, DSJ, Created. ** 05/24/91, DSJ, Updated for either char or baseline normalize. */ LIST Outlines; LIST RemainingOutlines; MFOUTLINE Outline; FEATURE_SET FeatureSet; FLOAT32 XScale, YScale; FeatureSet = NewFeatureSet (MAX_OUTLINE_FEATURES); if (Blob == NULL) return (FeatureSet); Outlines = ConvertBlob (Blob); NormalizeOutlines(Outlines, &XScale, &YScale); RemainingOutlines = Outlines; iterate(RemainingOutlines) { Outline = (MFOUTLINE) first_node (RemainingOutlines); ConvertToOutlineFeatures(Outline, FeatureSet); } if (classify_norm_method == baseline) NormalizeOutlineX(FeatureSet); FreeOutlines(Outlines); return (FeatureSet); } /* ExtractOutlineFeatures */
/*---------------------------------------------------------------------------*/ FEATURE_SET ExtractCharNormFeatures(TBLOB *Blob, LINE_STATS *LineStats) { /* ** Parameters: ** Blob blob to extract char norm feature from ** LineStats statistics on text row blob is in ** Globals: none ** Operation: Compute a feature whose parameters describe how a ** character will be affected by the character normalization ** algorithm. The feature parameters are: ** y position of center of mass in baseline coordinates ** total length of outlines in baseline coordinates ** divided by a scale factor ** radii of gyration about the center of mass in ** baseline coordinates ** Return: Character normalization feature for Blob. ** Exceptions: none ** History: Wed May 23 18:06:38 1990, DSJ, Created. */ FEATURE_SET FeatureSet; FEATURE Feature; FLOAT32 Scale; FLOAT32 Baseline; LIST Outlines; INT_FEATURE_ARRAY blfeatures; INT_FEATURE_ARRAY cnfeatures; INT_FX_RESULT_STRUCT FXInfo; /* allocate the feature and feature set - note that there is always one and only one char normalization feature for any blob */ FeatureSet = NewFeatureSet (1); Feature = NewFeature (&CharNormDesc); AddFeature(FeatureSet, Feature); /* compute the normalization statistics for this blob */ Outlines = ConvertBlob (Blob); /*---------Debug--------------------------------------------------* OFile = fopen ("f:/ims/debug/nfOutline.logCPP", "r"); if (OFile == NULL) { OFile = Efopen ("f:/ims/debug/nfOutline.logCPP", "w"); WriteOutlines(OFile, Outlines); } else { fclose (OFile); OFile = Efopen ("f:/ims/debug/nfOutline.logCPP", "a"); } WriteOutlines(OFile, Outlines); fclose (OFile); *--------------------------------------------------------------------*/ ExtractIntFeat(Blob, blfeatures, cnfeatures, &FXInfo); Baseline = BaselineAt (LineStats, FXInfo.Xmean); Scale = ComputeScaleFactor (LineStats); Feature->Params[CharNormY] = (FXInfo.Ymean - Baseline) * Scale; Feature->Params[CharNormLength] = FXInfo.Length * Scale / LENGTH_COMPRESSION; Feature->Params[CharNormRx] = FXInfo.Rx * Scale; Feature->Params[CharNormRy] = FXInfo.Ry * Scale; /*---------Debug--------------------------------------------------* File = fopen ("f:/ims/debug/nfFeatSet.logCPP", "r"); if (File == NULL) { File = Efopen ("f:/ims/debug/nfFeatSet.logCPP", "w"); WriteFeatureSet(File, FeatureSet); } else { fclose (File); File = Efopen ("f:/ims/debug/nfFeatSet.logCPP", "a"); } WriteFeatureSet(File, FeatureSet); fclose (File); *--------------------------------------------------------------------*/ FreeOutlines(Outlines); return (FeatureSet); } /* ExtractCharNormFeatures */
/*---------------------------------------------------------------------------*/ FEATURE_SET ExtractPicoFeatures(TBLOB *Blob, LINE_STATS *LineStats) { /* ** Parameters: ** Blob blob to extract pico-features from ** LineStats statistics on text row blob is in ** Globals: ** classify_norm_method normalization method currently specified ** Operation: Dummy for now. ** Return: Pico-features for Blob. ** Exceptions: none ** History: 9/4/90, DSJ, Created. */ LIST Outlines; LIST RemainingOutlines; MFOUTLINE Outline; FEATURE_SET FeatureSet; FLOAT32 XScale, YScale; FeatureSet = NewFeatureSet (MAX_PICO_FEATURES); Outlines = ConvertBlob (Blob); NormalizeOutlines(Outlines, LineStats, &XScale, &YScale); RemainingOutlines = Outlines; iterate(RemainingOutlines) { Outline = (MFOUTLINE) first_node (RemainingOutlines); /*---------Debug--------------------------------------------------* OFile = fopen ("f:/ims/debug/pfOutline.logCPP", "r"); if (OFile == NULL) { OFile = Efopen ("f:/ims/debug/pfOutline.logCPP", "w"); WriteOutline(OFile, Outline); } else { fclose (OFile); OFile = Efopen ("f:/ims/debug/pfOutline.logCPP", "a"); } WriteOutline(OFile, Outline); fclose (OFile); *--------------------------------------------------------------------*/ ConvertToPicoFeatures2(Outline, FeatureSet); } if (classify_norm_method == baseline) NormalizePicoX(FeatureSet); /*---------Debug--------------------------------------------------* File = fopen ("f:/ims/debug/pfFeatSet.logCPP", "r"); if (File == NULL) { File = Efopen ("f:/ims/debug/pfFeatSet.logCPP", "w"); WriteFeatureSet(File, FeatureSet); } else { fclose (File); File = Efopen ("f:/ims/debug/pfFeatSet.logCPP", "a"); } WriteFeatureSet(File, FeatureSet); fclose (File); *--------------------------------------------------------------------*/ FreeOutlines(Outlines); return (FeatureSet); } /* ExtractPicoFeatures */