/usr/include/tesseract/blobs.h is in libtesseract-dev 3.02.01-2.
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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | /* -*-C-*-
********************************************************************************
*
* File: blobs.h (Formerly blobs.h)
* Description: Blob definition
* Author: Mark Seaman, OCR Technology
* Created: Fri Oct 27 15:39:52 1989
* Modified: Thu Mar 28 15:33:38 1991 (Mark Seaman) marks@hpgrlt
* Language: C
* Package: N/A
* Status: Experimental (Do Not Distribute)
*
* (c) Copyright 1989, Hewlett-Packard Company.
** 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 BLOBS_H
#define BLOBS_H
/*----------------------------------------------------------------------
I n c l u d e s
----------------------------------------------------------------------*/
#include "clst.h"
#include "rect.h"
#include "vecfuncs.h"
class BLOCK;
class C_BLOB;
class DENORM;
class ROW;
class WERD;
/*----------------------------------------------------------------------
T y p e s
----------------------------------------------------------------------*/
#define EDGEPTFLAGS 4 /*concavity,length etc. */
typedef struct
{ /* Widths of pieces */
int num_chars;
int widths[1];
} WIDTH_RECORD;
struct TPOINT {
TPOINT(): x(0), y(0) {}
TPOINT(inT16 vx, inT16 vy) : x(vx), y(vy) {}
TPOINT(const ICOORD &ic) : x(ic.x()), y(ic.y()) {}
void operator+=(const TPOINT& other) {
x += other.x;
y += other.y;
}
void operator/=(int divisor) {
x /= divisor;
y /= divisor;
}
inT16 x; // absolute x coord.
inT16 y; // absolute y coord.
};
typedef TPOINT VECTOR; // structure for coordinates.
struct EDGEPT {
EDGEPT() : next(NULL), prev(NULL) {
memset(flags, 0, EDGEPTFLAGS * sizeof(flags[0]));
}
EDGEPT(const EDGEPT& src) : next(NULL), prev(NULL) {
CopyFrom(src);
}
EDGEPT& operator=(const EDGEPT& src) {
CopyFrom(src);
return *this;
}
// Copies the data elements, but leaves the pointers untouched.
void CopyFrom(const EDGEPT& src) {
pos = src.pos;
vec = src.vec;
memcpy(flags, src.flags, EDGEPTFLAGS * sizeof(flags[0]));
}
// Accessors to hide or reveal a cut edge from feature extractors.
void Hide() {
flags[0] = true;
}
void Reveal() {
flags[0] = false;
}
bool IsHidden() const {
return flags[0] != 0;
}
TPOINT pos; // position
VECTOR vec; // vector to next point
// TODO(rays) Remove flags and replace with
// is_hidden, runlength, dir, and fixed. The only use
// of the flags other than is_hidden is in polyaprx.cpp.
char flags[EDGEPTFLAGS]; // concavity, length etc
EDGEPT* next; // anticlockwise element
EDGEPT* prev; // clockwise element
};
// For use in chop and findseam to keep a list of which EDGEPTs were inserted.
CLISTIZEH(EDGEPT);
struct TESSLINE {
TESSLINE() : is_hole(false), loop(NULL), next(NULL) {}
TESSLINE(const TESSLINE& src) : loop(NULL), next(NULL) {
CopyFrom(src);
}
~TESSLINE() {
Clear();
}
TESSLINE& operator=(const TESSLINE& src) {
CopyFrom(src);
return *this;
}
// Consume the circular list of EDGEPTs to make a TESSLINE.
static TESSLINE* BuildFromOutlineList(EDGEPT* outline);
// Copies the data and the outline, but leaves next untouched.
void CopyFrom(const TESSLINE& src);
// Deletes owned data.
void Clear();
// Normalize in-place using the DENORM.
void Normalize(const DENORM& denorm);
// Rotates by the given rotation in place.
void Rotate(const FCOORD rotation);
// Moves by the given vec in place.
void Move(const ICOORD vec);
// Scales by the given factor in place.
void Scale(float factor);
// Sets up the start and vec members of the loop from the pos members.
void SetupFromPos();
// Recomputes the bounding box from the points in the loop.
void ComputeBoundingBox();
// Computes the min and max cross product of the outline points with the
// given vec and returns the results in min_xp and max_xp. Geometrically
// this is the left and right edge of the outline perpendicular to the
// given direction, but to get the distance units correct, you would
// have to divide by the modulus of vec.
void MinMaxCrossProduct(const TPOINT vec, int* min_xp, int* max_xp) const;
TBOX bounding_box() const;
// Returns true if the point is contained within the outline box.
bool Contains(const TPOINT& pt) {
return topleft.x <= pt.x && pt.x <= botright.x &&
botright.y <= pt.y && pt.y <= topleft.y;
}
void plot(ScrollView* window, ScrollView::Color color,
ScrollView::Color child_color);
int BBArea() const {
return (botright.x - topleft.x) * (topleft.y - botright.y);
}
TPOINT topleft; // Top left of loop.
TPOINT botright; // Bottom right of loop.
TPOINT start; // Start of loop.
bool is_hole; // True if this is a hole/child outline.
EDGEPT *loop; // Edgeloop.
TESSLINE *next; // Next outline in blob.
}; // Outline structure.
struct TBLOB {
TBLOB() : outlines(NULL), next(NULL) {}
TBLOB(const TBLOB& src) : outlines(NULL), next(NULL) {
CopyFrom(src);
}
~TBLOB() {
Clear();
}
TBLOB& operator=(const TBLOB& src) {
CopyFrom(src);
return *this;
}
// Factory to build a TBLOB from a C_BLOB with polygonal
// approximation along the way.
static TBLOB* PolygonalCopy(C_BLOB* src);
// Normalizes the blob for classification only if needed.
// (Normally this means a non-zero classify rotation.)
// If no Normalization is needed, then NULL is returned, and the denorm is
// unchanged. Otherwise a new TBLOB is returned and the denorm points to
// a new DENORM. In this case, both the TBLOB and DENORM must be deleted.
TBLOB* ClassifyNormalizeIfNeeded(const DENORM** denorm) const;
// Copies the data and the outlines, but leaves next untouched.
void CopyFrom(const TBLOB& src);
// Deletes owned data.
void Clear();
// Normalize in-place using the DENORM.
void Normalize(const DENORM& denorm);
// Rotates by the given rotation in place.
void Rotate(const FCOORD rotation);
// Moves by the given vec in place.
void Move(const ICOORD vec);
// Scales by the given factor in place.
void Scale(float factor);
// Recomputes the bounding boxes of the outlines.
void ComputeBoundingBoxes();
// Returns the number of outlines.
int NumOutlines() const;
TBOX bounding_box() const;
void plot(ScrollView* window, ScrollView::Color color,
ScrollView::Color child_color);
int BBArea() const {
int total_area = 0;
for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next)
total_area += outline->BBArea();
return total_area;
}
TESSLINE *outlines; // List of outlines in blob.
TBLOB *next; // Next blob in block.
}; // Blob structure.
int count_blobs(TBLOB *blobs);
struct TWERD {
TWERD() : blobs(NULL), latin_script(false), next(NULL) {}
TWERD(const TWERD& src) : blobs(NULL), next(NULL) {
CopyFrom(src);
}
~TWERD() {
Clear();
}
TWERD& operator=(const TWERD& src) {
CopyFrom(src);
return *this;
}
// Factory to build a TWERD from a (C_BLOB) WERD, with polygonal
// approximation along the way.
static TWERD* PolygonalCopy(WERD* src);
// Setup for Baseline normalization, recording the normalization in the
// DENORM, but doesn't do any normalization.
void SetupBLNormalize(const BLOCK* block, const ROW* row,
float x_height, bool numeric_mode,
DENORM* denorm) const;
// Normalize in-place using the DENORM.
void Normalize(const DENORM& denorm);
// Copies the data and the blobs, but leaves next untouched.
void CopyFrom(const TWERD& src);
// Deletes owned data.
void Clear();
// Recomputes the bounding boxes of the blobs.
void ComputeBoundingBoxes();
// Returns the number of blobs in the word.
int NumBlobs() const {
return count_blobs(blobs);
}
TBOX bounding_box() const;
// Merges the blobs from start to end, not including end, and deletes
// the blobs between start and end.
void MergeBlobs(int start, int end);
void plot(ScrollView* window);
TBLOB* blobs; // blobs in word.
bool latin_script; // This word is in a latin-based script.
TWERD* next; // next word.
};
/*----------------------------------------------------------------------
M a c r o s
----------------------------------------------------------------------*/
/**********************************************************************
* free_widths
*
* Free the memory taken up by a width array.
**********************************************************************/
#define free_widths(w) \
if (w) memfree (w)
/*----------------------------------------------------------------------
F u n c t i o n s
----------------------------------------------------------------------*/
// TODO(rays) This will become a member of TBLOB when TBLOB's definition
// moves to blobs.h
// Returns the center of blob's bounding box in origin.
void blob_origin(TBLOB *blob, TPOINT *origin);
/*blob to compute on */
WIDTH_RECORD *blobs_widths(TBLOB *blobs);
bool divisible_blob(TBLOB *blob, bool italic_blob, TPOINT* location);
void divide_blobs(TBLOB *blob, TBLOB *other_blob, bool italic_blob,
const TPOINT& location);
#endif
|