classify/blobclass.cpp

Go to the documentation of this file.
00001 
00020 /* =================
00021       Include Files and Type Defines
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 // define default font name to be used in training
00039 #define FONT_NAME       "UnknownFont"
00040 
00041 /* =================
00042         Global Data Definitions and Declarations
00043  ==================== */
00045 extern char imagefile[];
00046 
00048 static const char *FontName = FONT_NAME;
00049 
00050 /* =================
00051             Public Code
00052  ==================== */
00053 /* =============================== */
00064 void InitBlobClassifierVars() { 
00065   VALUE dummy;
00066 
00067   string_variable (FontName, "FontName", FONT_NAME);
00068 
00069 }                                /* InitBlobClassifierVars */
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   // throw out blobs which do not represent only one character
00108   if (TextLength != 1)
00109     return;
00110 
00111   GetLineStatsFromRow(Row, &LineStats); 
00112 
00113   CharDesc = ExtractBlobFeatures (Blob, &LineStats);
00114 
00115   // if a feature file is not yet open, open it
00116   // the name of the file is the name of the image plus TRAIN_SUFFIX
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   // get the name of the character for this blob
00126   chartoname (CharName, BlobText[0], "");
00127 
00128   // label the features with a class name and font name
00129   fprintf (FeatureFile, "\n%s %s ", FontName, CharName);
00130 
00131   // write micro-features to file and clean up
00132   WriteCharDescription(FeatureFile, CharDesc); 
00133   FreeCharDescription(CharDesc); 
00134 
00135 }                                // LearnBlob

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