1 /////////////////////////////////////////////////////////////////////// 2 // File: imagefind.h 3 // Description: Class to find image and drawing regions in an image 4 // and create a corresponding list of empty blobs. 5 // Author: Ray Smith 6 // Created: Fri Aug 01 10:50: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_IMAGEFIND_H__ 22 #define TESSERACT_TEXTORD_IMAGEFIND_H__ 23 24 struct Boxa; 25 struct Pix; 26 struct Pixa; 27 28 namespace tesseract { 29 30 // The ImageFinder class is a simple static function wrapper class that 31 // exposes the FindImages function and some useful helper functions. 32 class ImageFinder { 33 public: 34 // Finds image regions within the source pix (page image) and returns 35 // the image regions as a Boxa, Pixa pair, analgous to pixConnComp. 36 // The returned boxa, pixa may be NULL, meaning no images found. 37 // If not NULL, they must be destroyed by the caller. 38 static void FindImages(Pix* pix, Boxa** boxa, Pixa** pixa); 39 40 // Returns true if there is a rectangle in the source pix, such that all 41 // pixel rows and column slices outside of it have less than 42 // min_fraction of the pixels black, and within max_skew_gradient fraction 43 // of the pixels on the inside, there are at least max_fraction of the 44 // pixels black. In other words, the inside of the rectangle looks roughly 45 // rectangular, and the outside of it looks like extra bits. 46 // On return, the rectangle is defined by x_start, y_start, x_end and y_end. 47 // Note: the algorithm is iterative, allowing it to slice off pixels from 48 // one edge, allowing it to then slice off more pixels from another edge. 49 static bool pixNearlyRectangular(Pix* pix, 50 double min_fraction, double max_fraction, 51 double max_skew_gradient, 52 int* x_start, int* y_start, 53 int* x_end, int* y_end); 54 55 // Given an input pix, and a bounding rectangle, the sides of the rectangle 56 // are shrunk inwards until they bound any black pixels found within the 57 // original rectangle. 58 static void BoundsWithinRect(Pix* pix, int* x_start, int* y_start, 59 int* x_end, int* y_end); 60 }; 61 62 } // namespace tesseract. 63 64 #endif // TESSERACT_TEXTORD_LINEFIND_H__ 65 66