tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
linefind.h
1 // File: linefind.h
3 // Description: Class to find vertical lines in an image and create
4 // a corresponding list of empty blobs.
5 // Author: Ray Smith
6 // Created: Thu Mar 20 09:49:01 PDT 2008
7 //
8 // (C) Copyright 2008, Google Inc.
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
20 
21 #ifndef TESSERACT_TEXTORD_LINEFIND_H_
22 #define TESSERACT_TEXTORD_LINEFIND_H_
23 
24 struct Boxa;
25 struct Pix;
26 struct Pixa;
27 class C_BLOB_LIST;
28 class BLOBNBOX_LIST;
29 class ICOORD;
30 
31 namespace tesseract {
32 
33 class TabVector_LIST;
34 
39 class LineFinder {
40  public:
61  static void FindAndRemoveLines(int resolution, bool debug, Pix* pix,
62  int* vertical_x, int* vertical_y,
63  Pix** pix_music_mask,
64  TabVector_LIST* v_lines,
65  TabVector_LIST* h_lines);
66 
76  static void ConvertBoxaToBlobs(int image_width, int image_height,
77  Boxa** boxes, C_BLOB_LIST* blobs);
78 
79  private:
80  // Finds vertical line objects in pix_vline and removes them from src_pix.
81  // Uses the given resolution to determine size thresholds instead of any
82  // that may be present in the pix.
83  // The output vertical_x and vertical_y contain a sum of the output vectors,
84  // thereby giving the mean vertical direction.
85  // The output vectors are owned by the list and Frozen (cannot refit) by
86  // having no boxes, as there is no need to refit or merge separator lines.
87  // If no good lines are found, pix_vline is destroyed.
88  static void FindAndRemoveVLines(int resolution,
89  Pix* pix_intersections,
90  int* vertical_x, int* vertical_y,
91  Pix** pix_vline, Pix* pix_non_vline,
92  Pix* src_pix, TabVector_LIST* vectors);
93 
94 
95  // Finds horizontal line objects in pix_vline and removes them from src_pix.
96  // Uses the given resolution to determine size thresholds instead of any
97  // that may be present in the pix.
98  // The output vertical_x and vertical_y contain a sum of the output vectors,
99  // thereby giving the mean vertical direction.
100  // The output vectors are owned by the list and Frozen (cannot refit) by
101  // having no boxes, as there is no need to refit or merge separator lines.
102  // If no good lines are found, pix_hline is destroyed.
103  static void FindAndRemoveHLines(int resolution,
104  Pix* pix_intersections,
105  int vertical_x, int vertical_y,
106  Pix** pix_hline, Pix* pix_non_hline,
107  Pix* src_pix, TabVector_LIST* vectors);
108 
109  // Finds vertical lines in the given list of BLOBNBOXes. bleft and tright
110  // are the bounds of the image on which the input line_bblobs were found.
111  // The input line_bblobs list is const really.
112  // The output vertical_x and vertical_y are the total of all the vectors.
113  // The output list of TabVector makes no reference to the input BLOBNBOXes.
114  static void FindLineVectors(const ICOORD& bleft, const ICOORD& tright,
115  BLOBNBOX_LIST* line_bblobs,
116  int* vertical_x, int* vertical_y,
117  TabVector_LIST* vectors);
118 
119  // Most of the heavy lifting of line finding. Given src_pix and its separate
120  // resolution, returns image masks:
121  // Returns image masks:
122  // pix_vline candidate vertical lines.
123  // pix_non_vline pixels that didn't look like vertical lines.
124  // pix_hline candidate horizontal lines.
125  // pix_non_hline pixels that didn't look like horizontal lines.
126  // pix_intersections pixels where vertical and horizontal lines meet.
127  // pix_music_mask candidate music staves.
128  // This function promises to initialize all the output (2nd level) pointers,
129  // but any of the returns that are empty will be nullptr on output.
130  // None of the input (1st level) pointers may be nullptr except pix_music_mask,
131  // which will disable music detection, and pixa_display, which is for debug.
132  static void GetLineMasks(int resolution, Pix* src_pix,
133  Pix** pix_vline, Pix** pix_non_vline,
134  Pix** pix_hline, Pix** pix_non_hline,
135  Pix** pix_intersections, Pix** pix_music_mask,
136  Pixa* pixa_display);
137 
138  // Returns a list of boxes corresponding to the candidate line segments. Sets
139  // the line_crossings member of the boxes so we can later determine the number
140  // of intersections touched by a full line.
141  static void GetLineBoxes(bool horizontal_lines,
142  Pix* pix_lines, Pix* pix_intersections,
143  C_BLOB_LIST* line_cblobs,
144  BLOBNBOX_LIST* line_bblobs);
145 };
146 
147 } // namespace tesseract.
148 
149 #endif // TESSERACT_TEXTORD_LINEFIND_H_
static void ConvertBoxaToBlobs(int image_width, int image_height, Boxa **boxes, C_BLOB_LIST *blobs)
Definition: linefind.cpp:319
static void GetLineBoxes(bool horizontal_lines, Pix *pix_lines, Pix *pix_intersections, C_BLOB_LIST *line_cblobs, BLOBNBOX_LIST *line_bblobs)
Definition: linefind.cpp:713
Definition: linefind.h:39
Definition: baseapi.cpp:94
static void FindAndRemoveHLines(int resolution, Pix *pix_intersections, int vertical_x, int vertical_y, Pix **pix_hline, Pix *pix_non_hline, Pix *src_pix, TabVector_LIST *vectors)
Definition: linefind.cpp:398
static void GetLineMasks(int resolution, Pix *src_pix, Pix **pix_vline, Pix **pix_non_vline, Pix **pix_hline, Pix **pix_non_hline, Pix **pix_intersections, Pix **pix_music_mask, Pixa *pixa_display)
Definition: linefind.cpp:570
static void FindAndRemoveVLines(int resolution, Pix *pix_intersections, int *vertical_x, int *vertical_y, Pix **pix_vline, Pix *pix_non_vline, Pix *src_pix, TabVector_LIST *vectors)
Definition: linefind.cpp:362
integer coordinate
Definition: points.h:32
static void FindAndRemoveLines(int resolution, bool debug, Pix *pix, int *vertical_x, int *vertical_y, Pix **pix_music_mask, TabVector_LIST *v_lines, TabVector_LIST *h_lines)
Definition: linefind.cpp:241
static void FindLineVectors(const ICOORD &bleft, const ICOORD &tright, BLOBNBOX_LIST *line_bblobs, int *vertical_x, int *vertical_y, TabVector_LIST *vectors)
Definition: linefind.cpp:436