tesseract  4.00.00dev
ocrblock.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: ocrblock.h (Formerly block.h)
3  * Description: Page block class definition.
4  * Author: Ray Smith
5  * Created: Thu Mar 14 17:32:01 GMT 1991
6  *
7  * (C) Copyright 1991, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #ifndef OCRBLOCK_H
21 #define OCRBLOCK_H
22 
23 #include "ocrpara.h"
24 #include "ocrrow.h"
25 #include "pdblock.h"
26 
27 class BLOCK; //forward decl
28 
30 class BLOCK:public ELIST_LINK, public PDBLK
31 //page block
32 {
33  friend class BLOCK_RECT_IT; //block iterator
34 
35  public:
37  : re_rotation_(1.0f, 0.0f),
38  classify_rotation_(1.0f, 0.0f),
39  skew_(1.0f, 0.0f) {
40  right_to_left_ = false;
41  hand_poly = NULL;
42  }
43  BLOCK(const char *name, //< filename
44  BOOL8 prop, //< proportional
45  inT16 kern, //< kerning
46  inT16 space, //< spacing
47  inT16 xmin, //< bottom left
48  inT16 ymin,
49  inT16 xmax, //< top right
50  inT16 ymax);
51 
52  ~BLOCK () {
53  }
54 
62  void set_stats(BOOL8 prop,
63  inT16 kern,
64  inT16 space,
65  inT16 ch_pitch) {
66  proportional = prop;
67  kerning = (inT8) kern;
68  spacing = space;
69  pitch = ch_pitch;
70  }
72  void set_xheight(inT32 height) {
73  xheight = height;
74  }
76  void set_font_class(inT16 font) {
77  font_class = font;
78  }
80  BOOL8 prop() const {
81  return proportional;
82  }
83  bool right_to_left() const {
84  return right_to_left_;
85  }
86  void set_right_to_left(bool value) {
87  right_to_left_ = value;
88  }
90  inT32 fixed_pitch() const {
91  return pitch;
92  }
94  inT16 kern() const {
95  return kerning;
96  }
98  inT16 font() const {
99  return font_class;
100  }
102  inT16 space() const {
103  return spacing;
104  }
106  const char *name() const {
107  return filename.string ();
108  }
110  inT32 x_height() const {
111  return xheight;
112  }
113  float cell_over_xheight() const {
114  return cell_over_xheight_;
115  }
116  void set_cell_over_xheight(float ratio) {
117  cell_over_xheight_ = ratio;
118  }
120  ROW_LIST *row_list() {
121  return &rows;
122  }
123  // Compute the margins between the edges of each row and this block's
124  // polyblock, and store the results in the rows.
125  void compute_row_margins();
126 
127  // get paragraphs
128  PARA_LIST *para_list() {
129  return &paras_;
130  }
132  C_BLOB_LIST *blob_list() {
133  return &c_blobs;
134  }
135  C_BLOB_LIST *reject_blobs() {
136  return &rej_blobs;
137  }
138  FCOORD re_rotation() const {
139  return re_rotation_; // How to transform coords back to image.
140  }
141  void set_re_rotation(const FCOORD& rotation) {
142  re_rotation_ = rotation;
143  }
145  return classify_rotation_; // Apply this before classifying.
146  }
147  void set_classify_rotation(const FCOORD& rotation) {
148  classify_rotation_ = rotation;
149  }
150  FCOORD skew() const {
151  return skew_; // Direction of true horizontal.
152  }
153  void set_skew(const FCOORD& skew) {
154  skew_ = skew;
155  }
156  const ICOORD& median_size() const {
157  return median_size_;
158  }
159  void set_median_size(int x, int y) {
160  median_size_.set_x(x);
161  median_size_.set_y(y);
162  }
163 
164  Pix* render_mask(TBOX* mask_box) {
165  return PDBLK::render_mask(re_rotation_, mask_box);
166  }
167 
168  // Returns the bounding box including the desired combination of upper and
169  // lower noise/diacritic elements.
170  TBOX restricted_bounding_box(bool upper_dots, bool lower_dots) const;
171 
172  // Reflects the polygon in the y-axis and recomputes the bounding_box.
173  // Does nothing to any contained rows/words/blobs etc.
174  void reflect_polygon_in_y_axis();
175 
176  void rotate(const FCOORD& rotation);
177 
179  void sort_rows();
180 
182  void compress();
183 
185  void check_pitch();
186 
188  void compress(const ICOORD vec);
189 
191  void print(FILE *fp, BOOL8 dump);
192 
193  BLOCK& operator=(const BLOCK & source);
194 
195  private:
196  BOOL8 proportional; //< proportional
197  bool right_to_left_; //< major script is right to left.
198  inT8 kerning; //< inter blob gap
199  inT16 spacing; //< inter word gap
200  inT16 pitch; //< pitch of non-props
201  inT16 font_class; //< correct font class
202  inT32 xheight; //< height of chars
203  float cell_over_xheight_; //< Ratio of cell height to xheight.
204  STRING filename; //< name of block
205  ROW_LIST rows; //< rows in block
206  PARA_LIST paras_; //< paragraphs of block
207  C_BLOB_LIST c_blobs; //< before textord
208  C_BLOB_LIST rej_blobs; //< duff stuff
209  FCOORD re_rotation_; //< How to transform coords back to image.
210  FCOORD classify_rotation_; //< Apply this before classifying.
211  FCOORD skew_; //< Direction of true horizontal.
212  ICOORD median_size_; //< Median size of blobs.
213 };
214 
215 int decreasing_top_order(const void *row1, const void *row2);
216 
217 // A function to print segmentation stats for the given block list.
218 void PrintSegmentationStats(BLOCK_LIST* block_list);
219 
220 // Extracts blobs fromo the given block list and adds them to the output list.
221 // The block list must have been created by performing a page segmentation.
222 void ExtractBlobsFromSegmentation(BLOCK_LIST* blocks,
223  C_BLOB_LIST* output_blob_list);
224 
225 // Refreshes the words in the block_list by using blobs in the
226 // new_blobs list.
227 // Block list must have word segmentation in it.
228 // It consumes the blobs provided in the new_blobs list. The blobs leftover in
229 // the new_blobs list after the call weren't matched to any blobs of the words
230 // in block list.
231 // The output not_found_blobs is a list of blobs from the original segmentation
232 // in the block_list for which no corresponding new blobs were found.
233 void RefreshWordBlobsFromNewBlobs(BLOCK_LIST* block_list,
234  C_BLOB_LIST* new_blobs,
235  C_BLOB_LIST* not_found_blobs);
236 
237 #endif
void set_xheight(inT32 height)
set char size
Definition: ocrblock.h:72
Definition: points.h:189
FCOORD skew() const
Definition: ocrblock.h:150
int32_t inT32
Definition: host.h:38
void set_right_to_left(bool value)
Definition: ocrblock.h:86
void PrintSegmentationStats(BLOCK_LIST *block_list)
Definition: ocrblock.cpp:410
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:948
inT16 font() const
return font class
Definition: ocrblock.h:98
float cell_over_xheight() const
Definition: ocrblock.h:113
C_BLOB_LIST * reject_blobs()
Definition: ocrblock.h:135
const ICOORD & median_size() const
Definition: ocrblock.h:156
void set_stats(BOOL8 prop, inT16 kern, inT16 space, inT16 ch_pitch)
Definition: ocrblock.h:62
void set_font_class(inT16 font)
set font class
Definition: ocrblock.h:76
Pix * render_mask(const FCOORD &rerotation, TBOX *mask_box)
Definition: pdblock.cpp:129
int16_t inT16
Definition: host.h:36
inT32 fixed_pitch() const
return pitch
Definition: ocrblock.h:90
void set_classify_rotation(const FCOORD &rotation)
Definition: ocrblock.h:147
void set_cell_over_xheight(float ratio)
Definition: ocrblock.h:116
inT32 x_height() const
return xheight
Definition: ocrblock.h:110
unsigned char BOOL8
Definition: host.h:44
Definition: strngs.h:45
void ExtractBlobsFromSegmentation(BLOCK_LIST *blocks, C_BLOB_LIST *output_blob_list)
Definition: ocrblock.cpp:443
C_BLOB_LIST * blob_list()
get blobs
Definition: ocrblock.h:132
Pix * render_mask(TBOX *mask_box)
Definition: ocrblock.h:164
int decreasing_top_order(const void *row1, const void *row2)
Definition: ocrblock.cpp:72
void set_re_rotation(const FCOORD &rotation)
Definition: ocrblock.h:141
PARA_LIST * para_list()
Definition: ocrblock.h:128
inT16 kern() const
return kerning
Definition: ocrblock.h:94
void RefreshWordBlobsFromNewBlobs(BLOCK_LIST *block_list, C_BLOB_LIST *new_blobs, C_BLOB_LIST *not_found_blobs)
Definition: ocrblock.cpp:478
Definition: rect.h:30
int8_t inT8
Definition: host.h:34
BOOL8 prop() const
return proportional
Definition: ocrblock.h:80
const char * filename
Definition: ioapi.h:38
FCOORD re_rotation() const
Definition: ocrblock.h:138
bool right_to_left() const
Definition: ocrblock.h:83
~BLOCK()
Definition: ocrblock.h:52
BLOCK()
Definition: ocrblock.h:36
const char * name() const
return filename
Definition: ocrblock.h:106
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:120
inT16 space() const
return spacing
Definition: ocrblock.h:102
FCOORD classify_rotation() const
Definition: ocrblock.h:144
Definition: ocrblock.h:30
void set_median_size(int x, int y)
Definition: ocrblock.h:159
integer coordinate
Definition: points.h:30
void set_skew(const FCOORD &skew)
Definition: ocrblock.h:153
page block
Definition: pdblock.h:32