classify/normmatch.h File Reference

#include "matchdefs.h"
#include "ocrfeatures.h"

Go to the source code of this file.

Functions


Function Documentation

FLOAT32 ComputeNormMatch ( CLASS_ID  ClassId,
FEATURE  Feature,
BOOL8  DebugMatch 
)

Compares Features against each character normalization proto for ClassId and returns the match rating of the best match.

Parameters:
ClassId Id of class to match against
Feature Character normalization feature
DebugMatch Controls dump of debug info
Note:
Globals: NormProtos Character normalization prototypes
Returns:
Best match rating for Feature against protos of ClassId.
Note:
Exceptions: none
Date:
Wed Dec 19 16:56:12 1990, DSJ, Created.

Definition at line 96 of file normmatch.cpp.

References CharNormLength, CharNormRx, CharNormRy, CharNormY, cprintf(), FLOATUNION::Elliptical, first, iterate, MAX_FLOAT32, proto::Mean, NO_CLASS, NormEvidenceOf(), NormProtos, NORM_PROTOS::NumParams, ParamOf, PrintNormMatch(), NORM_PROTOS::Protos, proto::Variance, proto::Weight, WriteFeature(), and WriteNFloats().

Referenced by ComputeIntCharNormArray().

00096                                                                               { 
00097   LIST Protos;
00098   FLOAT32 BestMatch;
00099   FLOAT32 Match;
00100   FLOAT32 Delta;
00101   PROTOTYPE *Proto;
00102   int ProtoId;
00103 
00104   /* handle requests for classification as noise */
00105   if (ClassId == NO_CLASS) {
00106     /* kludge - clean up constants and make into control knobs later */
00107     Match = (ParamOf (Feature, CharNormLength) *
00108       ParamOf (Feature, CharNormLength) * 500.0 +
00109       ParamOf (Feature, CharNormRx) *
00110       ParamOf (Feature, CharNormRx) * 8000.0 +
00111       ParamOf (Feature, CharNormRy) *
00112       ParamOf (Feature, CharNormRy) * 8000.0);
00113     return (1.0 - NormEvidenceOf (Match));
00114   }
00115 
00116   BestMatch = MAX_FLOAT32;
00117   Protos = NormProtos->Protos[ClassId];
00118 
00119   if (DebugMatch) {
00120     cprintf ("\nFeature = ");
00121     WriteFeature(stdout, Feature);
00122   }
00123 
00124   ProtoId = 0;
00125   iterate(Protos) {
00126     Proto = (PROTOTYPE *) first (Protos);
00127     Delta = ParamOf (Feature, CharNormY) - Proto->Mean[CharNormY];
00128     Match = Delta * Delta * Proto->Weight.Elliptical[CharNormY];
00129     Delta = ParamOf (Feature, CharNormRx) - Proto->Mean[CharNormRx];
00130     Match += Delta * Delta * Proto->Weight.Elliptical[CharNormRx];
00131 
00132     if (Match < BestMatch)
00133       BestMatch = Match;
00134 
00135     if (DebugMatch) {
00136       cprintf ("Proto %1d = ", ProtoId);
00137       WriteNFloats (stdout, NormProtos->NumParams, Proto->Mean);
00138       cprintf ("      var = ");
00139       WriteNFloats (stdout, NormProtos->NumParams,
00140         Proto->Variance.Elliptical);
00141       cprintf ("    match = ");
00142       PrintNormMatch (stdout, NormProtos->NumParams, Proto, Feature);
00143     }
00144     ProtoId++;
00145   }
00146   return (1.0 - NormEvidenceOf (BestMatch));
00147 }                                /* ComputeNormMatch */

void FreeNormProtos (  ) 

Definition at line 175 of file normmatch.cpp.

References Efree(), FreeProtoList(), MAX_CLASS_ID, NormProtos, NULL, NORM_PROTOS::ParamDesc, and NORM_PROTOS::Protos.

Referenced by EndAdaptiveClassifier().

00175                       {
00176   if (NormProtos != NULL) {
00177     for (int i = 0; i <= MAX_CLASS_ID; i++)
00178       FreeProtoList(&NormProtos->Protos[i]);
00179     Efree(NormProtos->ParamDesc);
00180     Efree(NormProtos);
00181     NormProtos = NULL;
00182   }
00183 }

void GetNormProtos (  ) 

Reads in a set of character normalization protos from NormProtoFile and places them into NormProtos.

Parameters:
none 
Note:
Globals:
  • NormProtoFile Name of file containing normalization protos
  • NormProtos Global data structure to hold protos
Returns:
none
Note:
Exceptions: none
Date:
Wed Dec 19 16:24:25 1990, DSJ, Created.

Definition at line 163 of file normmatch.cpp.

References demodir, Efopen(), NormProtoFile, NormProtos, and ReadNormProtos().

Referenced by InitAdaptiveClassifier().

00163                      { 
00164   FILE *File;
00165   char name[1024];
00166 
00167   strcpy(name, demodir);
00168   strcat(name, NormProtoFile);
00169   File = Efopen (name, "r");
00170   NormProtos = ReadNormProtos (File);
00171   fclose(File);
00172 
00173 }                                /* GetNormProtos */

void InitNormProtoVars (  ) 

Initialize the control variables for the normalization matcher.

Parameters:
none 
Note:
Globals: NormProtoFile filename for normalization protos
Returns:
none
Note:
Exceptions: none
Date:
Mon Nov 5 17:22:10 1990, DSJ, Created.

Definition at line 195 of file normmatch.cpp.

References dummy, NORM_PROTO_FILE, NormProtoFile, and string_variable.

Referenced by init_dj_debug().

00195                          { 
00196   VALUE dummy;
00197 
00198   string_variable (NormProtoFile, "NormProtoFile", NORM_PROTO_FILE);
00199 
00200   MakeNormAdjMidpoint();
00201   MakeNormAdjCurl();
00202 
00203 }                                /* InitNormProtoVars */


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