tesseract
3.03
|
00001 /****************************************************************************** 00002 * 00003 * File: blkocc.h (Formerly blockocc.h) 00004 * Description: Block Occupancy routines 00005 * Author: Chris Newton 00006 * Created: Fri Nov 8 00007 * Modified: 00008 * Language: C++ 00009 * Package: N/A 00010 * Status: Experimental (Do Not Distribute) 00011 * 00012 * (c) Copyright 1991, Hewlett-Packard Company. 00013 ** Licensed under the Apache License, Version 2.0 (the "License"); 00014 ** you may not use this file except in compliance with the License. 00015 ** You may obtain a copy of the License at 00016 ** http://www.apache.org/licenses/LICENSE-2.0 00017 ** Unless required by applicable law or agreed to in writing, software 00018 ** distributed under the License is distributed on an "AS IS" BASIS, 00019 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 ** See the License for the specific language governing permissions and 00021 ** limitations under the License. 00022 * 00023 ******************************************************************************/ 00024 00025 #ifndef BLKOCC_H 00026 #define BLKOCC_H 00027 00028 #include "params.h" 00029 #include "elst.h" 00030 00031 /*************************************************************************** 00032 CLASS REGION_OCC 00033 00034 The class REGION_OCC defines a section of outline which exists entirely 00035 within a single region. The only data held is the min and max x limits of 00036 the outline within the region. 00037 00038 REGION_OCCs are held on lists, one list for each region. The lists are 00039 built in sorted order of min x. Overlapping REGION_OCCs are not permitted on 00040 a single list. An overlapping region to be added causes the existing region 00041 to be extended. This extension may result in the following REGION_OCC on the 00042 list overlapping the ammended one. In this case the ammended REGION_OCC is 00043 further extended to include the range of the following one, so that the 00044 following one can be deleted. 00045 00046 ****************************************************************************/ 00047 00048 class REGION_OCC:public ELIST_LINK 00049 { 00050 public: 00051 float min_x; //Lowest x in region 00052 float max_x; //Highest x in region 00053 inT16 region_type; //Type of crossing 00054 00055 REGION_OCC() { 00056 }; //constructor used 00057 //only in COPIER etc 00058 REGION_OCC( //constructor 00059 float min, 00060 float max, 00061 inT16 region) { 00062 min_x = min; 00063 max_x = max; 00064 region_type = region; 00065 } 00066 }; 00067 00068 ELISTIZEH (REGION_OCC) 00069 #define RANGE_IN_BAND( band_max, band_min, range_max, range_min ) \ 00070 ( ((range_min) >= (band_min)) && ((range_max) < (band_max)) ) ? TRUE : FALSE 00071 /************************************************************************ 00072 Adapted from the following procedure so that it can be used in the bands 00073 class in an include file... 00074 00075 BOOL8 range_in_band[ 00076 range within band? 00077 inT16 band_max, 00078 inT16 band_min, 00079 inT16 range_max, 00080 inT16 range_min] 00081 { 00082 if ( (range_min >= band_min) && (range_max < band_max) ) 00083 return TRUE; 00084 else 00085 return FALSE; 00086 } 00087 ***********************************************************************/ 00088 #define RANGE_OVERLAPS_BAND( band_max, band_min, range_max, range_min ) \ 00089 ( ((range_max) >= (band_min)) && ((range_min) < (band_max)) ) ? TRUE : FALSE 00090 /************************************************************************ 00091 Adapted from the following procedure so that it can be used in the bands 00092 class in an include file... 00093 00094 BOOL8 range_overlaps_band[ 00095 range crosses band? 00096 inT16 band_max, 00097 inT16 band_min, 00098 inT16 range_max, 00099 inT16 range_min] 00100 { 00101 if ( (range_max >= band_min) && (range_min < band_max) ) 00102 return TRUE; 00103 else 00104 return FALSE; 00105 } 00106 ***********************************************************************/ 00107 /********************************************************************** 00108 Bands 00109 ----- 00110 00111 BAND 4 00112 -------------------------------- 00113 BAND 3 00114 -------------------------------- 00115 00116 BAND 2 00117 00118 -------------------------------- 00119 00120 BAND 1 00121 00122 Band 0 is the dot band 00123 00124 Each band has an error margin above and below. An outline is not considered to 00125 have significantly changed bands until it has moved out of the error margin. 00126 *************************************************************************/ 00127 class BAND 00128 { 00129 public: 00130 inT16 max_max; //upper max 00131 inT16 max; //nominal max 00132 inT16 min_max; //lower max 00133 inT16 max_min; //upper min 00134 inT16 min; //nominal min 00135 inT16 min_min; //lower min 00136 00137 BAND() { 00138 } // constructor 00139 00140 void set( // initialise a band 00141 inT16 new_max_max, // upper max 00142 inT16 new_max, // new nominal max 00143 inT16 new_min_max, // new lower max 00144 inT16 new_max_min, // new upper min 00145 inT16 new_min, // new nominal min 00146 inT16 new_min_min) { // new lower min 00147 max_max = new_max_max; 00148 max = new_max; 00149 min_max = new_min_max; 00150 max_min = new_max_min; 00151 min = new_min; 00152 min_min = new_min_min; 00153 } 00154 00155 BOOL8 in_minimal( //in minimal limits? 00156 float y) { //y value 00157 if ((y >= max_min) && (y < min_max)) 00158 return TRUE; 00159 else 00160 return FALSE; 00161 } 00162 00163 BOOL8 in_nominal( //in nominal limits? 00164 float y) { //y value 00165 if ((y >= min) && (y < max)) 00166 return TRUE; 00167 else 00168 return FALSE; 00169 } 00170 00171 BOOL8 in_maximal( //in maximal limits? 00172 float y) { //y value 00173 if ((y >= min_min) && (y < max_max)) 00174 return TRUE; 00175 else 00176 return FALSE; 00177 } 00178 00179 //overlaps min limits? 00180 BOOL8 range_overlaps_minimal(float y1, //one range limit 00181 float y2) { //other range limit 00182 if (y1 > y2) 00183 return RANGE_OVERLAPS_BAND (min_max, max_min, y1, y2); 00184 else 00185 return RANGE_OVERLAPS_BAND (min_max, max_min, y2, y1); 00186 } 00187 00188 //overlaps nom limits? 00189 BOOL8 range_overlaps_nominal(float y1, //one range limit 00190 float y2) { //other range limit 00191 if (y1 > y2) 00192 return RANGE_OVERLAPS_BAND (max, min, y1, y2); 00193 else 00194 return RANGE_OVERLAPS_BAND (max, min, y2, y1); 00195 } 00196 00197 //overlaps max limits? 00198 BOOL8 range_overlaps_maximal(float y1, //one range limit 00199 float y2) { //other range limit 00200 if (y1 > y2) 00201 return RANGE_OVERLAPS_BAND (max_max, min_min, y1, y2); 00202 else 00203 return RANGE_OVERLAPS_BAND (max_max, min_min, y2, y1); 00204 } 00205 00206 BOOL8 range_in_minimal( //within min limits? 00207 float y1, //one range limit 00208 float y2) { //other range limit 00209 if (y1 > y2) 00210 return RANGE_IN_BAND (min_max, max_min, y1, y2); 00211 else 00212 return RANGE_IN_BAND (min_max, max_min, y2, y1); 00213 } 00214 00215 BOOL8 range_in_nominal( //within nom limits? 00216 float y1, //one range limit 00217 float y2) { //other range limit 00218 if (y1 > y2) 00219 return RANGE_IN_BAND (max, min, y1, y2); 00220 else 00221 return RANGE_IN_BAND (max, min, y2, y1); 00222 } 00223 00224 BOOL8 range_in_maximal( //within max limits? 00225 float y1, //one range limit 00226 float y2) { //other range limit 00227 if (y1 > y2) 00228 return RANGE_IN_BAND (max_max, min_min, y1, y2); 00229 else 00230 return RANGE_IN_BAND (max_max, min_min, y2, y1); 00231 } 00232 }; 00233 00234 /* Standard positions */ 00235 00236 #define MAX_NUM_BANDS 5 00237 #define UNDEFINED_BAND 99 00238 #define NO_LOWER_LIMIT -9999 00239 #define NO_UPPER_LIMIT 9999 00240 00241 #define DOT_BAND 0 00242 00243 /* Special occupancy code emitted for the 0 region at the end of a word */ 00244 00245 #define END_OF_WERD_CODE 255 00246 00247 extern BOOL_VAR_H (blockocc_show_result, FALSE, "Show intermediate results"); 00248 extern INT_VAR_H (blockocc_desc_height, 0, 00249 "Descender height after normalisation"); 00250 extern INT_VAR_H (blockocc_asc_height, 255, 00251 "Ascender height after normalisation"); 00252 extern INT_VAR_H (blockocc_band_count, 4, "Number of bands used"); 00253 extern double_VAR_H (textord_underline_threshold, 0.9, 00254 "Fraction of width occupied"); 00255 00256 BOOL8 test_underline( //look for underlines 00257 BOOL8 testing_on, //drawing blob 00258 C_BLOB *blob, //blob to test 00259 inT16 baseline, //coords of baseline 00260 inT16 xheight //height of line 00261 ); 00262 00263 #endif