Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 "img.h"
24 #include "ocrpara.h"
25 #include "ocrrow.h"
26 #include "pdblock.h"
27
28 class BLOCK; //forward decl
29
30 ELISTIZEH (BLOCK)
31 class BLOCK:public ELIST_LINK, public PDBLK
32 //page block
33 {
34 friend class BLOCK_RECT_IT; //block iterator
35
36 public:
37 BLOCK()
38 : re_rotation_(1.0f, 0.0f),
39 classify_rotation_(1.0f, 0.0f),
40 skew_(1.0f, 0.0f) {
41 right_to_left_ = false;
42 hand_poly = NULL;
43 }
44 BLOCK(const char *name, //< filename
45 BOOL8 prop, //< proportional
46 inT16 kern, //< kerning
47 inT16 space, //< spacing
48 inT16 xmin, //< bottom left
49 inT16 ymin,
50 inT16 xmax, //< top right
51 inT16 ymax);
52
53 ~BLOCK () {
54 }
55
63 void set_stats(BOOL8 prop,
64 inT16 kern,
65 inT16 space,
66 inT16 ch_pitch) {
67 proportional = prop;
68 kerning = (inT8) kern;
69 spacing = space;
70 pitch = ch_pitch;
71 }
73 void set_xheight(inT32 height) {
74 xheight = height;
75 }
77 void set_font_class(inT16 font) {
78 font_class = font;
79 }
81 BOOL8 prop() const {
82 return proportional;
83 }
84 bool right_to_left() const {
85 return right_to_left_;
86 }
87 void set_right_to_left(bool value) {
88 right_to_left_ = value;
89 }
91 inT32 fixed_pitch() const {
92 return pitch;
93 }
95 inT16 kern() const {
96 return kerning;
97 }
99 inT16 font() const {
100 return font_class;
101 }
103 inT16 space() const {
104 return spacing;
105 }
107 const char *name() const {
108 return filename.string ();
109 }
111 inT32 x_height() const {
112 return xheight;
113 }
114 float cell_over_xheight() const {
115 return cell_over_xheight_;
116 }
117 void set_cell_over_xheight(float ratio) {
118 cell_over_xheight_ = ratio;
119 }
121 ROW_LIST *row_list() {
122 return &rows;
123 }
124 // Compute the margins between the edges of each row and this block's
125 // polyblock, and store the results in the rows.
126 void compute_row_margins();
127
128 // get paragraphs
129 PARA_LIST *para_list() {
130 return &paras_;
131 }
133 C_BLOB_LIST *blob_list() {
134 return &c_blobs;
135 }
136 C_BLOB_LIST *reject_blobs() {
137 return &rej_blobs;
138 }
139 FCOORD re_rotation() const {
140 return re_rotation_; // How to transform coords back to image.
141 }
142 void set_re_rotation(const FCOORD& rotation) {
143 re_rotation_ = rotation;
144 }
145 FCOORD classify_rotation() const {
146 return classify_rotation_; // Apply this before classifying.
147 }
148 void set_classify_rotation(const FCOORD& rotation) {
149 classify_rotation_ = rotation;
150 }
151 FCOORD skew() const {
152 return skew_; // Direction of true horizontal.
153 }
154 void set_skew(const FCOORD& skew) {
155 skew_ = skew;
156 }
157 const ICOORD& median_size() const {
158 return median_size_;
159 }
160 void set_median_size(int x, int y) {
161 median_size_.set_x(x);
162 median_size_.set_y(y);
163 }
164
165 Pix* render_mask() {
166 return PDBLK::render_mask(re_rotation_);
167 }
168
169 // Reflects the polygon in the y-axis and recomputes the bounding_box.
170 // Does nothing to any contained rows/words/blobs etc.
171 void reflect_polygon_in_y_axis();
172
173 void rotate(const FCOORD& rotation);
174
176 void sort_rows();
177
179 void compress();
180
182 void check_pitch();
183
185 void compress(const ICOORD vec);
186
188 void print(FILE *fp, BOOL8 dump);
189
190 BLOCK& operator=(const BLOCK & source);
191
192 private:
193 BOOL8 proportional; //< proportional
194 bool right_to_left_; //< major script is right to left.
195 inT8 kerning; //< inter blob gap
196 inT16 spacing; //< inter word gap
197 inT16 pitch; //< pitch of non-props
198 inT16 font_class; //< correct font class
199 inT32 xheight; //< height of chars
200 float cell_over_xheight_; //< Ratio of cell height to xheight.
201 STRING filename; //< name of block
202 ROW_LIST rows; //< rows in block
203 PARA_LIST paras_; //< paragraphs of block
204 C_BLOB_LIST c_blobs; //< before textord
205 C_BLOB_LIST rej_blobs; //< duff stuff
206 FCOORD re_rotation_; //< How to transform coords back to image.
207 FCOORD classify_rotation_; //< Apply this before classifying.
208 FCOORD skew_; //< Direction of true horizontal.
209 ICOORD median_size_; //< Median size of blobs.
210 };
211
212 int decreasing_top_order(const void *row1, const void *row2);
213
214 // A function to print segmentation stats for the given block list.
215 void PrintSegmentationStats(BLOCK_LIST* block_list);
216
217 // Extracts blobs fromo the given block list and adds them to the output list.
218 // The block list must have been created by performing a page segmentation.
219 void ExtractBlobsFromSegmentation(BLOCK_LIST* blocks,
220 C_BLOB_LIST* output_blob_list);
221
222 // Refreshes the words in the block_list by using blobs in the
223 // new_blobs list.
224 // Block list must have word segmentation in it.
225 // It consumes the blobs provided in the new_blobs list. The blobs leftover in
226 // the new_blobs list after the call weren't matched to any blobs of the words
227 // in block list.
228 // The output not_found_blobs is a list of blobs from the original segmentation
229 // in the block_list for which no corresponding new blobs were found.
230 void RefreshWordBlobsFromNewBlobs(BLOCK_LIST* block_list,
231 C_BLOB_LIST* new_blobs,
232 C_BLOB_LIST* not_found_blobs);
233
234 #endif