classify/picofeat.cpp File Reference

#include "picofeat.h"
#include "mfoutline.h"
#include "variables.h"
#include "sigmenu.h"
#include "hideedge.h"
#include "fpoint.h"
#include <math.h>
#include "ocrfeatures.h"
#include <stdio.h>
#include "efio.h"

Go to the source code of this file.

Defines

Functions


Define Documentation

#define PICO_FEATURE_LENGTH   0.05

Note:
File: picofeat.cpp
Definition of pico-features.
Author:
Dan Johnson
Date:
9/4/90, DSJ, Created.
 **	(c) Copyright Hewlett-Packard Company, 1988.
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 ** http://www.apache.org/licenses/LICENSE-2.0
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.

Definition at line 36 of file picofeat.cpp.


Function Documentation

void ConvertSegmentToPicoFeat ( FPOINT Start,
FPOINT End,
FEATURE_SET  FeatureSet 
)

Converts segment of outline into pico features & adds to FeatureSet.

Parameters:
Start Starting point of pico-feature
End Ending point of pico-feature
FeatureSet Set to add pico-feature to
Note:
Globals: PicoFeatureLength Length of a single pico-feature
Returns:
none (results are placed in FeatureSet)
Converts an entire segment of an outline into a set of pico features which are added to FeatureSet. The length of the segment is rounded to the nearest whole number of pico-features. The pico-features are spaced evenly over the entire segment.

Note:
Exceptions: none
Date:
Tue Apr 30 15:44:34 1991, DSJ, Created.

Definition at line 184 of file picofeat.cpp.

References AddFeature(), DistanceBetween, NewFeature(), NormalizedAngleFrom(), ParamOf, PicoFeatDesc, PicoFeatDir, PicoFeatureLength, PicoFeatX, PicoFeatY, XDelta, Xof, YDelta, and Yof.

Referenced by ConvertToPicoFeatures2().

00186                                                       {
00187   FEATURE Feature;
00188   FLOAT32 Angle;
00189   FLOAT32 Length;
00190   int NumFeatures;
00191   FPOINT Center;
00192   FPOINT Delta;
00193   int i;
00194 
00195   Angle = NormalizedAngleFrom (Start, End, 1.0);
00196   Length = DistanceBetween (*Start, *End);
00197   NumFeatures = (int) floor (Length / PicoFeatureLength + 0.5);
00198   if (NumFeatures < 1)
00199     NumFeatures = 1;
00200 
00201   /* compute vector for one pico feature */
00202   Xof (Delta) = XDelta (*Start, *End) / NumFeatures;
00203   Yof (Delta) = YDelta (*Start, *End) / NumFeatures;
00204 
00205   /* compute position of first pico feature */
00206   Xof (Center) = Xof (*Start) + Xof (Delta) / 2.0;
00207   Yof (Center) = Yof (*Start) + Yof (Delta) / 2.0;
00208 
00209   /* compute each pico feature in segment and add to feature set */
00210   for (i = 0; i < NumFeatures; i++) {
00211     Feature = NewFeature (&PicoFeatDesc);
00212     ParamOf (Feature, PicoFeatDir) = Angle;
00213     ParamOf (Feature, PicoFeatX) = Xof (Center);
00214     ParamOf (Feature, PicoFeatY) = Yof (Center);
00215     AddFeature(FeatureSet, Feature); 
00216 
00217     Xof (Center) += Xof (Delta);
00218     Yof (Center) += Yof (Delta);
00219   }
00220 }                                /* ConvertSegmentToPicoFeat */

void ConvertToPicoFeatures2 ( MFOUTLINE  Outline,
FEATURE_SET  FeatureSet 
)

Steps thru the specified outline and cuts it up into pieces of equal length.

Parameters:
Outline Outline to extract micro-features from
FeatureSet Set of features to add pico-features to
Note:
Globals: PicoFeatureLength Length of features to be extracted
Returns:
none (results are returned in FeatureSet)
These pieces become the desired pico-features. Each segment in the outline is converted into an integral number of pico-features.

Note:
An edge is hidden if the ending point of the edge is marked as hidden. This situation happens because the order of the outlines is reversed when they are converted from the old format. In the old format, a hidden edge is marked by the starting point for that edge.
Date:
4/30/91, DSJ, Adapted from ConvertToPicoFeatures().

An edge is hidden if the ending point of the edge is marked as hidden. This situation happens because the order of the outlines is reversed when they are converted from the old format. In the old format, a hidden edge is marked by the starting point for that edge.

Definition at line 243 of file picofeat.cpp.

References ConvertSegmentToPicoFeat(), DegenerateOutline, IsVisible, NextPointAfter, PointAt, and PositionOf.

Referenced by ExtractPicoFeatures().

00243                                                                        { 
00244   MFOUTLINE Next;
00245   MFOUTLINE First;
00246   MFOUTLINE Current;
00247 
00248   if (DegenerateOutline (Outline))
00249     return;
00250 
00251   First = Outline;
00252   Current = First;
00253   Next = NextPointAfter (Current);
00254   do {
00260     if (IsVisible (PointAt (Next)))
00261       ConvertSegmentToPicoFeat (&(PositionOf (PointAt (Current))),
00262         &(PositionOf (PointAt (Next))), FeatureSet);
00263 
00264     Current = Next;
00265     Next = NextPointAfter (Current);
00266   }
00267   while (Current != First);
00268 
00269 }                                /* ConvertToPicoFeatures2 */

FEATURE_SET ExtractPicoFeatures ( TBLOB Blob,
LINE_STATS LineStats 
)

Dummy for now.

Parameters:
Blob Blob to extract pico-features from
LineStats Statistics on text row blob is in
Note:
Globals: NormMethod Normalization method currently specified
Returns:
Pico-features for Blob.
Note:
Exceptions: none
Date:
9/4/90, DSJ, Created.

Definition at line 89 of file picofeat.cpp.

References baseline, ConvertBlob(), ConvertToPicoFeatures2(), first, FreeOutlines(), iterate, MAX_PICO_FEATURES, NewFeatureSet(), NormalizeOutlines(), NormalizePicoX(), NormMethod, and Outline.

Referenced by GetAdaptiveFeatures(), and GetBaselineFeatures().

00089                                                                     { 
00090   LIST Outlines;
00091   LIST RemainingOutlines;
00092   MFOUTLINE Outline;
00093   FEATURE_SET FeatureSet;
00094   FLOAT32 XScale, YScale;
00095 
00096   FeatureSet = NewFeatureSet (MAX_PICO_FEATURES);
00097 
00098   Outlines = ConvertBlob (Blob);
00099 
00100   NormalizeOutlines(Outlines, LineStats, &XScale, &YScale); 
00101   RemainingOutlines = Outlines;
00102   iterate(RemainingOutlines) { 
00103     Outline = (MFOUTLINE) first (RemainingOutlines);
00104     /*---------Debug--------------------------------------------------*
00105     OFile = fopen ("f:/ims/debug/pfOutline.logCPP", "r");
00106     if (OFile == NULL)
00107     {
00108       OFile = Efopen ("f:/ims/debug/pfOutline.logCPP", "w");
00109       WriteOutline(OFile, Outline);
00110     }
00111     else
00112     {
00113       fclose (OFile);
00114       OFile = Efopen ("f:/ims/debug/pfOutline.logCPP", "a");
00115     }
00116     WriteOutline(OFile, Outline);
00117     fclose (OFile);
00118     *--------------------------------------------------------------------*/
00119     ConvertToPicoFeatures2(Outline, FeatureSet); 
00120   }
00121   if (NormMethod == baseline)
00122     NormalizePicoX(FeatureSet); 
00123   /*---------Debug--------------------------------------------------*
00124   File = fopen ("f:/ims/debug/pfFeatSet.logCPP", "r");
00125   if (File == NULL)
00126   {
00127     File = Efopen ("f:/ims/debug/pfFeatSet.logCPP", "w");
00128     WriteFeatureSet(File, FeatureSet);
00129   }
00130   else
00131   {
00132     fclose (File);
00133     File = Efopen ("f:/ims/debug/pfFeatSet.logCPP", "a");
00134   }
00135   WriteFeatureSet(File, FeatureSet);
00136   fclose (File);
00137   *--------------------------------------------------------------------*/
00138   FreeOutlines(Outlines); 
00139   return (FeatureSet);
00140 
00141 }                                /* ExtractPicoFeatures */

void InitPicoFXVars (  ) 

Initialize the pico-feature extractor variables that can be tuned without recompiling.

Parameters:
none 
Note:
Globals: PicoFeatureLength = Controls length of pico-features
Returns:
none
Note:
Exceptions: none
Date:
9/4/90, DSJ, Created.

Definition at line 155 of file picofeat.cpp.

References dummy, float_variable, PICO_FEATURE_LENGTH, and PicoFeatureLength.

Referenced by InitAdaptiveClassifierVars().

00155                       { 
00156 
00157    VALUE dummy;
00158    
00159    float_variable (PicoFeatureLength, "PicoFeatureLength",
00160       PICO_FEATURE_LENGTH);
00161    
00162 }  /* InitPicoFXVars */

void NormalizePicoX ( FEATURE_SET  FeatureSet  ) 

Computes the average x position over all of the pico-features in FeatureSet and then renormalizes the pico-features to force this average to be the x origin (ie x=0).

Parameters:
FeatureSet Pico-features to be normalized
Returns:
none (FeatureSet is changed)
Note:
Exceptions: none
Date:
Tue Sep 4 16:50:08 1990, DSJ, Created.

Definition at line 284 of file picofeat.cpp.

References FeatureIn, NumFeaturesIn, ParamOf, and PicoFeatX.

Referenced by ExtractPicoFeatures().

00284                                             { 
00285   int i;
00286   FEATURE Feature;
00287   FLOAT32 Origin = 0.0;
00288 
00289   for (i = 0; i < NumFeaturesIn (FeatureSet); i++) {
00290     Feature = FeatureIn (FeatureSet, i);
00291     Origin += ParamOf (Feature, PicoFeatX);
00292   }
00293   Origin /= NumFeaturesIn (FeatureSet);
00294 
00295   for (i = 0; i < NumFeaturesIn (FeatureSet); i++) {
00296     Feature = FeatureIn (FeatureSet, i);
00297     ParamOf (Feature, PicoFeatX) -= Origin;
00298   }
00299 }                                /* NormalizePicoX */


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