#include "outfeat.h"
#include "mfoutline.h"
#include "variables.h"
#include "sigmenu.h"
#include "ocrfeatures.h"
#include <stdio.h>
#include "efio.h"
Go to the source code of this file.
void AddOutlineFeatureToSet | ( | FPOINT * | Start, | |
FPOINT * | End, | |||
FEATURE_SET | FeatureSet | |||
) |
Computes the midpoint between Start and End to obtain the x,y position of the outline-feature.
Start | Starting point of outline-feature | |
End | Ending point of outline-feature | |
FeatureSet | Set to add outline-feature to |
This feature is then inserted into the next feature slot in FeatureSet.
Definition at line 173 of file outfeat.cpp.
References AddFeature(), AverageOf, DistanceBetween, NewFeature(), NormalizedAngleFrom(), OutlineFeatDesc, OutlineFeatDir, OutlineFeatLength, OutlineFeatX, OutlineFeatY, ParamOf, Xof, and Yof.
Referenced by ConvertToOutlineFeatures().
00175 { 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 } /* AddOutlineFeatureToSet */
void ConvertToOutlineFeatures | ( | MFOUTLINE | Outline, | |
FEATURE_SET | FeatureSet | |||
) |
Converts each section in the specified outline to a feature described by its x,y position, length and angle.
Outline | Outline to extract outline-features from | |
FeatureSet | Set of features to add outline-features to |
Definition at line 209 of file outfeat.cpp.
References AddOutlineFeatureToSet(), CopyPoint, DegenerateOutline, IsVisible, NextPointAfter, PointAt, and PositionOf.
Referenced by ExtractOutlineFeatures().
00209 { 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 /* Note that an edge is hidden if the ending point of the edge is 00225 marked as hidden. This situation happens because the order of 00226 the outlines is reversed when they are converted from the old 00227 format. In the old format, a hidden edge is marked by the 00228 starting point for that edge. */ 00229 if (IsVisible (PointAt (Next))) { 00230 CopyPoint (PositionOf (PointAt (Next)), FeatureEnd); 00231 AddOutlineFeatureToSet(&FeatureStart, &FeatureEnd, FeatureSet); 00232 } 00233 } 00234 while (Next != First); 00235 } /* ConvertToOutlineFeatures */
FEATURE_SET ExtractOutlineFeatures | ( | TBLOB * | Blob, | |
LINE_STATS * | LineStats | |||
) |
Convert each segment in the outline to a feature.
Blob | Blob to extract pico-features from | |
LineStats | Statistics on text row blob is in |
Definition at line 77 of file outfeat.cpp.
References baseline, ConvertBlob(), ConvertToOutlineFeatures(), cprintf(), first, FreeOutlines(), iterate, MAX_OUTLINE_FEATURES, NewFeatureSet(), NormalizeOutlines(), NormalizeOutlineX(), NormMethod, NULL, and Outline.
Referenced by MakeNewAdaptedClass().
00077 { 00078 LIST Outlines; 00079 LIST RemainingOutlines; 00080 MFOUTLINE Outline; 00081 FEATURE_SET FeatureSet; 00082 FLOAT32 XScale, YScale; 00083 00084 #ifdef TEXT_VERBOSE 00085 // gets a 'o', see ccmain/tesseractmain.dox 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 /*---------Debug--------------------------------------------------* 00099 OFile = fopen ("f:/ims/debug/ofOutline.logCPP", "r"); 00100 if (OFile == NULL) 00101 { 00102 OFile = Efopen ("f:/ims/debug/ofOutline.logCPP", "w"); 00103 WriteOutline(OFile, Outline); 00104 } 00105 else 00106 { 00107 fclose (OFile); 00108 OFile = Efopen ("f:/ims/debug/ofOutline.logCPP", "a"); 00109 } 00110 WriteOutline(OFile, Outline); 00111 fclose (OFile); 00112 *--------------------------------------------------------------------*/ 00113 ConvertToOutlineFeatures(Outline, FeatureSet); 00114 } 00115 if (NormMethod == baseline) 00116 NormalizeOutlineX(FeatureSet); 00117 /*---------Debug--------------------------------------------------* 00118 File = fopen ("f:/ims/debug/ofFeatSet.logCPP", "r"); 00119 if (File == NULL) 00120 { 00121 File = Efopen ("f:/ims/debug/ofFeatSet.logCPP", "w"); 00122 WriteFeatureSet(File, FeatureSet); 00123 } 00124 else 00125 { 00126 fclose (File); 00127 File = Efopen ("f:/ims/debug/ofFeatSet.logCPP", "a"); 00128 } 00129 WriteFeatureSet(File, FeatureSet); 00130 fclose (File); 00131 *--------------------------------------------------------------------*/ 00132 FreeOutlines(Outlines); 00133 return (FeatureSet); 00134 } /* ExtractOutlineFeatures */
void InitOutlineFXVars | ( | ) |
Initialize the outline-feature extractor variables that can be tuned without recompiling.
none |
Definition at line 147 of file outfeat.cpp.
Referenced by InitAdaptiveClassifierVars().
void NormalizeOutlineX | ( | FEATURE_SET | FeatureSet | ) |
Computes the weighted average x position over all of the outline-features in FeatureSet and then renormalizes the outline-features to force this average to be the x origin (i.e. x=0).
FeatureSet | Outline-features to be normalized |
Definition at line 250 of file outfeat.cpp.
References FeatureIn, NumFeaturesIn, OutlineFeatLength, OutlineFeatX, and ParamOf.
Referenced by ExtractOutlineFeatures().
00250 { 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 } /* NormalizeOutlineX */