#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.
#define PICO_FEATURE_LENGTH 0.05 |
** (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.
void ConvertSegmentToPicoFeat | ( | FPOINT * | Start, | |
FPOINT * | End, | |||
FEATURE_SET | FeatureSet | |||
) |
Converts segment of outline into pico features & adds to FeatureSet.
Start | Starting point of pico-feature | |
End | Ending point of pico-feature | |
FeatureSet | Set to add pico-feature to |
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.
Outline | Outline to extract micro-features from | |
FeatureSet | Set of features to add pico-features to |
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.
Blob | Blob to extract pico-features from | |
LineStats | Statistics on text row blob is in |
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.
none |
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).
FeatureSet | Pico-features to be normalized |
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 */