tesseract  5.0.0-alpha-619-ge9db
tesseract::BoxWord Class Reference

#include <boxword.h>

Public Member Functions

 BoxWord ()
 
 BoxWord (const BoxWord &src)
 
 ~BoxWord ()=default
 
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, std::function< void(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 36 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 }

◆ ~BoxWord()

tesseract::BoxWord::~BoxWord ( )
default

Member Function Documentation

◆ BlobBox()

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

Definition at line 83 of file boxword.h.

83  {
84  return boxes_[index];
85  }

◆ bounding_box()

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

Definition at line 79 of file boxword.h.

79  {
80  return bbox_;
81  }

◆ ChangeBox()

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

Definition at line 159 of file boxword.cpp.

159  {
160  boxes_[index] = box;
161  ComputeBoundingBox();
162 }

◆ ClipToOriginalWord()

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

Definition at line 92 of file boxword.cpp.

92  {
93  for (int i = 0; i < length_; ++i) {
94  TBOX box = boxes_[i];
95  // Expand by a single pixel, as the poly approximation error is 1 pixel.
96  box = TBOX(box.left() - 1, box.bottom() - 1,
97  box.right() + 1, box.top() + 1);
98  // Now find the original box that matches.
99  TBOX original_box;
100  C_BLOB_IT b_it(original_word->cblob_list());
101  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
102  TBOX blob_box = b_it.data()->bounding_box();
103  if (block != nullptr)
104  blob_box.rotate(block->re_rotation());
105  if (blob_box.major_overlap(box)) {
106  original_box += blob_box;
107  }
108  }
109  if (!original_box.null_box()) {
110  if (NearlyEqual<int>(original_box.left(), box.left(), kBoxClipTolerance))
111  box.set_left(original_box.left());
112  if (NearlyEqual<int>(original_box.right(), box.right(),
114  box.set_right(original_box.right());
115  if (NearlyEqual<int>(original_box.top(), box.top(), kBoxClipTolerance))
116  box.set_top(original_box.top());
117  if (NearlyEqual<int>(original_box.bottom(), box.bottom(),
119  box.set_bottom(original_box.bottom());
120  }
121  original_box = original_word->bounding_box();
122  if (block != nullptr)
123  original_box.rotate(block->re_rotation());
124  boxes_[i] = box.intersection(original_box);
125  }
126  ComputeBoundingBox();
127 }

◆ CopyFrom()

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

Definition at line 45 of file boxword.cpp.

45  {
46  bbox_ = src.bbox_;
47  length_ = src.length_;
48  boxes_.clear();
49  boxes_.reserve(length_);
50  for (int i = 0; i < length_; ++i)
51  boxes_.push_back(src.boxes_[i]);
52 }

◆ CopyFromNormalized()

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

Definition at line 56 of file boxword.cpp.

56  {
57  auto* boxword = new BoxWord();
58  // Count the blobs.
59  boxword->length_ = tessword->NumBlobs();
60  // Allocate memory.
61  boxword->boxes_.reserve(boxword->length_);
62 
63  for (int b = 0; b < boxword->length_; ++b) {
64  TBLOB* tblob = tessword->blobs[b];
65  TBOX blob_box;
66  for (TESSLINE* outline = tblob->outlines; outline != nullptr;
67  outline = outline->next) {
68  EDGEPT* edgept = outline->loop;
69  // Iterate over the edges.
70  do {
71  if (!edgept->IsHidden() || !edgept->prev->IsHidden()) {
72  ICOORD pos(edgept->pos.x, edgept->pos.y);
73  TPOINT denormed;
74  tblob->denorm().DenormTransform(nullptr, edgept->pos, &denormed);
75  pos.set_x(denormed.x);
76  pos.set_y(denormed.y);
77  TBOX pt_box(pos, pos);
78  blob_box += pt_box;
79  }
80  edgept = edgept->next;
81  } while (edgept != outline->loop);
82  }
83  boxword->boxes_.push_back(blob_box);
84  }
85  boxword->ComputeBoundingBox();
86  return boxword;
87 }

◆ DeleteAllBoxes()

void tesseract::BoxWord::DeleteAllBoxes ( )

Definition at line 174 of file boxword.cpp.

174  {
175  length_ = 0;
176  boxes_.clear();
177  bbox_ = TBOX();
178 }

◆ DeleteBox()

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

Definition at line 166 of file boxword.cpp.

166  {
167  ASSERT_HOST(0 <= index && index < length_);
168  boxes_.remove(index);
169  --length_;
170  ComputeBoundingBox();
171 }

◆ InsertBox()

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

Definition at line 148 of file boxword.cpp.

148  {
149  if (index < length_)
150  boxes_.insert(box, index);
151  else
152  boxes_.push_back(box);
153  length_ = boxes_.size();
154  ComputeBoundingBox();
155 }

◆ length()

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

Definition at line 82 of file boxword.h.

82 { return length_; }

◆ MergeBoxes()

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

Definition at line 131 of file boxword.cpp.

131  {
132  start = ClipToRange(start, 0, length_);
133  end = ClipToRange(end, 0, length_);
134  if (end <= start + 1)
135  return;
136  for (int i = start + 1; i < end; ++i) {
137  boxes_[start] += boxes_[i];
138  }
139  int shrinkage = end - 1 - start;
140  length_ -= shrinkage;
141  for (int i = start + 1; i < length_; ++i)
142  boxes_[i] = boxes_[i + shrinkage];
143  boxes_.truncate(length_);
144 }

◆ operator=()

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

Definition at line 40 of file boxword.cpp.

40  {
41  CopyFrom(src);
42  return *this;
43 }

◆ ProcessMatchedBlobs()

void tesseract::BoxWord::ProcessMatchedBlobs ( const TWERD other,
std::function< void(int)>  cb 
) const

Definition at line 190 of file boxword.cpp.

191  {
192  for (int i = 0; i < length_ && i < other.NumBlobs(); ++i) {
193  TBOX blob_box = other.blobs[i]->bounding_box();
194  if (blob_box == boxes_[i])
195  cb(i);
196  }
197 }

The documentation for this class was generated from the following files:
TBOX
Definition: cleanapi_test.cc:19
GenericVector::remove
void remove(int index)
Definition: genericvector.h:765
tesseract::BoxWord::BoxWord
BoxWord()
Definition: boxword.cpp:33
ClipToRange
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:106
TBOX::intersection
TBOX intersection(const TBOX &box) const
Definition: rect.cpp:83
TPOINT
Definition: blobs.h:49
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
WERD::bounding_box
TBOX bounding_box() const
Definition: werd.cpp:147
TBLOB::outlines
TESSLINE * outlines
Definition: blobs.h:398
GenericVector::insert
void insert(const T &t, int index)
Definition: genericvector.h:750
TBLOB::denorm
const DENORM & denorm() const
Definition: blobs.h:361
EDGEPT::IsHidden
bool IsHidden() const
Definition: blobs.h:174
ICOORD
integer coordinate
Definition: points.h:30
TESSLINE
Definition: blobs.h:201
TBOX::top
int16_t top() const
Definition: rect.h:57
TBOX::set_top
void set_top(int y)
Definition: rect.h:60
TESSLINE::next
TESSLINE * next
Definition: blobs.h:279
TBOX::rotate
void rotate(const FCOORD &vec)
Definition: rect.h:196
tesseract::BoxWord::CopyFrom
void CopyFrom(const BoxWord &src)
Definition: boxword.cpp:45
WERD::cblob_list
C_BLOB_LIST * cblob_list()
Definition: werd.h:94
EDGEPT::prev
EDGEPT * prev
Definition: blobs.h:191
TBOX::set_right
void set_right(int x)
Definition: rect.h:81
GenericVector::push_back
int push_back(T object)
Definition: genericvector.h:799
TPOINT::x
int16_t x
Definition: blobs.h:91
DENORM::DenormTransform
void DenormTransform(const DENORM *last_denorm, const TPOINT &pt, TPOINT *original) const
Definition: normalis.cpp:389
tesseract::kBoxClipTolerance
const int kBoxClipTolerance
Definition: boxword.cpp:31
TPOINT::y
int16_t y
Definition: blobs.h:92
TWERD::blobs
GenericVector< TBLOB * > blobs
Definition: blobs.h:457
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
GenericVector::reserve
void reserve(int size)
Definition: genericvector.h:679
TBLOB
Definition: blobs.h:282
TBOX::major_overlap
bool major_overlap(const TBOX &box) const
Definition: rect.h:362
GenericVector::truncate
void truncate(int size)
Definition: genericvector.h:132
TBOX::left
int16_t left() const
Definition: rect.h:71
GenericVector::clear
void clear()
Definition: genericvector.h:857
TBOX::right
int16_t right() const
Definition: rect.h:78
EDGEPT
Definition: blobs.h:97
TBOX::set_bottom
void set_bottom(int y)
Definition: rect.h:67
BLOCK::re_rotation
FCOORD re_rotation() const
Definition: ocrblock.h:133
GenericVector::size
int size() const
Definition: genericvector.h:71
EDGEPT::pos
TPOINT pos
Definition: blobs.h:184
TWERD::NumBlobs
int NumBlobs() const
Definition: blobs.h:446
EDGEPT::next
EDGEPT * next
Definition: blobs.h:190
TBOX::set_left
void set_left(int x)
Definition: rect.h:74
TBOX
Definition: rect.h:33