Tesseract  3.02
tesseract-ocr/textord/linefind.h
Go to the documentation of this file.
00001 
00002 // File:        linefind.h
00003 // Description: Class to find vertical lines in an image and create
00004 //              a corresponding list of empty blobs.
00005 // Author:      Ray Smith
00006 // Created:     Thu Mar 20 09:49:01 PDT 2008
00007 //
00008 // (C) Copyright 2008, Google Inc.
00009 // Licensed under the Apache License, Version 2.0 (the "License");
00010 // you may not use this file except in compliance with the License.
00011 // You may obtain a copy of the License at
00012 // http://www.apache.org/licenses/LICENSE-2.0
00013 // Unless required by applicable law or agreed to in writing, software
00014 // distributed under the License is distributed on an "AS IS" BASIS,
00015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016 // See the License for the specific language governing permissions and
00017 // limitations under the License.
00018 //
00020 
00021 #ifndef TESSERACT_TEXTORD_LINEFIND_H__
00022 #define TESSERACT_TEXTORD_LINEFIND_H__
00023 
00024 struct Boxa;
00025 struct Pix;
00026 struct Pixa;
00027 class C_BLOB_LIST;
00028 class BLOBNBOX_LIST;
00029 class ICOORD;
00030 
00031 namespace tesseract {
00032 
00033 class TabVector_LIST;
00034 
00039 class LineFinder {
00040  public:
00061   static void FindAndRemoveLines(int resolution,  bool debug, Pix* pix,
00062                                  int* vertical_x, int* vertical_y,
00063                                  Pix** pix_music_mask,
00064                                  TabVector_LIST* v_lines,
00065                                  TabVector_LIST* h_lines);
00066 
00076   static void ConvertBoxaToBlobs(int image_width, int image_height,
00077                                  Boxa** boxes, C_BLOB_LIST* blobs);
00078 
00079  private:
00080   // Finds vertical line objects in pix_vline and removes them from src_pix.
00081   // Uses the given resolution to determine size thresholds instead of any
00082   // that may be present in the pix.
00083   // The output vertical_x and vertical_y contain a sum of the output vectors,
00084   // thereby giving the mean vertical direction.
00085   // The output vectors are owned by the list and Frozen (cannot refit) by
00086   // having no boxes, as there is no need to refit or merge separator lines.
00087   // If no good lines are found, pix_vline is destroyed.
00088   static void FindAndRemoveVLines(int resolution,
00089                                   Pix* pix_intersections,
00090                                   int* vertical_x, int* vertical_y,
00091                                   Pix** pix_vline, Pix* pix_non_vline,
00092                                   Pix* src_pix, TabVector_LIST* vectors);
00093 
00094 
00095   // Finds horizontal line objects in pix_vline and removes them from src_pix.
00096   // Uses the given resolution to determine size thresholds instead of any
00097   // that may be present in the pix.
00098   // The output vertical_x and vertical_y contain a sum of the output vectors,
00099   // thereby giving the mean vertical direction.
00100   // The output vectors are owned by the list and Frozen (cannot refit) by
00101   // having no boxes, as there is no need to refit or merge separator lines.
00102   // If no good lines are found, pix_hline is destroyed.
00103   static void FindAndRemoveHLines(int resolution,
00104                                   Pix* pix_intersections,
00105                                   int vertical_x, int vertical_y,
00106                                   Pix** pix_hline, Pix* pix_non_hline,
00107                                   Pix* src_pix, TabVector_LIST* vectors);
00108 
00109   // Finds vertical lines in the given list of BLOBNBOXes. bleft and tright
00110   // are the bounds of the image on which the input line_bblobs were found.
00111   // The input line_bblobs list is const really.
00112   // The output vertical_x and vertical_y are the total of all the vectors.
00113   // The output list of TabVector makes no reference to the input BLOBNBOXes.
00114   static void FindLineVectors(const ICOORD& bleft, const ICOORD& tright,
00115                               BLOBNBOX_LIST* line_bblobs,
00116                               int* vertical_x, int* vertical_y,
00117                               TabVector_LIST* vectors);
00118 
00119   // Most of the heavy lifting of line finding. Given src_pix and its separate
00120   // resolution, returns image masks:
00121   // Returns image masks:
00122   // pix_vline           candidate vertical lines.
00123   // pix_non_vline       pixels that didn't look like vertical lines.
00124   // pix_hline           candidate horizontal lines.
00125   // pix_non_hline       pixels that didn't look like horizontal lines.
00126   // pix_intersections   pixels where vertical and horizontal lines meet.
00127   // pix_music_mask      candidate music staves.
00128   // This function promises to initialize all the output (2nd level) pointers,
00129   // but any of the returns that are empty will be NULL on output.
00130   // None of the input (1st level) pointers may be NULL except pix_music_mask,
00131   // which will disable music detection, and pixa_display, which is for debug.
00132   static void GetLineMasks(int resolution, Pix* src_pix,
00133                            Pix** pix_vline, Pix** pix_non_vline,
00134                            Pix** pix_hline, Pix** pix_non_hline,
00135                            Pix** pix_intersections, Pix** pix_music_mask,
00136                            Pixa* pixa_display);
00137 
00138   // Returns a list of boxes corresponding to the candidate line segments. Sets
00139   // the line_crossings member of the boxes so we can later determin the number
00140   // of intersections touched by a full line.
00141   static void GetLineBoxes(bool horizontal_lines,
00142                            Pix* pix_lines, Pix* pix_intersections,
00143                            C_BLOB_LIST* line_cblobs,
00144                            BLOBNBOX_LIST* line_bblobs);
00145 };
00146 
00147 }  // namespace tesseract.
00148 
00149 #endif  // TESSERACT_TEXTORD_LINEFIND_H__
00150