wordrec/charsample.h

Go to the documentation of this file.
00001 
00020 #ifndef           CHARSAMPLE_H
00021 #define           CHARSAMPLE_H
00022 
00023 #include          "elst.h"
00024 #include          "pageres.h"
00025 #include          "memry.h"
00026 #include          "notdll.h"
00027 #include          "notdll.h"
00028 
00029 #define BAD_SCORE MAX_INT32
00030 #define FIRST_CHAR '!'
00031 #define LAST_CHAR  '~'
00032 
00037 enum ClusterType
00038 {
00039    UNKNOWN,
00040    BLOB_CLUSTER,
00041    IMAGE_CLUSTER
00042 };
00043 
00044 class CHAR_SAMPLE;               //forward decl
00045 
00046 ELISTIZEH (CHAR_SAMPLE)
00047 class CHAR_SAMPLES;              //forward decl
00048 
00049 ELISTIZEH (CHAR_SAMPLES)
00050 class CHAR_PROTO;                //forward decl
00051 
00056 class CHAR_SAMPLE:public ELIST_LINK
00057 {
00058   public:
00059     CHAR_SAMPLE();  // empty constructor
00060 
00061     CHAR_SAMPLE(  // simple constructor
00062                 PBLOB *blob,
00063                 DENORM *denorm,
00064                 char c);
00065 
00066     CHAR_SAMPLE(  // simple constructor
00067                 IMAGE *image,
00068                 char c);
00069 
00070     ~CHAR_SAMPLE () {
00071       // We own the image, so it has to be deleted.
00072       if (sample_image != NULL)
00073         delete sample_image;
00074     }
00075 
00076     float match_sample(CHAR_SAMPLE *test_sample, BOOL8 updating);
00077 
00078     INT32 n_matches() {
00079       return n_samples_matched;
00080     }
00081 
00082     IMAGE *image() {
00083       return sample_image;
00084     }
00085 
00086     PBLOB *blob() {
00087       return sample_blob;
00088     }
00089 
00090     DENORM *denorm() {
00091       return sample_denorm;
00092     }
00093 
00094     double mean_score();
00095 
00096     double variance();
00097 
00098     char character() {
00099       return ch;
00100     }
00101 
00102     void print(FILE *f);
00103 
00104     void reset_match_statistics();
00105 
00106     NEWDELETE2 (CHAR_SAMPLE) private:
00107     IMAGE * sample_image;
00108     PBLOB *sample_blob;
00109     DENORM *sample_denorm;
00110     INT32 n_samples_matched;
00111     double total_match_scores;
00112     double sumsq_match_scores;
00113     char ch;
00114 };
00115 
00122 class CHAR_SAMPLES:public ELIST_LINK
00123 {
00124   public:
00125     CHAR_SAMPLES();  //empty constructor
00126 
00127     CHAR_SAMPLES(CHAR_SAMPLE *sample);
00128 
00129     ~CHAR_SAMPLES () {           //destructor
00130     }
00131 
00132     INT32 n_samples() {
00133       return samples.length ();
00134     }
00135 
00136     void add_sample(CHAR_SAMPLE *sample);
00137 
00138     void build_prototype();
00139 
00140     void rebuild_prototype(INT32 new_xsize, INT32 new_ysize);
00141 
00142     void add_sample_to_prototype(CHAR_SAMPLE *sample);
00143 
00144     CHAR_PROTO *prototype() {
00145       return proto;
00146     }
00147 
00148     void find_best_sample();
00149 
00150     float match_score(CHAR_SAMPLE *sample);
00151 
00152     float nn_match_score(CHAR_SAMPLE *sample);
00153 
00154     char character() {
00155       return ch;
00156     }
00157 
00158     void assign_to_char();
00159 
00160     void print(FILE *f);
00161 
00162     NEWDELETE2 (CHAR_SAMPLES) private:
00163     ClusterType type;
00164     char ch;
00165     CHAR_PROTO *proto;
00166     CHAR_SAMPLE *best_sample;
00167     CHAR_SAMPLE_LIST samples;
00168 };
00169 
00186 class CHAR_PROTO
00187 {
00188   public:
00189     CHAR_PROTO();  // empty constructor
00190 
00191     CHAR_PROTO(INT32 x_size,
00192                INT32 y_size,
00193                INT32 n_samples,
00194                float initial_value,
00195                char c);
00196 
00197     CHAR_PROTO(  // simple constructor
00198                CHAR_SAMPLE *sample);
00199 
00200     ~CHAR_PROTO ();
00201 
00202     float match_sample(CHAR_SAMPLE *test_sample);
00203 
00204     float match(CHAR_PROTO *test_proto);
00205 
00206     INT32 n_samples() {
00207       return nsamples;
00208     }
00209 
00210     INT32 x_size() {
00211       return xsize;
00212     }
00213 
00214     INT32 y_size() {
00215       return ysize;
00216     }
00217 
00218     float **data() {
00219       return proto;
00220     }
00221     char character() {
00222       return ch;
00223     }
00224 
00225     void enlarge_prototype(INT32 new_xsize, INT32 new_ysize);
00226 
00227     void add_sample(CHAR_SAMPLE *sample);
00228 
00229     IMAGE *make_image();
00230 
00231     void print(FILE *f);
00232 
00233     NEWDELETE2 (CHAR_PROTO) private:
00234     INT32 xsize;
00235     INT32 ysize;
00236     float *proto_data;
00237     float **proto;
00238     INT32 nsamples;
00239     char ch;
00240 };
00241 #endif

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