tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
boxword.h
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 "genericvector.h" // for GenericVector
24 #include "rect.h" // for TBOX
25 
26 class BLOCK;
27 class WERD;
28 
29 struct TWERD;
30 
31 template <class A1> class TessCallback1;
32 
33 namespace tesseract {
34 
35 // Class to hold an array of bounding boxes for an output word and
36 // the bounding box of the whole word.
37 class BoxWord {
38  public:
39  BoxWord();
40  explicit BoxWord(const BoxWord& src);
41  ~BoxWord() = default;
42 
43  BoxWord& operator=(const BoxWord& src);
44 
45  void CopyFrom(const BoxWord& src);
46 
47  // Factory to build a BoxWord from a TWERD using the DENORMs on each blob to
48  // switch back to original image coordinates.
49  static BoxWord* CopyFromNormalized(TWERD* tessword);
50 
51  // Clean up the bounding boxes from the polygonal approximation by
52  // expanding slightly, then clipping to the blobs from the original_word
53  // that overlap. If not null, the block provides the inverse rotation.
54  void ClipToOriginalWord(const BLOCK* block, WERD* original_word);
55 
56  // Merges the boxes from start to end, not including end, and deletes
57  // the boxes between start and end.
58  void MergeBoxes(int start, int end);
59 
60  // Inserts a new box before the given index.
61  // Recomputes the bounding box.
62  void InsertBox(int index, const TBOX& box);
63 
64  // Changes the box at the given index to the new box.
65  // Recomputes the bounding box.
66  void ChangeBox(int index, const TBOX& box);
67 
68  // Deletes the box with the given index, and shuffles up the rest.
69  // Recomputes the bounding box.
70  void DeleteBox(int index);
71 
72  // Deletes all the boxes stored in BoxWord.
73  void DeleteAllBoxes();
74 
75  // This and other putatively are the same, so call the (permanent) callback
76  // for each blob index where the bounding boxes match.
77  // The callback is deleted on completion.
78  void ProcessMatchedBlobs(const TWERD& other, TessCallback1<int>* cb) const;
79 
80  const TBOX& bounding_box() const {
81  return bbox_;
82  }
83  int length() const { return length_; }
84  const TBOX& BlobBox(int index) const {
85  return boxes_[index];
86  }
87 
88  private:
89  void ComputeBoundingBox();
90 
92  int length_;
94 };
95 
96 } // namespace tesseract.
97 
98 #endif // TESSERACT_CSTRUCT_BOXWORD_H_
BoxWord()
Definition: boxword.cpp:33
void DeleteBox(int index)
Definition: boxword.cpp:166
Definition: werd.h:59
void InsertBox(int index, const TBOX &box)
Definition: boxword.cpp:148
int length_
Definition: boxword.h:92
void ClipToOriginalWord(const BLOCK *block, WERD *original_word)
Definition: boxword.cpp:92
void ChangeBox(int index, const TBOX &box)
Definition: boxword.cpp:159
void ComputeBoundingBox()
Definition: boxword.cpp:181
Definition: rect.h:34
Definition: boxword.h:31
Definition: baseapi.cpp:94
const TBOX & bounding_box() const
Definition: boxword.h:80
void MergeBoxes(int start, int end)
Definition: boxword.cpp:131
TBOX bbox_
Definition: boxword.h:91
Definition: blobs.h:402
Definition: ocrblock.h:30
int length() const
Definition: boxword.h:83
static BoxWord * CopyFromNormalized(TWERD *tessword)
Definition: boxword.cpp:56
void DeleteAllBoxes()
Definition: boxword.cpp:174
Definition: boxword.h:37
GenericVector< TBOX > boxes_
Definition: boxword.h:93
const TBOX & BlobBox(int index) const
Definition: boxword.h:84
void CopyFrom(const BoxWord &src)
Definition: boxword.cpp:45
void ProcessMatchedBlobs(const TWERD &other, TessCallback1< int > *cb) const
Definition: boxword.cpp:190
BoxWord & operator=(const BoxWord &src)
Definition: boxword.cpp:40