00001
00019
00020
00021
00022 #include "picofeat.h"
00023 #include "mfoutline.h"
00024 #include "variables.h"
00025 #include "sigmenu.h"
00026 #include "hideedge.h"
00027 #include "fpoint.h"
00028
00029 #include <math.h>
00030
00031 #include "ocrfeatures.h"
00032 #include <stdio.h>
00033 #include "efio.h"
00034
00035
00036 #define PICO_FEATURE_LENGTH 0.05
00037
00038
00039
00040
00041 void ConvertSegmentToPicoFeat(FPOINT *Start,
00042 FPOINT *End,
00043 FEATURE_SET FeatureSet);
00044
00045 void ConvertToPicoFeatures2(MFOUTLINE Outline, FEATURE_SET FeatureSet);
00046
00047 void NormalizePicoX(FEATURE_SET FeatureSet);
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00089 FEATURE_SET ExtractPicoFeatures(TBLOB *Blob, LINE_STATS *LineStats) {
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
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 ConvertToPicoFeatures2(Outline, FeatureSet);
00120 }
00121 if (NormMethod == baseline)
00122 NormalizePicoX(FeatureSet);
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 FreeOutlines(Outlines);
00139 return (FeatureSet);
00140
00141 }
00142
00143
00144
00155 void InitPicoFXVars() {
00156
00157 VALUE dummy;
00158
00159 float_variable (PicoFeatureLength, "PicoFeatureLength",
00160 PICO_FEATURE_LENGTH);
00161
00162 }
00163
00164
00165
00166
00184 void ConvertSegmentToPicoFeat(FPOINT *Start,
00185 FPOINT *End,
00186 FEATURE_SET FeatureSet) {
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
00202 Xof (Delta) = XDelta (*Start, *End) / NumFeatures;
00203 Yof (Delta) = YDelta (*Start, *End) / NumFeatures;
00204
00205
00206 Xof (Center) = Xof (*Start) + Xof (Delta) / 2.0;
00207 Yof (Center) = Yof (*Start) + Yof (Delta) / 2.0;
00208
00209
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 }
00221
00222
00223
00243 void ConvertToPicoFeatures2(MFOUTLINE Outline, FEATURE_SET FeatureSet) {
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 }
00270
00271
00272
00284 void NormalizePicoX(FEATURE_SET FeatureSet) {
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 }