tesseract  5.0.0-alpha-619-ge9db
boxword.h
Go to the documentation of this file.
1 // File: boxword.h
3 // Description: Class to represent the bounding boxes of the output.
4 // Author: Ray Smith
5 // Created: Tue May 25 14:18:14 PDT 2010
6 //
7 // (C) Copyright 2010, Google Inc.
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
19 
20 #ifndef TESSERACT_CSTRUCT_BOXWORD_H_
21 #define TESSERACT_CSTRUCT_BOXWORD_H_
22 
23 #include <functional> // for std::function
24 #include <tesseract/genericvector.h> // for GenericVector
25 #include "rect.h" // for TBOX
26 
27 class BLOCK;
28 class WERD;
29 
30 struct TWERD;
31 
32 namespace tesseract {
33 
34 // Class to hold an array of bounding boxes for an output word and
35 // the bounding box of the whole word.
36 class BoxWord {
37  public:
38  BoxWord();
39  explicit BoxWord(const BoxWord& src);
40  ~BoxWord() = default;
41 
42  BoxWord& operator=(const BoxWord& src);
43 
44  void CopyFrom(const BoxWord& src);
45 
46  // Factory to build a BoxWord from a TWERD using the DENORMs on each blob to
47  // switch back to original image coordinates.
48  static BoxWord* CopyFromNormalized(TWERD* tessword);
49 
50  // Clean up the bounding boxes from the polygonal approximation by
51  // expanding slightly, then clipping to the blobs from the original_word
52  // that overlap. If not null, the block provides the inverse rotation.
53  void ClipToOriginalWord(const BLOCK* block, WERD* original_word);
54 
55  // Merges the boxes from start to end, not including end, and deletes
56  // the boxes between start and end.
57  void MergeBoxes(int start, int end);
58 
59  // Inserts a new box before the given index.
60  // Recomputes the bounding box.
61  void InsertBox(int index, const TBOX& box);
62 
63  // Changes the box at the given index to the new box.
64  // Recomputes the bounding box.
65  void ChangeBox(int index, const TBOX& box);
66 
67  // Deletes the box with the given index, and shuffles up the rest.
68  // Recomputes the bounding box.
69  void DeleteBox(int index);
70 
71  // Deletes all the boxes stored in BoxWord.
72  void DeleteAllBoxes();
73 
74  // This and other putatively are the same, so call the (permanent) callback
75  // for each blob index where the bounding boxes match.
76  // The callback is deleted on completion.
77  void ProcessMatchedBlobs(const TWERD& other, std::function<void(int)> cb) const;
78 
79  const TBOX& bounding_box() const {
80  return bbox_;
81  }
82  int length() const { return length_; }
83  const TBOX& BlobBox(int index) const {
84  return boxes_[index];
85  }
86 
87  private:
88  void ComputeBoundingBox();
89 
90  TBOX bbox_;
91  int length_;
92  GenericVector<TBOX> boxes_;
93 };
94 
95 } // namespace tesseract.
96 
97 #endif // TESSERACT_CSTRUCT_BOXWORD_H_
tesseract::BoxWord::BoxWord
BoxWord()
Definition: boxword.cpp:33
tesseract::BoxWord::DeleteBox
void DeleteBox(int index)
Definition: boxword.cpp:166
tesseract::BoxWord::CopyFromNormalized
static BoxWord * CopyFromNormalized(TWERD *tessword)
Definition: boxword.cpp:56
TWERD
Definition: blobs.h:416
tesseract::BoxWord::ClipToOriginalWord
void ClipToOriginalWord(const BLOCK *block, WERD *original_word)
Definition: boxword.cpp:92
rect.h
tesseract::BoxWord::CopyFrom
void CopyFrom(const BoxWord &src)
Definition: boxword.cpp:45
genericvector.h
BLOCK
Definition: ocrblock.h:28
tesseract::BoxWord::BlobBox
const TBOX & BlobBox(int index) const
Definition: boxword.h:83
tesseract::BoxWord::ProcessMatchedBlobs
void ProcessMatchedBlobs(const TWERD &other, std::function< void(int)> cb) const
Definition: boxword.cpp:190
tesseract
Definition: baseapi.h:65
tesseract::BoxWord::~BoxWord
~BoxWord()=default
GenericVector< TBOX >
tesseract::BoxWord::InsertBox
void InsertBox(int index, const TBOX &box)
Definition: boxword.cpp:148
tesseract::BoxWord::length
int length() const
Definition: boxword.h:82
tesseract::BoxWord::ChangeBox
void ChangeBox(int index, const TBOX &box)
Definition: boxword.cpp:159
WERD
Definition: werd.h:55
tesseract::BoxWord::DeleteAllBoxes
void DeleteAllBoxes()
Definition: boxword.cpp:174
tesseract::BoxWord::operator=
BoxWord & operator=(const BoxWord &src)
Definition: boxword.cpp:40
tesseract::BoxWord::MergeBoxes
void MergeBoxes(int start, int end)
Definition: boxword.cpp:131
tesseract::BoxWord::bounding_box
const TBOX & bounding_box() const
Definition: boxword.h:79
TBOX
Definition: rect.h:33
tesseract::BoxWord
Definition: boxword.h:36