• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////
2 // 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 //
19 ///////////////////////////////////////////////////////////////////////
20 
21 #ifndef TESSERACT_TEXTORD_LINEFIND_H__
22 #define TESSERACT_TEXTORD_LINEFIND_H__
23 
24 struct Pix;
25 struct Boxa;
26 class C_BLOB_LIST;
27 class BLOBNBOX_LIST;
28 class ICOORD;
29 
30 namespace tesseract {
31 
32 class TabVector_LIST;
33 
34 // The LineFinder class is a simple static function wrapper class that mainly
35 // exposes the FindVerticalLines function.
36 class LineFinder {
37  public:
38   // Finds vertical line objects in the given pix.
39   // Uses the given resolution to determine size thresholds instead of any
40   // that may be present in the pix.
41   // The output vertical_x and vertical_y contain a sum of the output vectors,
42   // thereby giving the mean vertical direction.
43   // The output vectors are owned by the list and Frozen (cannot refit) by
44   // having no boxes, as there is no need to refit or merge separator lines.
45   static void FindVerticalLines(int resolution,  Pix* pix,
46                                 int* vertical_x, int* vertical_y,
47                                 TabVector_LIST* vectors);
48 
49   // Finds horizontal line objects in the given pix.
50   // Uses the given resolution to determine size thresholds instead of any
51   // that may be present in the pix.
52   // The output vectors are owned by the list and Frozen (cannot refit) by
53   // having no boxes, as there is no need to refit or merge separator lines.
54   static void FindHorizontalLines(int resolution,  Pix* pix,
55                                   TabVector_LIST* vectors);
56 
57   // Converts the Boxa array to a list of C_BLOB, getting rid of severely
58   // overlapping outlines and those that are children of a bigger one.
59   // The output is a list of C_BLOBs that are owned by the list.
60   // The C_OUTLINEs in the C_BLOBs contain no outline data - just empty
61   // bounding boxes. The Boxa is consumed and destroyed.
62   static void ConvertBoxaToBlobs(int image_width, int image_height,
63                                  Boxa** boxes, C_BLOB_LIST* blobs);
64 
65  private:
66   // Finds vertical lines in the given list of BLOBNBOXes. bleft and tright
67   // are the bounds of the image on which the input line_bblobs were found.
68   // The input line_bblobs list is const really.
69   // The output vertical_x and vertical_y are the total of all the vectors.
70   // The output list of TabVector makes no reference to the input BLOBNBOXes.
71   static void FindLineVectors(const ICOORD& bleft, const ICOORD& tright,
72                               BLOBNBOX_LIST* line_bblobs,
73                               int* vertical_x, int* vertical_y,
74                               TabVector_LIST* vectors);
75 
76   // Get a set of bounding boxes of possible vertical lines in the image.
77   // The input resolution overrides any resolution set in src_pix.
78   // The output line_pix contains just all the detected lines.
79   static Boxa* GetVLineBoxes(int resolution, Pix* src_pix, Pix** line_pix);
80 
81   // Get a set of bounding boxes of possible horizontal lines in the image.
82   // The input resolution overrides any resolution set in src_pix.
83   // The output line_pix contains just all the detected lines.
84   // The output boxes undergo the transformation (x,y)->(height-y,x) so the
85   // lines can be found with a vertical line finder afterwards.
86   // This transformation allows a simple x/y flip to reverse it in tesseract
87   // coordinates and it is faster to flip the lines than rotate the image.
88   static Boxa* GetHLineBoxes(int resolution, Pix* src_pix, Pix** line_pix);
89 };
90 
91 }  // namespace tesseract.
92 
93 #endif  // TESSERACT_TEXTORD_LINEFIND_H__
94 
95