Tesseract 3.01
|
00001 00002 // File: imagefind.h 00003 // Description: Class to find image and drawing regions in an image 00004 // and create a corresponding list of empty blobs. 00005 // Author: Ray Smith 00006 // Created: Fri Aug 01 10:50: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_IMAGEFIND_H__ 00022 #define TESSERACT_TEXTORD_IMAGEFIND_H__ 00023 00024 struct Boxa; 00025 struct Pix; 00026 struct Pixa; 00027 00028 namespace tesseract { 00029 00030 // The ImageFinder class is a simple static function wrapper class that 00031 // exposes the FindImages function and some useful helper functions. 00032 class ImageFinder { 00033 public: 00034 // Finds image regions within the source pix (page image) and returns 00035 // the image regions as a Boxa, Pixa pair, analgous to pixConnComp. 00036 // The returned boxa, pixa may be NULL, meaning no images found. 00037 // If not NULL, they must be destroyed by the caller. 00038 static void FindImages(Pix* pix, Boxa** boxa, Pixa** pixa); 00039 00040 // Returns true if there is a rectangle in the source pix, such that all 00041 // pixel rows and column slices outside of it have less than 00042 // min_fraction of the pixels black, and within max_skew_gradient fraction 00043 // of the pixels on the inside, there are at least max_fraction of the 00044 // pixels black. In other words, the inside of the rectangle looks roughly 00045 // rectangular, and the outside of it looks like extra bits. 00046 // On return, the rectangle is defined by x_start, y_start, x_end and y_end. 00047 // Note: the algorithm is iterative, allowing it to slice off pixels from 00048 // one edge, allowing it to then slice off more pixels from another edge. 00049 static bool pixNearlyRectangular(Pix* pix, 00050 double min_fraction, double max_fraction, 00051 double max_skew_gradient, 00052 int* x_start, int* y_start, 00053 int* x_end, int* y_end); 00054 00055 // Given an input pix, and a bounding rectangle, the sides of the rectangle 00056 // are shrunk inwards until they bound any black pixels found within the 00057 // original rectangle. 00058 static void BoundsWithinRect(Pix* pix, int* x_start, int* y_start, 00059 int* x_end, int* y_end); 00060 }; 00061 00062 } // namespace tesseract. 00063 00064 #endif // TESSERACT_TEXTORD_LINEFIND_H__ 00065