00001 
00020 
00021 
00022 
00023 #include "blobclass.h"
00024 #include "fxdefs.h"
00025 #include "variables.h"
00026 #include "extract.h"
00027 #include "efio.h"
00028 #include "callcpp.h"
00029 #include "chartoname.h"
00030 
00031 #include <math.h>
00032 #include <stdio.h>
00033 #include <signal.h>
00034 
00035 #define MAXFILENAME             80
00036 #define MAXMATCHES              10
00037 
00038 
00039 #define FONT_NAME       "UnknownFont"
00040 
00041 
00042 
00043 
00045 extern char imagefile[];
00046 
00048 static const char *FontName = FONT_NAME;
00049 
00050 
00051 
00052 
00053 
00064 void InitBlobClassifierVars() { 
00065   VALUE dummy;
00066 
00067   string_variable (FontName, "FontName", FONT_NAME);
00068 
00069 }                                
00070 
00071 
00072 
00074 #define MAXFILENAME     80
00075 
00076 #define MAXCHARNAME     20
00077 
00078 #define MAXFONTNAME     20
00079 
00080 #define TRAIN_SUFFIX    ".tr"
00081 
00096 void
00097 LearnBlob (TBLOB * Blob, TEXTROW * Row, char BlobText[], int TextLength)
00098 {
00099   static FILE *FeatureFile = NULL;
00100   char Filename[MAXFILENAME];
00101   char CharName[MAXCHARNAME];
00102   CHAR_DESC CharDesc;
00103   LINE_STATS LineStats;
00104 
00105   EnterLearnMode;
00106 
00107   
00108   if (TextLength != 1)
00109     return;
00110 
00111   GetLineStatsFromRow(Row, &LineStats); 
00112 
00113   CharDesc = ExtractBlobFeatures (Blob, &LineStats);
00114 
00115   
00116   
00117   if (FeatureFile == NULL) {
00118     strcpy(Filename, imagefile); 
00119     strcat(Filename, TRAIN_SUFFIX); 
00120     FeatureFile = Efopen (Filename, "w");
00121 
00122     cprintf ("TRAINING ... Font name = %s.\n", FontName);
00123   }
00124 
00125   
00126   chartoname (CharName, BlobText[0], "");
00127 
00128   
00129   fprintf (FeatureFile, "\n%s %s ", FontName, CharName);
00130 
00131   
00132   WriteCharDescription(FeatureFile, CharDesc); 
00133   FreeCharDescription(CharDesc); 
00134 
00135 }