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