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 Pix; 00025 struct Boxa; 00026 class C_BLOB_LIST; 00027 class BLOBNBOX_LIST; 00028 class ICOORD; 00029 00030 namespace tesseract { 00031 00032 class TabVector_LIST; 00033 00034 // The LineFinder class is a simple static function wrapper class that mainly 00035 // exposes the FindVerticalLines function. 00036 class LineFinder { 00037 public: 00038 // Finds vertical line objects in the given pix. 00039 // Uses the given resolution to determine size thresholds instead of any 00040 // that may be present in the pix. 00041 // The output vertical_x and vertical_y contain a sum of the output vectors, 00042 // thereby giving the mean vertical direction. 00043 // The output vectors are owned by the list and Frozen (cannot refit) by 00044 // having no boxes, as there is no need to refit or merge separator lines. 00045 static void FindVerticalLines(int resolution, Pix* pix, 00046 int* vertical_x, int* vertical_y, 00047 TabVector_LIST* vectors); 00048 00049 // Finds horizontal line objects in the given pix. 00050 // Uses the given resolution to determine size thresholds instead of any 00051 // that may be present in the pix. 00052 // The output vectors are owned by the list and Frozen (cannot refit) by 00053 // having no boxes, as there is no need to refit or merge separator lines. 00054 static void FindHorizontalLines(int resolution, Pix* pix, 00055 TabVector_LIST* vectors); 00056 00057 // Converts the Boxa array to a list of C_BLOB, getting rid of severely 00058 // overlapping outlines and those that are children of a bigger one. 00059 // The output is a list of C_BLOBs that are owned by the list. 00060 // The C_OUTLINEs in the C_BLOBs contain no outline data - just empty 00061 // bounding boxes. The Boxa is consumed and destroyed. 00062 static void ConvertBoxaToBlobs(int image_width, int image_height, 00063 Boxa** boxes, C_BLOB_LIST* blobs); 00064 00065 private: 00066 // Finds vertical lines in the given list of BLOBNBOXes. bleft and tright 00067 // are the bounds of the image on which the input line_bblobs were found. 00068 // The input line_bblobs list is const really. 00069 // The output vertical_x and vertical_y are the total of all the vectors. 00070 // The output list of TabVector makes no reference to the input BLOBNBOXes. 00071 static void FindLineVectors(const ICOORD& bleft, const ICOORD& tright, 00072 BLOBNBOX_LIST* line_bblobs, 00073 int* vertical_x, int* vertical_y, 00074 TabVector_LIST* vectors); 00075 00076 // Get a set of bounding boxes of possible vertical lines in the image. 00077 // The input resolution overrides any resolution set in src_pix. 00078 // The output line_pix contains just all the detected lines. 00079 static Boxa* GetVLineBoxes(int resolution, Pix* src_pix, Pix** line_pix); 00080 00081 // Get a set of bounding boxes of possible horizontal lines in the image. 00082 // The input resolution overrides any resolution set in src_pix. 00083 // The output line_pix contains just all the detected lines. 00084 // The output boxes undergo the transformation (x,y)->(height-y,x) so the 00085 // lines can be found with a vertical line finder afterwards. 00086 // This transformation allows a simple x/y flip to reverse it in tesseract 00087 // coordinates and it is faster to flip the lines than rotate the image. 00088 static Boxa* GetHLineBoxes(int resolution, Pix* src_pix, Pix** line_pix); 00089 }; 00090 00091 } // namespace tesseract. 00092 00093 #endif // TESSERACT_TEXTORD_LINEFIND_H__ 00094