00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022 #ifndef ASSOCIATE_H
00023 #define ASSOCIATE_H
00024
00025 #include "blobs.h"
00026 #include "elst.h"
00027 #include "matrix.h"
00028 #include "seam.h"
00029 #include "split.h"
00030 #include "states.h"
00031
00032 class WERD_RES;
00033
00034 typedef inT16 BLOB_WEIGHTS[MAX_NUM_CHUNKS];
00035
00036
00037 struct EVALUATION_RECORD {
00038 float match;
00039 float certainty;
00040 char character;
00041 int width;
00042 int gap;
00043 };
00044
00045 typedef EVALUATION_RECORD EVALUATION_ARRAY[MAX_NUM_CHUNKS];
00046
00047
00048
00049
00050
00051 struct CHUNKS_RECORD {
00052 MATRIX *ratings;
00053 TBLOB *chunks;
00054 WERD_RES* word_res;
00055 SEAMS splits;
00056 int x_height;
00057 WIDTH_RECORD *chunk_widths;
00058 WIDTH_RECORD *char_widths;
00059 inT16 *weights;
00060 };
00061
00062 namespace tesseract {
00063
00064
00065 struct AssociateStats {
00066 AssociateStats() { Clear(); }
00067
00068 void Clear() {
00069 shape_cost = 0.0f;
00070 bad_shape = false;
00071 full_wh_ratio = 0.0f;
00072 full_wh_ratio_total = 0.0f;
00073 full_wh_ratio_var = 0.0f;
00074 bad_fixed_pitch_right_gap = false;
00075 bad_fixed_pitch_wh_ratio = false;
00076 }
00077
00078 void Print() {
00079 tprintf("AssociateStats: w(%g %d) s(%g %d)\n", shape_cost, bad_shape);
00080 }
00081
00082 float shape_cost;
00083 bool bad_shape;
00084 float full_wh_ratio;
00085 float full_wh_ratio_total;
00086
00087 float full_wh_ratio_var;
00088 bool bad_fixed_pitch_right_gap;
00089
00090 bool bad_fixed_pitch_wh_ratio;
00091
00092 };
00093
00094
00095
00096 class AssociateUtils {
00097 public:
00098 static const float kMaxFixedPitchCharAspectRatio;
00099 static const float kMinGap;
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 static void ComputeStats(int col, int row,
00114 const AssociateStats *parent_stats,
00115 int parent_path_length,
00116 bool fixed_pitch,
00117 float max_char_wh_ratio,
00118 const DENORM *denorm,
00119 CHUNKS_RECORD *chunks_record,
00120 int debug_level,
00121 AssociateStats *stats);
00122
00123
00124
00125
00126
00127
00128 static int GetChunksWidth(WIDTH_RECORD *width_record,
00129 int start_blob, int last_blob);
00130
00131
00132 static inline int GetChunksGap(WIDTH_RECORD *width_record, int last_chunk) {
00133 return (last_chunk >= 0 && last_chunk < width_record->num_chars - 1) ?
00134 width_record->widths[last_chunk * 2 + 1] : 0;
00135 }
00136
00137
00138 static float FixedPitchWidthCost(float norm_width, float right_gap,
00139 bool end_pos, float max_char_wh_ratio);
00140
00141
00142
00143 static inline float FixedPitchGapCost(float norm_gap, bool end_pos) {
00144 return (norm_gap < 0.05 && !end_pos) ? 5.0f : 0.0f;
00145 }
00146 };
00147
00148 }
00149
00150 #endif