tesseract  5.0.0
equationdetectbase.cpp
Go to the documentation of this file.
1 // File: equationdetectbase.cpp
3 // Description: The base class equation detection class.
4 // Author: Zongyi (Joe) Liu (joeliu@google.com)
5 // Created: Fri Aug 31 11:13:01 PST 2011
6 //
7 // (C) Copyright 2011, 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 #ifdef HAVE_CONFIG_H
21 # include "config_auto.h"
22 #endif
23 
24 #include "equationdetectbase.h"
25 
26 #include "blobbox.h"
27 
28 #include <allheaders.h>
29 
30 namespace tesseract {
31 
32 // Destructor.
33 // It is defined here, so the compiler can create a single vtable
34 // instead of weak vtables in every compilation unit.
36 
38  ASSERT_HOST(pix != nullptr && pixGetDepth(pix) == 32 && blob != nullptr);
39  const TBOX &tbox = blob->bounding_box();
40  int height = pixGetHeight(pix);
41  const int box_width = 5;
42 
43  // Coordinate translation: tesseract use left bottom as the original, while
44  // leptonica uses left top as the original.
45  Box *box = boxCreate(tbox.left(), height - tbox.top(), tbox.width(), tbox.height());
46  switch (blob->special_text_type()) {
47  case BSTT_MATH: // Red box.
48  pixRenderBoxArb(pix, box, box_width, 255, 0, 0);
49  break;
50  case BSTT_DIGIT: // cyan box.
51  pixRenderBoxArb(pix, box, box_width, 0, 255, 255);
52  break;
53  case BSTT_ITALIC: // Green box.
54  pixRenderBoxArb(pix, box, box_width, 0, 255, 0);
55  break;
56  case BSTT_UNCLEAR: // blue box.
57  pixRenderBoxArb(pix, box, box_width, 0, 255, 0);
58  break;
59  case BSTT_NONE:
60  default:
61  // yellow box.
62  pixRenderBoxArb(pix, box, box_width, 255, 255, 0);
63  break;
64  }
65  boxDestroy(&box);
66 }
67 
68 } // namespace tesseract
#define ASSERT_HOST(x)
Definition: errcode.h:59
@ BSTT_MATH
Definition: blobbox.h:96
@ BSTT_UNCLEAR
Definition: blobbox.h:97
@ BSTT_DIGIT
Definition: blobbox.h:95
@ BSTT_ITALIC
Definition: blobbox.h:94
@ BSTT_NONE
Definition: blobbox.h:93
const TBOX & bounding_box() const
Definition: blobbox.h:239
BlobSpecialTextType special_text_type() const
Definition: blobbox.h:304
TDimension left() const
Definition: rect.h:82
TDimension height() const
Definition: rect.h:118
TDimension width() const
Definition: rect.h:126
TDimension top() const
Definition: rect.h:68
static void RenderSpecialText(Image pix, BLOBNBOX *blob)