tesseract v5.3.3.20231005
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
26namespace tesseract {
27
28class BLOCK; // forward decl
29
30ELISTIZEH(BLOCK)
31
33// page block
34{
35 friend class BLOCK_RECT_IT; // block iterator
36public:
37 BLOCK() : re_rotation_(1.0f, 0.0f), classify_rotation_(1.0f, 0.0f), skew_(1.0f, 0.0f) {}
38 BLOCK(const char *name,
39 bool prop,
40 int16_t kern,
41 int16_t space,
42 TDimension xmin,
43 TDimension ymin,
44 TDimension xmax,
45 TDimension ymax);
46
47 ~BLOCK() = default;
48
56 void set_stats(bool prop, int16_t kern, int16_t space, int16_t ch_pitch) {
57 proportional = prop;
58 kerning = static_cast<int8_t>(kern);
59 spacing = space;
60 pitch = ch_pitch;
61 }
63 void set_xheight(int32_t height) {
64 xheight = height;
65 }
67 void set_font_class(int16_t font) {
68 font_class = font;
69 }
71 bool prop() const {
72 return proportional;
73 }
74 bool right_to_left() const {
75 return right_to_left_;
76 }
78 right_to_left_ = value;
79 }
81 int32_t fixed_pitch() const {
82 return pitch;
83 }
85 int16_t kern() const {
86 return kerning;
87 }
89 int16_t font() const {
90 return font_class;
91 }
93 int16_t space() const {
94 return spacing;
95 }
97 const char *name() const {
98 return filename.c_str();
99 }
101 int32_t x_height() const {
102 return xheight;
103 }
104 float cell_over_xheight() const {
105 return cell_over_xheight_;
106 }
107 void set_cell_over_xheight(float ratio) {
108 cell_over_xheight_ = ratio;
109 }
111 ROW_LIST *row_list() {
112 return &rows;
113 }
114 // Compute the margins between the edges of each row and this block's
115 // polyblock, and store the results in the rows.
116 void compute_row_margins();
117
118 // get paragraphs
119 PARA_LIST *para_list() {
120 return &paras_;
121 }
123 C_BLOB_LIST *blob_list() {
124 return &c_blobs;
125 }
126 C_BLOB_LIST *reject_blobs() {
127 return &rej_blobs;
128 }
130 return re_rotation_; // How to transform coords back to image.
131 }
132 void set_re_rotation(const FCOORD &rotation) {
133 re_rotation_ = rotation;
134 }
136 return classify_rotation_; // Apply this before classifying.
137 }
138 void set_classify_rotation(const FCOORD &rotation) {
139 classify_rotation_ = rotation;
140 }
141 FCOORD skew() const {
142 return skew_; // Direction of true horizontal.
143 }
144 void set_skew(const FCOORD &skew) {
145 skew_ = skew;
146 }
147 const ICOORD &median_size() const {
148 return median_size_;
149 }
150 void set_median_size(int x, int y) {
151 median_size_.set_x(x);
152 median_size_.set_y(y);
153 }
154
155 Image render_mask(TBOX *mask_box) {
156 return pdblk.render_mask(re_rotation_, mask_box);
157 }
158
159 // Returns the bounding box including the desired combination of upper and
160 // lower noise/diacritic elements.
161 TBOX restricted_bounding_box(bool upper_dots, bool lower_dots) const;
162
163 // Reflects the polygon in the y-axis and recomputes the bounding_box.
164 // Does nothing to any contained rows/words/blobs etc.
165 void reflect_polygon_in_y_axis();
166
167 void rotate(const FCOORD &rotation);
168
170 void sort_rows();
171
173 void compress();
174
176 void check_pitch();
177
179 void compress(const ICOORD vec);
180
182 void print(FILE *fp, bool dump);
183
184 BLOCK &operator=(const BLOCK &source);
186
187private:
188 bool proportional = false;
189 bool right_to_left_ = false;
190 int8_t kerning = 0;
191 int16_t spacing = 0;
192 int16_t pitch = 0;
193 int16_t font_class = 0;
194 int32_t xheight = 0;
195 float cell_over_xheight_ = 0.0f;
196 std::string filename;
197 ROW_LIST rows;
198 PARA_LIST paras_;
199 C_BLOB_LIST c_blobs;
200 C_BLOB_LIST rej_blobs;
201 FCOORD re_rotation_;
202 FCOORD classify_rotation_;
203 FCOORD skew_;
204 ICOORD median_size_;
205};
206
207// A function to print segmentation stats for the given block list.
208void PrintSegmentationStats(BLOCK_LIST *block_list);
209
210// Extracts blobs fromo the given block list and adds them to the output list.
211// The block list must have been created by performing a page segmentation.
212void ExtractBlobsFromSegmentation(BLOCK_LIST *blocks, C_BLOB_LIST *output_blob_list);
213
214// Refreshes the words in the block_list by using blobs in the
215// new_blobs list.
216// Block list must have word segmentation in it.
217// It consumes the blobs provided in the new_blobs list. The blobs leftover in
218// the new_blobs list after the call weren't matched to any blobs of the words
219// in block list.
220// The output not_found_blobs is a list of blobs from the original segmentation
221// in the block_list for which no corresponding new blobs were found.
222void RefreshWordBlobsFromNewBlobs(BLOCK_LIST *block_list, C_BLOB_LIST *new_blobs,
223 C_BLOB_LIST *not_found_blobs);
224
225} // namespace tesseract
226
227#endif
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:803
int value
const double y
void RefreshWordBlobsFromNewBlobs(BLOCK_LIST *block_list, C_BLOB_LIST *new_blobs, C_BLOB_LIST *not_found_blobs)
Definition: ocrblock.cpp:474
void PrintSegmentationStats(BLOCK_LIST *block_list)
Definition: ocrblock.cpp:407
int16_t TDimension
Definition: tesstypes.h:32
void ExtractBlobsFromSegmentation(BLOCK_LIST *blocks, C_BLOB_LIST *output_blob_list)
Definition: ocrblock.cpp:440
const char * name() const
return filename
Definition: ocrblock.h:97
void set_font_class(int16_t font)
set font class
Definition: ocrblock.h:67
FCOORD classify_rotation() const
Definition: ocrblock.h:135
FCOORD re_rotation() const
Definition: ocrblock.h:129
float cell_over_xheight() const
Definition: ocrblock.h:104
C_BLOB_LIST * reject_blobs()
Definition: ocrblock.h:126
int32_t fixed_pitch() const
return pitch
Definition: ocrblock.h:81
void set_cell_over_xheight(float ratio)
Definition: ocrblock.h:107
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:185
bool prop() const
return proportional
Definition: ocrblock.h:71
void set_median_size(int x, int y)
Definition: ocrblock.h:150
bool right_to_left() const
Definition: ocrblock.h:74
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:111
void set_classify_rotation(const FCOORD &rotation)
Definition: ocrblock.h:138
PARA_LIST * para_list()
Definition: ocrblock.h:119
FCOORD skew() const
Definition: ocrblock.h:141
int16_t kern() const
return kerning
Definition: ocrblock.h:85
void set_skew(const FCOORD &skew)
Definition: ocrblock.h:144
void set_xheight(int32_t height)
set char size
Definition: ocrblock.h:63
int16_t font() const
return font class
Definition: ocrblock.h:89
const ICOORD & median_size() const
Definition: ocrblock.h:147
void set_stats(bool prop, int16_t kern, int16_t space, int16_t ch_pitch)
Definition: ocrblock.h:56
int16_t space() const
return spacing
Definition: ocrblock.h:93
int32_t x_height() const
return xheight
Definition: ocrblock.h:101
C_BLOB_LIST * blob_list()
get blobs
Definition: ocrblock.h:123
void set_right_to_left(bool value)
Definition: ocrblock.h:77
~BLOCK()=default
Image render_mask(TBOX *mask_box)
Definition: ocrblock.h:155
void set_re_rotation(const FCOORD &rotation)
Definition: ocrblock.h:132
page block
Definition: pdblock.h:33
integer coordinate
Definition: points.h:36
#define TESS_API
Definition: export.h:32