Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cube_line_segmenter.h
Go to the documentation of this file.
1 /**********************************************************************
2 * File: cube_page_segmenter.h
3 * Description: Declaration of the Cube Page Segmenter Class
4 * Author: Ahmad Abdulkader
5 * Created: 2007
6 *
7 * (C) Copyright 2008, Google Inc.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 **********************************************************************/
19
20 // TODO(ahmadab)
21 // This is really a makeshift line segmenter that works well for Arabic
22 // This should eventually be replaced by Ray Smith's Page segmenter
23 // There are lots of magic numbers below that were determined empirically
24 // but not thoroughly tested
25
26 #ifndef CUBE_LINE_SEGMENTER_H
27 #define CUBE_LINE_SEGMENTER_H
28
29 #include "cube_reco_context.h"
30 #include "allheaders.h"
31
32 namespace tesseract {
33
34 class CubeLineSegmenter {
35 public:
36 CubeLineSegmenter(CubeRecoContext *cntxt, Pix *img);
37 ~CubeLineSegmenter();
38
39 // Accessor functions
40 Pix *PostProcessedImage() {
41 if (init_ == false && Init() == false) {
42 return NULL;
43 }
44 return img_;
45 }
46 int ColumnCnt() {
47 if (init_ == false && Init() == false) {
48 return NULL;
49 }
50 return columns_->n;
51 }
52 Box *Column(int col) {
53 if (init_ == false && Init() == false) {
54 return NULL;
55 }
56
57 return columns_->boxa->box[col];
58 }
59 int LineCnt() {
60 if (init_ == false && Init() == false) {
61 return NULL;
62 }
63
64 return line_cnt_;
65 }
66 Pixa *ConComps() {
67 if (init_ == false && Init() == false) {
68 return NULL;
69 }
70
71 return con_comps_;
72 }
73 Pixaa *Columns() {
74 if (init_ == false && Init() == false) {
75 return NULL;
76 }
77
78 return columns_;
79 }
80 inline double AlefHgtEst() { return est_alef_hgt_; }
81 inline double DotHgtEst() { return est_dot_hgt_; }
82 Pix *Line(int line, Box **line_box);
83
84 private:
85 static const float kMinValidLineHgtRatio;
86 static const int kLineSepMorphMinHgt;
87 static const int kHgtBins;
88 static const int kMaxConnCompHgt;
89 static const int kMaxConnCompWid;
90 static const int kMaxHorzAspectRatio;
91 static const int kMaxVertAspectRatio;
92 static const int kMinWid;
93 static const int kMinHgt;
94 static const double kMaxValidLineRatio;
95
96 // Cube Reco context
97 CubeRecoContext *cntxt_;
98 // Original image
99 Pix *orig_img_;
100 // Post processed image
101 Pix *img_;
102 // Init flag
103 bool init_;
104 // Output Line and column info
105 int line_cnt_;
106 Pixaa *columns_;
107 Pixa *con_comps_;
108 Pixa *lines_pixa_;
109 // Estimates for sizes of ALEF and DOT needed for Arabic analysis
110 double est_alef_hgt_;
111 double est_dot_hgt_;
112
113 // Init the page analysis
114 bool Init();
115 // Performs line segmentation
116 bool LineSegment();
117 // Cleanup function
118 Pix *CleanUp(Pix *pix);
119 // compute validity ratio for a line
120 double ValidityRatio(Pix *line_mask_pix, Box *line_box);
121 // validate line
122 bool ValidLine(Pix *line_mask_pix, Box *line_box);
123 // split a line continuously until valid or fail
124 Pixa *SplitLine(Pix *line_mask_pix, Box *line_box);
125 // do a desperate attempt at cracking lines
126 Pixa *CrackLine(Pix *line_mask_pix, Box *line_box);
127 Pixa *CrackLine(Pix *line_mask_pix, Box *line_box, int line_cnt);
128 // Checks of a line is too small
129 bool SmallLine(Box *line_box);
130 // Compute the connected components in a line
131 Boxa * ComputeLineConComps(Pix *line_mask_pix, Box *line_box,
132 Pixa **con_comps_pixa);
133 // create a union of two arbitrary pix
134 Pix *PixUnion(Pix *dest_pix, Box *dest_box, Pix *src_pix, Box *src_box);
135 // create a union of a pixa subset
136 Pix *Pixa2Pix(Pixa *pixa, Box **dest_box, int start_pix, int pix_cnt);
137 // create a union of a pixa
138 Pix *Pixa2Pix(Pixa *pixa, Box **dest_box);
139 // merges a number of lines into one line given a bounding box and a mask
140 bool MergeLine(Pix *line_mask_pix, Box *line_box,
141 Pixa *lines, Boxaa *lines_con_comps);
142 // Creates new set of lines from the computed columns
143 bool AddLines(Pixa *lines);
144 // Estimate the parameters of the font(s) used in the page
145 bool EstimateFontParams();
146 // perform a vertical Closing with the specified threshold
147 // returning the resulting conn comps as a pixa
148 Pixa *VerticalClosing(Pix *pix, int thresold, Boxa **boxa);
149 // Index the specific pixa using RTL reading order
150 int *IndexRTL(Pixa *pixa);
151 // Implements a rudimentary page & line segmenter
152 bool FindLines();
153 };
154 }
155
156 #endif // CUBE_LINE_SEGMENTER_H