00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef OCRBLOCK_H
00021 #define OCRBLOCK_H
00022
00023 #include "img.h"
00024 #include "ocrpara.h"
00025 #include "ocrrow.h"
00026 #include "pdblock.h"
00027
00028 class BLOCK;
00029
00030 ELISTIZEH (BLOCK)
00031 class BLOCK:public ELIST_LINK, public PDBLK
00032
00033 {
00034 friend class BLOCK_RECT_IT;
00035
00036 public:
00037 BLOCK()
00038 : re_rotation_(1.0f, 0.0f),
00039 classify_rotation_(1.0f, 0.0f),
00040 skew_(1.0f, 0.0f) {
00041 right_to_left_ = false;
00042 hand_poly = NULL;
00043 }
00044 BLOCK(const char *name,
00045 BOOL8 prop,
00046 inT16 kern,
00047 inT16 space,
00048 inT16 xmin,
00049 inT16 ymin,
00050 inT16 xmax,
00051 inT16 ymax);
00052
00053 ~BLOCK () {
00054 }
00055
00063 void set_stats(BOOL8 prop,
00064 inT16 kern,
00065 inT16 space,
00066 inT16 ch_pitch) {
00067 proportional = prop;
00068 kerning = (inT8) kern;
00069 spacing = space;
00070 pitch = ch_pitch;
00071 }
00073 void set_xheight(inT32 height) {
00074 xheight = height;
00075 }
00077 void set_font_class(inT16 font) {
00078 font_class = font;
00079 }
00081 BOOL8 prop() const {
00082 return proportional;
00083 }
00084 bool right_to_left() const {
00085 return right_to_left_;
00086 }
00087 void set_right_to_left(bool value) {
00088 right_to_left_ = value;
00089 }
00091 inT32 fixed_pitch() const {
00092 return pitch;
00093 }
00095 inT16 kern() const {
00096 return kerning;
00097 }
00099 inT16 font() const {
00100 return font_class;
00101 }
00103 inT16 space() const {
00104 return spacing;
00105 }
00107 const char *name() const {
00108 return filename.string ();
00109 }
00111 inT32 x_height() const {
00112 return xheight;
00113 }
00114 float cell_over_xheight() const {
00115 return cell_over_xheight_;
00116 }
00117 void set_cell_over_xheight(float ratio) {
00118 cell_over_xheight_ = ratio;
00119 }
00121 ROW_LIST *row_list() {
00122 return &rows;
00123 }
00124
00125
00126 void compute_row_margins();
00127
00128
00129 PARA_LIST *para_list() {
00130 return ¶s_;
00131 }
00133 C_BLOB_LIST *blob_list() {
00134 return &c_blobs;
00135 }
00136 C_BLOB_LIST *reject_blobs() {
00137 return &rej_blobs;
00138 }
00139 FCOORD re_rotation() const {
00140 return re_rotation_;
00141 }
00142 void set_re_rotation(const FCOORD& rotation) {
00143 re_rotation_ = rotation;
00144 }
00145 FCOORD classify_rotation() const {
00146 return classify_rotation_;
00147 }
00148 void set_classify_rotation(const FCOORD& rotation) {
00149 classify_rotation_ = rotation;
00150 }
00151 FCOORD skew() const {
00152 return skew_;
00153 }
00154 void set_skew(const FCOORD& skew) {
00155 skew_ = skew;
00156 }
00157 const ICOORD& median_size() const {
00158 return median_size_;
00159 }
00160 void set_median_size(int x, int y) {
00161 median_size_.set_x(x);
00162 median_size_.set_y(y);
00163 }
00164
00165 Pix* render_mask() {
00166 return PDBLK::render_mask(re_rotation_);
00167 }
00168
00169
00170
00171 void reflect_polygon_in_y_axis();
00172
00173 void rotate(const FCOORD& rotation);
00174
00176 void sort_rows();
00177
00179 void compress();
00180
00182 void check_pitch();
00183
00185 void compress(const ICOORD vec);
00186
00188 void print(FILE *fp, BOOL8 dump);
00189
00190 BLOCK& operator=(const BLOCK & source);
00191
00192 private:
00193 BOOL8 proportional;
00194 bool right_to_left_;
00195 inT8 kerning;
00196 inT16 spacing;
00197 inT16 pitch;
00198 inT16 font_class;
00199 inT32 xheight;
00200 float cell_over_xheight_;
00201 STRING filename;
00202 ROW_LIST rows;
00203 PARA_LIST paras_;
00204 C_BLOB_LIST c_blobs;
00205 C_BLOB_LIST rej_blobs;
00206 FCOORD re_rotation_;
00207 FCOORD classify_rotation_;
00208 FCOORD skew_;
00209 ICOORD median_size_;
00210 };
00211
00212 int decreasing_top_order(const void *row1, const void *row2);
00213
00214
00215 void PrintSegmentationStats(BLOCK_LIST* block_list);
00216
00217
00218
00219 void ExtractBlobsFromSegmentation(BLOCK_LIST* blocks,
00220 C_BLOB_LIST* output_blob_list);
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 void RefreshWordBlobsFromNewBlobs(BLOCK_LIST* block_list,
00231 C_BLOB_LIST* new_blobs,
00232 C_BLOB_LIST* not_found_blobs);
00233
00234 #endif