classify/outfeat.cpp

Go to the documentation of this file.
00001 
00019 /* =================
00020  Include Files and Type Defines
00021  ==================== */
00022 #include "outfeat.h"
00023 #include "mfoutline.h"
00024 #include "variables.h"
00025 #include "sigmenu.h"
00026 
00027 #include "ocrfeatures.h"         //Debug
00028 #include <stdio.h>               //Debug
00029 #include "efio.h"                //Debug
00030 #ifdef TEXT_VERBOSE
00031 #include    "callcpp.h"
00032 #endif
00033 //#include "christydbg.h"
00034 
00035 /* =================
00036  Private Function Prototypes
00037  ==================== */
00038 /*
00039 #if defined(__STDC__) || defined(__cplusplus)
00040 # define _ARGS(s) s
00041 #else
00042 # define _ARGS(s) ()
00043 #endif*/
00044 
00045 /* /users/danj/wiseowl/src/danj/microfeatures/outfeat.c
00046 void AddOutlineFeatureToSet
00047   _ARGS((FPOINT *Start,
00048   FPOINT *End,
00049   FEATURE_SET FeatureSet));
00050 
00051 void ConvertToOutlineFeatures
00052   _ARGS((MFOUTLINE Outline,
00053   FEATURE_SET FeatureSet));
00054 
00055 void NormalizeOutlineX
00056   _ARGS((FEATURE_SET FeatureSet));
00057 
00058 #undef _ARGS
00059 */
00060 /* =================
00061  Global Data Definitions and Declarations
00062  ==================== */
00063 /* =================
00064               Public Code
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   // 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 */
00135 
00136 
00137 /* =============================== */
00147 void InitOutlineFXVars() { 
00148                                  //once contained a dummy
00149 }                                /* InitOutlineFXVars */
00150 
00151 
00152 /* =================
00153      Private Code
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 }                                /* AddOutlineFeatureToSet */
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     /* 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 */
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 }                                /* NormalizeOutlineX */

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