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