tesseract  4.1.0
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:
35  : re_rotation_(1.0f, 0.0f),
36  classify_rotation_(1.0f, 0.0f),
37  skew_(1.0f, 0.0f) {
38  right_to_left_ = false;
39  pdblk.hand_poly = nullptr;
40  }
41  BLOCK(const char *name,
42  bool prop,
43  int16_t kern,
44  int16_t space,
45  int16_t xmin,
46  int16_t ymin,
47  int16_t xmax,
48  int16_t ymax);
49 
50  ~BLOCK () = default;
51 
59  void set_stats(bool prop,
60  int16_t kern,
61  int16_t space,
62  int16_t ch_pitch) {
63  proportional = prop;
64  kerning = static_cast<int8_t>(kern);
65  spacing = space;
66  pitch = ch_pitch;
67  }
69  void set_xheight(int32_t height) {
70  xheight = height;
71  }
73  void set_font_class(int16_t font) {
74  font_class = font;
75  }
77  bool prop() const {
78  return proportional;
79  }
80  bool right_to_left() const {
81  return right_to_left_;
82  }
83  void set_right_to_left(bool value) {
84  right_to_left_ = value;
85  }
87  int32_t fixed_pitch() const {
88  return pitch;
89  }
91  int16_t kern() const {
92  return kerning;
93  }
95  int16_t font() const {
96  return font_class;
97  }
99  int16_t space() const {
100  return spacing;
101  }
103  const char *name() const {
104  return filename.string ();
105  }
107  int32_t x_height() const {
108  return xheight;
109  }
110  float cell_over_xheight() const {
111  return cell_over_xheight_;
112  }
113  void set_cell_over_xheight(float ratio) {
114  cell_over_xheight_ = ratio;
115  }
117  ROW_LIST *row_list() {
118  return &rows;
119  }
120  // Compute the margins between the edges of each row and this block's
121  // polyblock, and store the results in the rows.
122  void compute_row_margins();
123 
124  // get paragraphs
125  PARA_LIST *para_list() {
126  return &paras_;
127  }
129  C_BLOB_LIST *blob_list() {
130  return &c_blobs;
131  }
132  C_BLOB_LIST *reject_blobs() {
133  return &rej_blobs;
134  }
135  FCOORD re_rotation() const {
136  return re_rotation_; // How to transform coords back to image.
137  }
138  void set_re_rotation(const FCOORD& rotation) {
139  re_rotation_ = rotation;
140  }
142  return classify_rotation_; // Apply this before classifying.
143  }
144  void set_classify_rotation(const FCOORD& rotation) {
145  classify_rotation_ = rotation;
146  }
147  FCOORD skew() const {
148  return skew_; // Direction of true horizontal.
149  }
150  void set_skew(const FCOORD& skew) {
151  skew_ = skew;
152  }
153  const ICOORD& median_size() const {
154  return median_size_;
155  }
156  void set_median_size(int x, int y) {
157  median_size_.set_x(x);
158  median_size_.set_y(y);
159  }
160 
161  Pix* render_mask(TBOX* mask_box) {
162  return pdblk.render_mask(re_rotation_, mask_box);
163  }
164 
165  // Returns the bounding box including the desired combination of upper and
166  // lower noise/diacritic elements.
167  TBOX restricted_bounding_box(bool upper_dots, bool lower_dots) const;
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, bool dump);
189 
190  BLOCK& operator=(const BLOCK & source);
192 
193  private:
194  bool proportional;
195  bool right_to_left_;
196  int8_t kerning;
197  int16_t spacing;
198  int16_t pitch;
199  int16_t font_class;
200  int32_t xheight;
201  float cell_over_xheight_;
202  STRING filename;
203  ROW_LIST rows;
204  PARA_LIST paras_;
205  C_BLOB_LIST c_blobs;
206  C_BLOB_LIST rej_blobs;
207  FCOORD re_rotation_;
208  FCOORD classify_rotation_;
209  FCOORD skew_;
210  ICOORD median_size_;
211 };
212 
213 // A function to print segmentation stats for the given block list.
214 void PrintSegmentationStats(BLOCK_LIST* block_list);
215 
216 // Extracts blobs fromo the given block list and adds them to the output list.
217 // The block list must have been created by performing a page segmentation.
218 void ExtractBlobsFromSegmentation(BLOCK_LIST* blocks,
219  C_BLOB_LIST* output_blob_list);
220 
221 // Refreshes the words in the block_list by using blobs in the
222 // new_blobs list.
223 // Block list must have word segmentation in it.
224 // It consumes the blobs provided in the new_blobs list. The blobs leftover in
225 // the new_blobs list after the call weren't matched to any blobs of the words
226 // in block list.
227 // The output not_found_blobs is a list of blobs from the original segmentation
228 // in the block_list for which no corresponding new blobs were found.
229 void RefreshWordBlobsFromNewBlobs(BLOCK_LIST* block_list,
230  C_BLOB_LIST* new_blobs,
231  C_BLOB_LIST* not_found_blobs);
232 
233 #endif
void RefreshWordBlobsFromNewBlobs(BLOCK_LIST *block_list, C_BLOB_LIST *new_blobs, C_BLOB_LIST *not_found_blobs)
Definition: ocrblock.cpp:474
Definition: rect.h:34
FCOORD re_rotation() const
Definition: ocrblock.h:135
Definition: strngs.h:45
Definition: points.h:188
FCOORD classify_rotation() const
Definition: ocrblock.h:141
bool right_to_left() const
Definition: ocrblock.h:80
page block
Definition: pdblock.h:32
void set_right_to_left(bool value)
Definition: ocrblock.h:83
integer coordinate
Definition: points.h:31
bool prop() const
return proportional
Definition: ocrblock.h:77
BLOCK()
Definition: ocrblock.h:34
void ExtractBlobsFromSegmentation(BLOCK_LIST *blocks, C_BLOB_LIST *output_blob_list)
Definition: ocrblock.cpp:439
void set_skew(const FCOORD &skew)
Definition: ocrblock.h:150
int16_t space() const
return spacing
Definition: ocrblock.h:99
Pix * render_mask(TBOX *mask_box)
Definition: ocrblock.h:161
void set_stats(bool prop, int16_t kern, int16_t space, int16_t ch_pitch)
Definition: ocrblock.h:59
void set_median_size(int x, int y)
Definition: ocrblock.h:156
void set_cell_over_xheight(float ratio)
Definition: ocrblock.h:113
C_BLOB_LIST * reject_blobs()
Definition: ocrblock.h:132
int32_t fixed_pitch() const
return pitch
Definition: ocrblock.h:87
int32_t x_height() const
return xheight
Definition: ocrblock.h:107
const char * name() const
return filename
Definition: ocrblock.h:103
void set_classify_rotation(const FCOORD &rotation)
Definition: ocrblock.h:144
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:191
int16_t font() const
return font class
Definition: ocrblock.h:95
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:942
void set_re_rotation(const FCOORD &rotation)
Definition: ocrblock.h:138
FCOORD skew() const
Definition: ocrblock.h:147
PARA_LIST * para_list()
Definition: ocrblock.h:125
void set_font_class(int16_t font)
set font class
Definition: ocrblock.h:73
float cell_over_xheight() const
Definition: ocrblock.h:110
void PrintSegmentationStats(BLOCK_LIST *block_list)
Definition: ocrblock.cpp:406
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:117
C_BLOB_LIST * blob_list()
get blobs
Definition: ocrblock.h:129
void set_xheight(int32_t height)
set char size
Definition: ocrblock.h:69
int16_t kern() const
return kerning
Definition: ocrblock.h:91
Definition: ocrblock.h:29
const ICOORD & median_size() const
Definition: ocrblock.h:153