tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
blkocc.h
1 /******************************************************************************
2  *
3  * File: blkocc.h (Formerly blockocc.h)
4  * Description: Block Occupancy routines
5  * Author: Chris Newton
6  * Created: Fri Nov 8
7  * Modified:
8  * Language: C++
9  * Package: N/A
10  * Status: Experimental (Do Not Distribute)
11  *
12  * (c) Copyright 1991, Hewlett-Packard Company.
13  ** Licensed under the Apache License, Version 2.0 (the "License");
14  ** you may not use this file except in compliance with the License.
15  ** You may obtain a copy of the License at
16  ** http://www.apache.org/licenses/LICENSE-2.0
17  ** Unless required by applicable law or agreed to in writing, software
18  ** distributed under the License is distributed on an "AS IS" BASIS,
19  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  ** See the License for the specific language governing permissions and
21  ** limitations under the License.
22  *
23  ******************************************************************************/
24 
25 #ifndef BLKOCC_H
26 #define BLKOCC_H
27 
28 #include "params.h"
29 #include "elst.h"
30 
31 /***************************************************************************
32 CLASS REGION_OCC
33 
34  The class REGION_OCC defines a section of outline which exists entirely
35  within a single region. The only data held is the min and max x limits of
36  the outline within the region.
37 
38  REGION_OCCs are held on lists, one list for each region. The lists are
39  built in sorted order of min x. Overlapping REGION_OCCs are not permitted on
40  a single list. An overlapping region to be added causes the existing region
41  to be extended. This extension may result in the following REGION_OCC on the
42  list overlapping the amended one. In this case the amended REGION_OCC is
43  further extended to include the range of the following one, so that the
44  following one can be deleted.
45 
46 ****************************************************************************/
47 
48 class REGION_OCC:public ELIST_LINK
49 {
50  public:
51  float min_x; //Lowest x in region
52  float max_x; //Highest x in region
53  int16_t region_type; //Type of crossing
54 
55  REGION_OCC() = default; // constructor used
56  // only in COPIER etc
57  REGION_OCC( //constructor
58  float min,
59  float max,
60  int16_t region) {
61  min_x = min;
62  max_x = max;
63  region_type = region;
64  }
65 };
66 
67 ELISTIZEH (REGION_OCC)
68 #define RANGE_IN_BAND(band_max, band_min, range_max, range_min) \
69 (((range_min) >= (band_min)) && ((range_max) < (band_max)))
70 /************************************************************************
71 Adapted from the following procedure so that it can be used in the bands
72 class in an include file...
73 
74 BOOL8 range_in_band[
75  range within band?
76 int16_t band_max,
77 int16_t band_min,
78 int16_t range_max,
79 int16_t range_min]
80 {
81  if ((range_min >= band_min) && (range_max < band_max))
82  return TRUE;
83  else
84  return FALSE;
85 }
86 ***********************************************************************/
87 #define RANGE_OVERLAPS_BAND(band_max, band_min, range_max, range_min) \
88 (((range_max) >= (band_min)) && ((range_min) < (band_max)))
89 /************************************************************************
90 Adapted from the following procedure so that it can be used in the bands
91 class in an include file...
92 
93 BOOL8 range_overlaps_band[
94  range crosses band?
95 int16_t band_max,
96 int16_t band_min,
97 int16_t range_max,
98 int16_t range_min]
99 {
100  if ((range_max >= band_min) && (range_min < band_max))
101  return TRUE;
102  else
103  return FALSE;
104 }
105 ***********************************************************************/
106 /**********************************************************************
107  Bands
108  -----
109 
110  BAND 4
111 --------------------------------
112  BAND 3
113 --------------------------------
114 
115  BAND 2
116 
117 --------------------------------
118 
119  BAND 1
120 
121 Band 0 is the dot band
122 
123 Each band has an error margin above and below. An outline is not considered to
124 have significantly changed bands until it has moved out of the error margin.
125 *************************************************************************/
126 class BAND
127 {
128  public:
129  int16_t max_max; //upper max
130  int16_t max; //nominal max
131  int16_t min_max; //lower max
132  int16_t max_min; //upper min
133  int16_t min; //nominal min
134  int16_t min_min; //lower min
135 
136  BAND() = default; // constructor
137 
138  void set( // initialise a band
139  int16_t new_max_max, // upper max
140  int16_t new_max, // new nominal max
141  int16_t new_min_max, // new lower max
142  int16_t new_max_min, // new upper min
143  int16_t new_min, // new nominal min
144  int16_t new_min_min) { // new lower min
145  max_max = new_max_max;
146  max = new_max;
147  min_max = new_min_max;
148  max_min = new_max_min;
149  min = new_min;
150  min_min = new_min_min;
151  }
152 
153  bool in_minimal( //in minimal limits?
154  float y) { //y value
155  return (y >= max_min) && (y < min_max);
156  }
157 
158  bool in_nominal( //in nominal limits?
159  float y) { //y value
160  return (y >= min) && (y < max);
161  }
162 
163  bool in_maximal( //in maximal limits?
164  float y) { //y value
165  return (y >= min_min) && (y < max_max);
166  }
167 
168  //overlaps min limits?
169  bool range_overlaps_minimal(float y1, //one range limit
170  float y2) { //other range limit
171  if (y1 > y2)
172  return RANGE_OVERLAPS_BAND (min_max, max_min, y1, y2);
173  else
174  return RANGE_OVERLAPS_BAND (min_max, max_min, y2, y1);
175  }
176 
177  //overlaps nom limits?
178  bool range_overlaps_nominal(float y1, //one range limit
179  float y2) { //other range limit
180  if (y1 > y2)
181  return RANGE_OVERLAPS_BAND (max, min, y1, y2);
182  else
183  return RANGE_OVERLAPS_BAND (max, min, y2, y1);
184  }
185 
186  //overlaps max limits?
187  bool range_overlaps_maximal(float y1, //one range limit
188  float y2) { //other range limit
189  if (y1 > y2)
190  return RANGE_OVERLAPS_BAND (max_max, min_min, y1, y2);
191  else
192  return RANGE_OVERLAPS_BAND (max_max, min_min, y2, y1);
193  }
194 
195  bool range_in_minimal( //within min limits?
196  float y1, //one range limit
197  float y2) { //other range limit
198  if (y1 > y2)
199  return RANGE_IN_BAND (min_max, max_min, y1, y2);
200  else
201  return RANGE_IN_BAND (min_max, max_min, y2, y1);
202  }
203 
204  bool range_in_nominal( //within nom limits?
205  float y1, //one range limit
206  float y2) { //other range limit
207  if (y1 > y2)
208  return RANGE_IN_BAND (max, min, y1, y2);
209  else
210  return RANGE_IN_BAND (max, min, y2, y1);
211  }
212 
213  bool range_in_maximal( //within max limits?
214  float y1, //one range limit
215  float y2) { //other range limit
216  if (y1 > y2)
217  return RANGE_IN_BAND (max_max, min_min, y1, y2);
218  else
219  return RANGE_IN_BAND (max_max, min_min, y2, y1);
220  }
221 };
222 
223 /* Standard positions */
224 
225 #define MAX_NUM_BANDS 5
226 #define UNDEFINED_BAND 99
227 #define NO_LOWER_LIMIT -9999
228 #define NO_UPPER_LIMIT 9999
229 
230 #define DOT_BAND 0
231 
232 /* Special occupancy code emitted for the 0 region at the end of a word */
233 
234 #define END_OF_WERD_CODE 255
235 
236 extern BOOL_VAR_H (blockocc_show_result, FALSE, "Show intermediate results");
237 extern INT_VAR_H (blockocc_desc_height, 0,
238 "Descender height after normalisation");
239 extern INT_VAR_H (blockocc_asc_height, 255,
240 "Ascender height after normalisation");
241 extern INT_VAR_H (blockocc_band_count, 4, "Number of bands used");
242 extern double_VAR_H (textord_underline_threshold, 0.9,
243 "Fraction of width occupied");
244 
245 bool test_underline( //look for underlines
246  bool testing_on, //drawing blob
247  C_BLOB* blob, //blob to test
248  int16_t baseline, //coords of baseline
249  int16_t xheight //height of line
250 );
251 
252 #endif
bool range_overlaps_minimal(float y1, float y2)
Definition: blkocc.h:169
REGION_OCC()=default
bool range_overlaps_maximal(float y1, float y2)
Definition: blkocc.h:187
int16_t max
Definition: blkocc.h:130
bool in_minimal(float y)
Definition: blkocc.h:153
int16_t min
Definition: blkocc.h:133
int16_t max_min
Definition: blkocc.h:132
bool range_in_minimal(float y1, float y2)
Definition: blkocc.h:195
Definition: blkocc.h:48
int16_t min_min
Definition: blkocc.h:134
bool range_in_nominal(float y1, float y2)
Definition: blkocc.h:204
bool range_overlaps_nominal(float y1, float y2)
Definition: blkocc.h:178
int16_t max_max
Definition: blkocc.h:129
Definition: blkocc.h:126
float max_x
Definition: blkocc.h:52
int16_t min_max
Definition: blkocc.h:131
REGION_OCC(float min, float max, int16_t region)
Definition: blkocc.h:57
bool range_in_maximal(float y1, float y2)
Definition: blkocc.h:213
Definition: stepblob.h:37
bool in_nominal(float y)
Definition: blkocc.h:158
float min_x
Definition: blkocc.h:51
bool in_maximal(float y)
Definition: blkocc.h:163
int16_t region_type
Definition: blkocc.h:53