tesseract  4.00.00dev
tesseract::BoxWord Class Reference

#include <boxword.h>

Public Member Functions

 BoxWord ()
 
 BoxWord (const BoxWord &src)
 
 ~BoxWord ()
 
BoxWordoperator= (const BoxWord &src)
 
void CopyFrom (const BoxWord &src)
 
void ClipToOriginalWord (const BLOCK *block, WERD *original_word)
 
void MergeBoxes (int start, int end)
 
void InsertBox (int index, const TBOX &box)
 
void ChangeBox (int index, const TBOX &box)
 
void DeleteBox (int index)
 
void DeleteAllBoxes ()
 
void ProcessMatchedBlobs (const TWERD &other, TessCallback1< int > *cb) const
 
const TBOXbounding_box () const
 
int length () const
 
const TBOXBlobBox (int index) const
 

Static Public Member Functions

static BoxWordCopyFromNormalized (TWERD *tessword)
 

Detailed Description

Definition at line 39 of file boxword.h.

Constructor & Destructor Documentation

◆ BoxWord() [1/2]

tesseract::BoxWord::BoxWord ( )

Definition at line 33 of file boxword.cpp.

33  : length_(0) {
34 }

◆ BoxWord() [2/2]

tesseract::BoxWord::BoxWord ( const BoxWord src)
explicit

Definition at line 36 of file boxword.cpp.

36  {
37  CopyFrom(src);
38 }
void CopyFrom(const BoxWord &src)
Definition: boxword.cpp:48

◆ ~BoxWord()

tesseract::BoxWord::~BoxWord ( )

Definition at line 40 of file boxword.cpp.

40  {
41 }

Member Function Documentation

◆ BlobBox()

const TBOX& tesseract::BoxWord::BlobBox ( int  index) const
inline

Definition at line 86 of file boxword.h.

86  {
87  return boxes_[index];
88  }

◆ bounding_box()

const TBOX& tesseract::BoxWord::bounding_box ( ) const
inline

Definition at line 82 of file boxword.h.

82  {
83  return bbox_;
84  }

◆ ChangeBox()

void tesseract::BoxWord::ChangeBox ( int  index,
const TBOX box 
)

Definition at line 162 of file boxword.cpp.

162  {
163  boxes_[index] = box;
164  ComputeBoundingBox();
165 }

◆ ClipToOriginalWord()

void tesseract::BoxWord::ClipToOriginalWord ( const BLOCK block,
WERD original_word 
)

Definition at line 95 of file boxword.cpp.

95  {
96  for (int i = 0; i < length_; ++i) {
97  TBOX box = boxes_[i];
98  // Expand by a single pixel, as the poly approximation error is 1 pixel.
99  box = TBOX(box.left() - 1, box.bottom() - 1,
100  box.right() + 1, box.top() + 1);
101  // Now find the original box that matches.
102  TBOX original_box;
103  C_BLOB_IT b_it(original_word->cblob_list());
104  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
105  TBOX blob_box = b_it.data()->bounding_box();
106  if (block != NULL)
107  blob_box.rotate(block->re_rotation());
108  if (blob_box.major_overlap(box)) {
109  original_box += blob_box;
110  }
111  }
112  if (!original_box.null_box()) {
113  if (NearlyEqual<int>(original_box.left(), box.left(), kBoxClipTolerance))
114  box.set_left(original_box.left());
115  if (NearlyEqual<int>(original_box.right(), box.right(),
117  box.set_right(original_box.right());
118  if (NearlyEqual<int>(original_box.top(), box.top(), kBoxClipTolerance))
119  box.set_top(original_box.top());
120  if (NearlyEqual<int>(original_box.bottom(), box.bottom(),
122  box.set_bottom(original_box.bottom());
123  }
124  original_box = original_word->bounding_box();
125  if (block != NULL)
126  original_box.rotate(block->re_rotation());
127  boxes_[i] = box.intersection(original_box);
128  }
129  ComputeBoundingBox();
130 }
TBOX intersection(const TBOX &box) const
Definition: rect.cpp:87
const int kBoxClipTolerance
Definition: boxword.cpp:31
TBOX bounding_box() const
Definition: werd.cpp:160
inT16 left() const
Definition: rect.h:68
void set_top(int y)
Definition: rect.h:57
bool major_overlap(const TBOX &box) const
Definition: rect.h:358
inT16 top() const
Definition: rect.h:54
Definition: rect.h:30
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
inT16 right() const
Definition: rect.h:75
void set_right(int x)
Definition: rect.h:78
void set_left(int x)
Definition: rect.h:71
FCOORD re_rotation() const
Definition: ocrblock.h:138
inT16 bottom() const
Definition: rect.h:61
void set_bottom(int y)
Definition: rect.h:64
void rotate(const FCOORD &vec)
Definition: rect.h:189

◆ CopyFrom()

void tesseract::BoxWord::CopyFrom ( const BoxWord src)

Definition at line 48 of file boxword.cpp.

48  {
49  bbox_ = src.bbox_;
50  length_ = src.length_;
51  boxes_.clear();
52  boxes_.reserve(length_);
53  for (int i = 0; i < length_; ++i)
54  boxes_.push_back(src.boxes_[i]);
55 }
void reserve(int size)
int push_back(T object)

◆ CopyFromNormalized()

BoxWord * tesseract::BoxWord::CopyFromNormalized ( TWERD tessword)
static

Definition at line 59 of file boxword.cpp.

59  {
60  BoxWord* boxword = new BoxWord();
61  // Count the blobs.
62  boxword->length_ = tessword->NumBlobs();
63  // Allocate memory.
64  boxword->boxes_.reserve(boxword->length_);
65 
66  for (int b = 0; b < boxword->length_; ++b) {
67  TBLOB* tblob = tessword->blobs[b];
68  TBOX blob_box;
69  for (TESSLINE* outline = tblob->outlines; outline != NULL;
70  outline = outline->next) {
71  EDGEPT* edgept = outline->loop;
72  // Iterate over the edges.
73  do {
74  if (!edgept->IsHidden() || !edgept->prev->IsHidden()) {
75  ICOORD pos(edgept->pos.x, edgept->pos.y);
76  TPOINT denormed;
77  tblob->denorm().DenormTransform(NULL, edgept->pos, &denormed);
78  pos.set_x(denormed.x);
79  pos.set_y(denormed.y);
80  TBOX pt_box(pos, pos);
81  blob_box += pt_box;
82  }
83  edgept = edgept->next;
84  } while (edgept != outline->loop);
85  }
86  boxword->boxes_.push_back(blob_box);
87  }
88  boxword->ComputeBoundingBox();
89  return boxword;
90 }
TESSLINE * next
Definition: blobs.h:258
TPOINT pos
Definition: blobs.h:163
EDGEPT * prev
Definition: blobs.h:170
TESSLINE * outlines
Definition: blobs.h:377
void DenormTransform(const DENORM *last_denorm, const TPOINT &pt, TPOINT *original) const
Definition: normalis.cpp:389
const DENORM & denorm() const
Definition: blobs.h:340
bool IsHidden() const
Definition: blobs.h:153
inT16 x
Definition: blobs.h:71
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
int NumBlobs() const
Definition: blobs.h:425
inT16 y
Definition: blobs.h:72
Definition: rect.h:30
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
Definition: blobs.h:261
Definition: blobs.h:50
integer coordinate
Definition: points.h:30

◆ DeleteAllBoxes()

void tesseract::BoxWord::DeleteAllBoxes ( )

Definition at line 177 of file boxword.cpp.

177  {
178  length_ = 0;
179  boxes_.clear();
180  bbox_ = TBOX();
181 }
Definition: rect.h:30

◆ DeleteBox()

void tesseract::BoxWord::DeleteBox ( int  index)

Definition at line 169 of file boxword.cpp.

169  {
170  ASSERT_HOST(0 <= index && index < length_);
171  boxes_.remove(index);
172  --length_;
173  ComputeBoundingBox();
174 }
void remove(int index)
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ InsertBox()

void tesseract::BoxWord::InsertBox ( int  index,
const TBOX box 
)

Definition at line 151 of file boxword.cpp.

151  {
152  if (index < length_)
153  boxes_.insert(box, index);
154  else
155  boxes_.push_back(box);
156  length_ = boxes_.size();
157  ComputeBoundingBox();
158 }
int push_back(T object)
int size() const
Definition: genericvector.h:72
void insert(T t, int index)

◆ length()

int tesseract::BoxWord::length ( ) const
inline

Definition at line 85 of file boxword.h.

85 { return length_; }

◆ MergeBoxes()

void tesseract::BoxWord::MergeBoxes ( int  start,
int  end 
)

Definition at line 134 of file boxword.cpp.

134  {
135  start = ClipToRange(start, 0, length_);
136  end = ClipToRange(end, 0, length_);
137  if (end <= start + 1)
138  return;
139  for (int i = start + 1; i < end; ++i) {
140  boxes_[start] += boxes_[i];
141  }
142  int shrinkage = end - 1 - start;
143  length_ -= shrinkage;
144  for (int i = start + 1; i < length_; ++i)
145  boxes_[i] = boxes_[i + shrinkage];
146  boxes_.truncate(length_);
147 }
void truncate(int size)
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:122

◆ operator=()

BoxWord & tesseract::BoxWord::operator= ( const BoxWord src)

Definition at line 43 of file boxword.cpp.

43  {
44  CopyFrom(src);
45  return *this;
46 }
void CopyFrom(const BoxWord &src)
Definition: boxword.cpp:48

◆ ProcessMatchedBlobs()

void tesseract::BoxWord::ProcessMatchedBlobs ( const TWERD other,
TessCallback1< int > *  cb 
) const

Definition at line 193 of file boxword.cpp.

194  {
195  for (int i = 0; i < length_ && i < other.NumBlobs(); ++i) {
196  TBOX blob_box = other.blobs[i]->bounding_box();
197  if (blob_box == boxes_[i])
198  cb->Run(i);
199  }
200  delete cb;
201 }
virtual void Run(A1)=0
int NumBlobs() const
Definition: blobs.h:425
Definition: rect.h:30
GenericVector< TBLOB * > blobs
Definition: blobs.h:436

The documentation for this class was generated from the following files: