00001
00019
00020
00021
00022 #include "outfeat.h"
00023 #include "mfoutline.h"
00024 #include "variables.h"
00025 #include "sigmenu.h"
00026
00027 #include "ocrfeatures.h"
00028 #include <stdio.h>
00029 #include "efio.h"
00030 #ifdef TEXT_VERBOSE
00031 #include "callcpp.h"
00032 #endif
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00077 FEATURE_SET ExtractOutlineFeatures(TBLOB *Blob, LINE_STATS *LineStats) {
00078 LIST Outlines;
00079 LIST RemainingOutlines;
00080 MFOUTLINE Outline;
00081 FEATURE_SET FeatureSet;
00082 FLOAT32 XScale, YScale;
00083
00084 #ifdef TEXT_VERBOSE
00085
00086 cprintf("o");
00087 #endif
00088 FeatureSet = NewFeatureSet (MAX_OUTLINE_FEATURES);
00089 if (Blob == NULL)
00090 return (FeatureSet);
00091
00092 Outlines = ConvertBlob (Blob);
00093
00094 NormalizeOutlines(Outlines, LineStats, &XScale, &YScale);
00095 RemainingOutlines = Outlines;
00096 iterate(RemainingOutlines) {
00097 Outline = (MFOUTLINE) first (RemainingOutlines);
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 ConvertToOutlineFeatures(Outline, FeatureSet);
00114 }
00115 if (NormMethod == baseline)
00116 NormalizeOutlineX(FeatureSet);
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 FreeOutlines(Outlines);
00133 return (FeatureSet);
00134 }
00135
00136
00137
00147 void InitOutlineFXVars() {
00148
00149 }
00150
00151
00152
00153
00154
00155
00173 void AddOutlineFeatureToSet(FPOINT *Start,
00174 FPOINT *End,
00175 FEATURE_SET FeatureSet) {
00176 FEATURE Feature;
00177
00178 Feature = NewFeature (&OutlineFeatDesc);
00179 ParamOf (Feature, OutlineFeatDir) = NormalizedAngleFrom (Start, End, 1.0);
00180 ParamOf (Feature, OutlineFeatX) = AverageOf (Xof (*Start), Xof (*End));
00181 ParamOf (Feature, OutlineFeatY) = AverageOf (Yof (*Start), Yof (*End));
00182 ParamOf (Feature, OutlineFeatLength) = DistanceBetween (*Start, *End);
00183 AddFeature(FeatureSet, Feature);
00184
00185 }
00186
00187
00188
00209 void ConvertToOutlineFeatures(MFOUTLINE Outline, FEATURE_SET FeatureSet) {
00210 MFOUTLINE Next;
00211 MFOUTLINE First;
00212 FPOINT FeatureStart;
00213 FPOINT FeatureEnd;
00214
00215 if (DegenerateOutline (Outline))
00216 return;
00217
00218 First = Outline;
00219 Next = First;
00220 do {
00221 CopyPoint (PositionOf (PointAt (Next)), FeatureStart);
00222 Next = NextPointAfter (Next);
00223
00224
00225
00226
00227
00228
00229 if (IsVisible (PointAt (Next))) {
00230 CopyPoint (PositionOf (PointAt (Next)), FeatureEnd);
00231 AddOutlineFeatureToSet(&FeatureStart, &FeatureEnd, FeatureSet);
00232 }
00233 }
00234 while (Next != First);
00235 }
00236
00237
00238
00250 void NormalizeOutlineX(FEATURE_SET FeatureSet) {
00251 int i;
00252 FEATURE Feature;
00253 FLOAT32 Length;
00254 FLOAT32 TotalX = 0.0;
00255 FLOAT32 TotalWeight = 0.0;
00256 FLOAT32 Origin;
00257
00258 if (NumFeaturesIn (FeatureSet) <= 0)
00259 return;
00260
00261 for (i = 0; i < NumFeaturesIn (FeatureSet); i++) {
00262 Feature = FeatureIn (FeatureSet, i);
00263 Length = ParamOf (Feature, OutlineFeatLength);
00264 TotalX += ParamOf (Feature, OutlineFeatX) * Length;
00265 TotalWeight += Length;
00266 }
00267 Origin = TotalX / TotalWeight;
00268
00269 for (i = 0; i < NumFeaturesIn (FeatureSet); i++) {
00270 Feature = FeatureIn (FeatureSet, i);
00271 ParamOf (Feature, OutlineFeatX) -= Origin;
00272 }
00273 }