tesseract  5.0.0-alpha-619-ge9db
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 
26 class BLOCK; //forward decl
27 
29 class BLOCK:public ELIST_LINK
30 //page block
31 {
32  friend class BLOCK_RECT_IT; //block iterator
33  public:
34  BLOCK()
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.c_str ();
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  }
134  FCOORD re_rotation() const {
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  }
140  FCOORD classify_rotation() const {
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.
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);
190  PDBLK pdblk;
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.
213 void 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.
217 void 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.
228 void RefreshWordBlobsFromNewBlobs(BLOCK_LIST* block_list,
229  C_BLOB_LIST* new_blobs,
230  C_BLOB_LIST* not_found_blobs);
231 
232 #endif
PrintSegmentationStats
void PrintSegmentationStats(BLOCK_LIST *block_list)
Definition: ocrblock.cpp:403
ICOORD::set_x
void set_x(int16_t xin)
rewrite function
Definition: points.h:60
pdblock.h
BLOCK::skew
FCOORD skew() const
Definition: ocrblock.h:145
BLOCK::check_pitch
void check_pitch()
check proportional
Definition: ocrblock.cpp:163
BLOCK::set_xheight
void set_xheight(int32_t height)
set char size
Definition: ocrblock.h:67
BLOCK::row_list
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:115
ICOORD
integer coordinate
Definition: points.h:30
BLOCK::sort_rows
void sort_rows()
decreasing y order
Definition: ocrblock.cpp:111
BLOCK::set_right_to_left
void set_right_to_left(bool value)
Definition: ocrblock.h:81
BLOCK::name
const char * name() const
return filename
Definition: ocrblock.h:101
ExtractBlobsFromSegmentation
void ExtractBlobsFromSegmentation(BLOCK_LIST *blocks, C_BLOB_LIST *output_blob_list)
Definition: ocrblock.cpp:435
BLOCK::x_height
int32_t x_height() const
return xheight
Definition: ocrblock.h:105
STRING
Definition: strngs.h:45
BLOCK::font
int16_t font() const
return font class
Definition: ocrblock.h:93
BLOCK::render_mask
Pix * render_mask(TBOX *mask_box)
Definition: ocrblock.h:159
BLOCK::compute_row_margins
void compute_row_margins()
Definition: ocrblock.cpp:326
BLOCK::compress
void compress()
shrink white space
Definition: ocrblock.cpp:125
FCOORD
Definition: points.h:187
ICOORD::set_y
void set_y(int16_t yin)
rewrite function
Definition: points.h:64
ELISTIZEH
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:907
BLOCK::operator=
BLOCK & operator=(const BLOCK &source)
Definition: ocrblock.cpp:221
BLOCK::space
int16_t space() const
return spacing
Definition: ocrblock.h:97
BLOCK::right_to_left
bool right_to_left() const
Definition: ocrblock.h:78
BLOCK::set_median_size
void set_median_size(int x, int y)
Definition: ocrblock.h:154
BLOCK::set_re_rotation
void set_re_rotation(const FCOORD &rotation)
Definition: ocrblock.h:136
RefreshWordBlobsFromNewBlobs
void RefreshWordBlobsFromNewBlobs(BLOCK_LIST *block_list, C_BLOB_LIST *new_blobs, C_BLOB_LIST *not_found_blobs)
Definition: ocrblock.cpp:469
BLOCK::print
void print(FILE *fp, bool dump)
dump whole table
Definition: ocrblock.cpp:189
BLOCK
Definition: ocrblock.h:28
BLOCK::pdblk
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:189
STRING::c_str
const char * c_str() const
Definition: strngs.cpp:192
BLOCK::reflect_polygon_in_y_axis
void reflect_polygon_in_y_axis()
Definition: ocrblock.cpp:100
BLOCK::~BLOCK
~BLOCK()=default
BLOCK::BLOCK
BLOCK()
Definition: ocrblock.h:33
BLOCK::set_classify_rotation
void set_classify_rotation(const FCOORD &rotation)
Definition: ocrblock.h:142
BLOCK::cell_over_xheight
float cell_over_xheight() const
Definition: ocrblock.h:108
BLOCK::set_font_class
void set_font_class(int16_t font)
set font class
Definition: ocrblock.h:71
BLOCK::prop
bool prop() const
return proportional
Definition: ocrblock.h:75
BLOCK::para_list
PARA_LIST * para_list()
Definition: ocrblock.h:123
BLOCK::restricted_bounding_box
TBOX restricted_bounding_box(bool upper_dots, bool lower_dots) const
Definition: ocrblock.cpp:84
ocrpara.h
BLOCK::kern
int16_t kern() const
return kerning
Definition: ocrblock.h:89
PDBLK
page block
Definition: pdblock.h:30
BLOCK::median_size
const ICOORD & median_size() const
Definition: ocrblock.h:151
BLOCK::rotate
void rotate(const FCOORD &rotation)
Definition: ocrblock.cpp:77
ocrrow.h
BLOCK::set_cell_over_xheight
void set_cell_over_xheight(float ratio)
Definition: ocrblock.h:111
BLOCK::blob_list
C_BLOB_LIST * blob_list()
get blobs
Definition: ocrblock.h:127
BLOCK::classify_rotation
FCOORD classify_rotation() const
Definition: ocrblock.h:139
PDBLK::hand_poly
POLY_BLOCK * hand_poly
weird as well
Definition: pdblock.h:94
ELIST_LINK
Definition: elst.h:74
BLOCK::re_rotation
FCOORD re_rotation() const
Definition: ocrblock.h:133
BLOCK_RECT_IT
Definition: pdblock.h:101
BLOCK::reject_blobs
C_BLOB_LIST * reject_blobs()
Definition: ocrblock.h:130
BLOCK::set_skew
void set_skew(const FCOORD &skew)
Definition: ocrblock.h:148
BLOCK::fixed_pitch
int32_t fixed_pitch() const
return pitch
Definition: ocrblock.h:85
BLOCK::set_stats
void set_stats(bool prop, int16_t kern, int16_t space, int16_t ch_pitch)
Definition: ocrblock.h:57
TBOX
Definition: rect.h:33
PDBLK::render_mask
Pix * render_mask(const FCOORD &rerotation, TBOX *mask_box)
Definition: pdblock.cpp:126