tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
oldbasel.h
1 /**********************************************************************
2  * File: oldbasel.h (Formerly oldbl.h)
3  * Description: A re-implementation of the old baseline algorithm.
4  * Author: Ray Smith
5  *
6  * (C) Copyright 1993, 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 OLDBASEL_H
20 #define OLDBASEL_H
21 
22 #include "params.h"
23 #include "blobbox.h"
24 
25 extern BOOL_VAR_H (textord_really_old_xheight, FALSE,
26 "Use original wiseowl xheight");
27 extern BOOL_VAR_H (textord_oldbl_debug, FALSE,
28 "Debug old baseline generation");
29 extern BOOL_VAR_H (textord_debug_baselines, FALSE,
30 "Debug baseline generation");
31 extern BOOL_VAR_H (textord_oldbl_paradef, TRUE, "Use para default mechanism");
32 extern BOOL_VAR_H (textord_oldbl_split_splines, TRUE,
33 "Split stepped splines");
34 extern BOOL_VAR_H (textord_oldbl_merge_parts, TRUE,
35 "Merge suspect partitions");
36 extern BOOL_VAR_H (oldbl_xhfix, FALSE,
37 "Fix bug in modes threshold for xheights");
38 extern INT_VAR_H (oldbl_holed_losscount, 10,
39 "Max lost before fallback line used");
40 extern double_VAR_H (oldbl_dot_error_size, 1.26, "Max aspect ratio of a dot");
41 extern double_VAR_H (textord_oldbl_jumplimit, 0.15,
42 "X fraction for new partition");
43 int get_blob_coords( //get boxes
44  TO_ROW* row, //row to use
45  int32_t lineheight, //block level
46  TBOX* blobcoords, //output boxes
47  bool& holed_line, //lost a lot of blobs
48  int& outcount //no of real blobs
49 );
50 void make_first_baseline ( //initial approximation
51 TBOX blobcoords[], /*blob bounding boxes */
52 int blobcount, /*no of blobcoords */
53 int xcoords[], /*coords for spline */
54 int ycoords[], /*approximator */
55 QSPLINE * spline, /*initial spline */
56 QSPLINE * baseline, /*output spline */
57 float jumplimit /*guess half descenders */
58 );
59 void make_holed_baseline ( //initial approximation
60 TBOX blobcoords[], /*blob bounding boxes */
61 int blobcount, /*no of blobcoords */
62 QSPLINE * spline, /*initial spline */
63 QSPLINE * baseline, /*output spline */
64 float gradient //of line
65 );
66 int partition_line ( //partition blobs
67 TBOX blobcoords[], //bounding boxes
68 int blobcount, /*no of blobs on row */
69 int *numparts, /*number of partitions */
70 char partids[], /*partition no of each blob */
71 int partsizes[], /*no in each partition */
72 QSPLINE * spline, /*curve to fit to */
73 float jumplimit, /*allowed delta change */
74 float ydiffs[] /*diff from spline */
75 );
76 void merge_oldbl_parts ( //partition blobs
77 TBOX blobcoords[], //bounding boxes
78 int blobcount, /*no of blobs on row */
79 char partids[], /*partition no of each blob */
80 int partsizes[], /*no in each partition */
81 int biggestpart, //major partition
82 float jumplimit /*allowed delta change */
83 );
84 int get_ydiffs ( //evaluate differences
85 TBOX blobcoords[], //bounding boxes
86 int blobcount, /*no of blobs */
87 QSPLINE * spline, /*approximating spline */
88 float ydiffs[] /*output */
89 );
90 int choose_partition ( //select partition
91 float diff, /*diff from spline */
92 float partdiffs[], /*diff on all parts */
93 int lastpart, /*last assigned partition */
94 float jumplimit, /*new part threshold */
95 float* drift,
96 float* last_delta,
97 int *partcount /*no of partitions */
98 );
99 int partition_coords ( //find relevant coords
100 TBOX blobcoords[], //bounding boxes
101 int blobcount, /*no of blobs in row */
102 char partids[], /*partition no of each blob */
103 int bestpart, /*best new partition */
104 int xcoords[], /*points to work on */
105 int ycoords[] /*points to work on */
106 );
107 int segment_spline ( //make xstarts
108 TBOX blobcoords[], //boundign boxes
109 int blobcount, /*no of blobs in row */
110 int xcoords[], /*points to work on */
111 int ycoords[], /*points to work on */
112 int degree, int pointcount, /*no of points */
113 int xstarts[] //result
114 );
115 bool split_stepped_spline( //make xstarts
116  QSPLINE* baseline, //current shot
117  float jumplimit, //max step function
118  int* xcoords, /*points to work on */
119  int* xstarts, //result
120  int& segments //no of segments
121 );
122 void insert_spline_point ( //get descenders
123 int xstarts[], //starts to shuffle
124 int segment, //insertion pt
125 int coord1, //coords to add
126 int coord2, int &segments //total segments
127 );
128 void find_lesser_parts ( //get descenders
129 TO_ROW * row, //row to process
130 TBOX blobcoords[], //bounding boxes
131 int blobcount, /*no of blobs */
132 char partids[], /*partition of each blob */
133 int partsizes[], /*size of each part */
134 int partcount, /*no of partitions */
135 int bestpart /*biggest partition */
136 );
137 
138 void old_first_xheight ( //the wiseowl way
139 TO_ROW * row, /*current row */
140 TBOX blobcoords[], /*blob bounding boxes */
141 int initialheight, //initial guess
142 int blobcount, /*blobs in blobcoords */
143 QSPLINE * baseline, /*established */
144 float jumplimit /*min ascender height */
145 );
146 
147 void make_first_xheight ( //find xheight
148 TO_ROW * row, /*current row */
149 TBOX blobcoords[], /*blob bounding boxes */
150 int lineheight, //initial guess
151 int init_lineheight, //block level guess
152 int blobcount, /*blobs in blobcoords */
153 QSPLINE * baseline, /*established */
154 float jumplimit /*min ascender height */
155 );
156 
157 int *make_height_array ( //get array of heights
158 TBOX blobcoords[], /*blob bounding boxes */
159 int blobcount, /*blobs in blobcoords */
160 QSPLINE * baseline /*established */
161 );
162 
163 void find_top_modes ( //get modes
164 STATS * stats, //stats to hack
165 int statnum, //no of piles
166 int modelist[], int modenum //no of modes to get
167 );
168 
169 void pick_x_height(TO_ROW * row, //row to do
170 int modelist[],
171 int lefts[], int rights[],
172 STATS * heightstat,
173 int mode_threshold);
174 #endif
Definition: rect.h:34
Definition: quspline.h:32
Definition: blobbox.h:556
Definition: statistc.h:33