This file is indexed.

/usr/include/tesseract/imagefind.h is in libtesseract-dev 3.02.01-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
///////////////////////////////////////////////////////////////////////
// File:        imagefind.h
// Description: Class to find image and drawing regions in an image
//              and create a corresponding list of empty blobs.
// Author:      Ray Smith
// Created:     Fri Aug 01 10:50:01 PDT 2008
//
// (C) Copyright 2008, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////

#ifndef TESSERACT_TEXTORD_IMAGEFIND_H__
#define TESSERACT_TEXTORD_IMAGEFIND_H__

#include "host.h"

struct Boxa;
struct Pix;
struct Pixa;
class TBOX;
class FCOORD;
class TO_BLOCK;
class BLOBNBOX_LIST;

namespace tesseract {

class ColPartitionGrid;
class ColPartition_LIST;
class TabFind;

// The ImageFind class is a simple static function wrapper class that
// exposes the FindImages function and some useful helper functions.
class ImageFind {
 public:
  // Finds image regions within the BINARY source pix (page image) and returns
  // the image regions as a mask image.
  // The returned pix may be NULL, meaning no images found.
  // If not NULL, it must be PixDestroyed by the caller.
  static Pix* FindImages(Pix* pix);

  // Generates a Boxa, Pixa pair from the input binary (image mask) pix,
  // analgous to pixConnComp, except that connected components which are nearly
  // rectangular are replaced with solid rectangles.
  // The returned boxa, pixa may be NULL, meaning no images found.
  // If not NULL, they must be destroyed by the caller.
  // Resolution of pix should match the source image (Tesseract::pix_binary_)
  // so the output coordinate systems match.
  static void ConnCompAndRectangularize(Pix* pix, Boxa** boxa, Pixa** pixa);

  // Returns true if there is a rectangle in the source pix, such that all
  // pixel rows and column slices outside of it have less than
  // min_fraction of the pixels black, and within max_skew_gradient fraction
  // of the pixels on the inside, there are at least max_fraction of the
  // pixels black. In other words, the inside of the rectangle looks roughly
  // rectangular, and the outside of it looks like extra bits.
  // On return, the rectangle is defined by x_start, y_start, x_end and y_end.
  // Note: the algorithm is iterative, allowing it to slice off pixels from
  // one edge, allowing it to then slice off more pixels from another edge.
  static bool pixNearlyRectangular(Pix* pix,
                                   double min_fraction, double max_fraction,
                                   double max_skew_gradient,
                                   int* x_start, int* y_start,
                                   int* x_end, int* y_end);

  // Given an input pix, and a bounding rectangle, the sides of the rectangle
  // are shrunk inwards until they bound any black pixels found within the
  // original rectangle. Returns false if the rectangle contains no black
  // pixels at all.
  static bool BoundsWithinRect(Pix* pix, int* x_start, int* y_start,
                               int* x_end, int* y_end);

  // Given a point in 3-D (RGB) space, returns the squared Euclidean distance
  // of the point from the given line, defined by a pair of points in the 3-D
  // (RGB) space, line1 and line2.
  static double ColorDistanceFromLine(const uinT8* line1, const uinT8* line2,
                                      const uinT8* point);

  // Returns the leptonica combined code for the given RGB triplet.
  static uinT32 ComposeRGB(uinT32 r, uinT32 g, uinT32 b);

  // Returns the input value clipped to a uinT8.
  static uinT8 ClipToByte(double pixel);

  // Computes the light and dark extremes of color in the given rectangle of
  // the given pix, which is factor smaller than the coordinate system in rect.
  // The light and dark points are taken to be the upper and lower 8th-ile of
  // the most deviant of R, G and B. The value of the other 2 channels are
  // computed by linear fit against the most deviant.
  // The colors of the two point are returned in color1 and color2, with the
  // alpha channel set to a scaled mean rms of the fits.
  // If color_map1 is not null then it and color_map2 get rect pasted in them
  // with the two calculated colors, and rms map gets a pasted rect of the rms.
  // color_map1, color_map2 and rms_map are assumed to be the same scale as pix.
  static void ComputeRectangleColors(const TBOX& rect, Pix* pix, int factor,
                                     Pix* color_map1, Pix* color_map2,
                                     Pix* rms_map,
                                     uinT8* color1, uinT8* color2);

  // Returns true if there are no black pixels in between the boxes.
  // The im_box must represent the bounding box of the pix in tesseract
  // coordinates, which may be negative, due to rotations to make the textlines
  // horizontal. The boxes are rotated by rotation, which should undo such
  // rotations, before mapping them onto the pix.
  static bool BlankImageInBetween(const TBOX& box1, const TBOX& box2,
                                  const TBOX& im_box, const FCOORD& rotation,
                                  Pix* pix);

  // Returns the number of pixels in box in the pix.
  // The im_box must represent the bounding box of the pix in tesseract
  // coordinates, which may be negative, due to rotations to make the textlines
  // horizontal. The boxes are rotated by rotation, which should undo such
  // rotations, before mapping them onto the pix.
  static int CountPixelsInRotatedBox(TBOX box, const TBOX& im_box,
                                     const FCOORD& rotation, Pix* pix);


  // Locates all the image partitions in the part_grid, that were found by a
  // previous call to FindImagePartitions, marks them in the image_mask,
  // removes them from the grid, and deletes them. This makes it possble to
  // call FindImagePartitions again to produce less broken-up and less
  // overlapping image partitions.
  // rerotation specifies how to rotate the partition coords to match
  // the image_mask, since this function is used after orientation correction.
  static void TransferImagePartsToImageMask(const FCOORD& rerotation,
                                            ColPartitionGrid* part_grid,
                                            Pix* image_mask);

  // Runs a CC analysis on the image_pix mask image, and creates
  // image partitions from them, cutting out strong text, and merging with
  // nearby image regions such that they don't interfere with text.
  // Rotation and rerotation specify how to rotate image coords to match
  // the blob and partition coords and back again.
  // The input/output part_grid owns all the created partitions, and
  // the partitions own all the fake blobs that belong in the partitions.
  // Since the other blobs in the other partitions will be owned by the block,
  // ColPartitionGrid::ReTypeBlobs must be called afterwards to fix this
  // situation and collect the image blobs.
  static void FindImagePartitions(Pix* image_pix,
                                  const FCOORD& rotation,
                                  const FCOORD& rerotation,
                                  TO_BLOCK* block,
                                  TabFind* tab_grid,
                                  ColPartitionGrid* part_grid,
                                  ColPartition_LIST* big_parts);
};

}  // namespace tesseract.

#endif  // TESSERACT_TEXTORD_LINEFIND_H__