tesseract  5.0.0-alpha-619-ge9db
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 #include "allheaders.h"
21 #include "blobbox.h"
22 #include "equationdetectbase.h"
23 
24 namespace tesseract {
25 
26 // Destructor.
27 // It is defined here, so the compiler can create a single vtable
28 // instead of weak vtables in every compilation unit.
30 
32  BLOBNBOX* blob) {
33  ASSERT_HOST(pix != nullptr && pixGetDepth(pix) == 32 && blob != nullptr);
34  const TBOX& tbox = blob->bounding_box();
35  int height = pixGetHeight(pix);
36  const int box_width = 5;
37 
38  // Coordinate translation: tesseract use left bottom as the original, while
39  // leptonica uses left top as the original.
40  Box *box = boxCreate(tbox.left(), height - tbox.top(),
41  tbox.width(), tbox.height());
42  switch (blob->special_text_type()) {
43  case BSTT_MATH: // Red box.
44  pixRenderBoxArb(pix, box, box_width, 255, 0, 0);
45  break;
46  case BSTT_DIGIT: // cyan box.
47  pixRenderBoxArb(pix, box, box_width, 0, 255, 255);
48  break;
49  case BSTT_ITALIC: // Green box.
50  pixRenderBoxArb(pix, box, box_width, 0, 255, 0);
51  break;
52  case BSTT_UNCLEAR: // blue box.
53  pixRenderBoxArb(pix, box, box_width, 0, 255, 0);
54  break;
55  case BSTT_NONE:
56  default:
57  // yellow box.
58  pixRenderBoxArb(pix, box, box_width, 255, 255, 0);
59  break;
60  }
61  boxDestroy(&box);
62 }
63 
64 } // namespace tesseract
tesseract::EquationDetectBase::~EquationDetectBase
virtual ~EquationDetectBase()
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
blobbox.h
TBOX::top
int16_t top() const
Definition: rect.h:57
tesseract::EquationDetectBase::RenderSpecialText
static void RenderSpecialText(Pix *pix, BLOBNBOX *blob)
Definition: equationdetectbase.cpp:31
equationdetectbase.h
BSTT_MATH
Definition: blobbox.h:99
BLOBNBOX
Definition: blobbox.h:142
BSTT_DIGIT
Definition: blobbox.h:98
TBOX::height
int16_t height() const
Definition: rect.h:107
BSTT_UNCLEAR
Definition: blobbox.h:100
BLOBNBOX::special_text_type
BlobSpecialTextType special_text_type() const
Definition: blobbox.h:288
TBOX::width
int16_t width() const
Definition: rect.h:114
tesseract
Definition: baseapi.h:65
BLOBNBOX::bounding_box
const TBOX & bounding_box() const
Definition: blobbox.h:229
TBOX::left
int16_t left() const
Definition: rect.h:71
BSTT_ITALIC
Definition: blobbox.h:97
BSTT_NONE
Definition: blobbox.h:96
TBOX
Definition: rect.h:33