Tesseract  3.02
tesseract-ocr/textord/equationdetectbase.cpp
Go to the documentation of this file.
00001 
00002 // File:        equationdetectbase.cpp
00003 // Description: The base class equation detection class.
00004 // Author:      Zongyi (Joe) Liu (joeliu@google.com)
00005 // Created:     Fri Aug 31 11:13:01 PST 2011
00006 //
00007 // (C) Copyright 2011, Google Inc.
00008 // Licensed under the Apache License, Version 2.0 (the "License");
00009 // you may not use this file except in compliance with the License.
00010 // You may obtain a copy of the License at
00011 // http://www.apache.org/licenses/LICENSE-2.0
00012 // Unless required by applicable law or agreed to in writing, software
00013 // distributed under the License is distributed on an "AS IS" BASIS,
00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 // See the License for the specific language governing permissions and
00016 // limitations under the License.
00017 //
00019 
00020 #include "allheaders.h"
00021 #include "blobbox.h"
00022 #include "equationdetectbase.h"
00023 
00024 namespace tesseract {
00025 
00026 EquationDetectBase::EquationDetectBase() {
00027 }
00028 
00029 EquationDetectBase::~EquationDetectBase() {
00030 }
00031 
00032 void EquationDetectBase::RenderSpecialText(Pix* pix,
00033                                            BLOBNBOX* blob) {
00034   ASSERT_HOST(pix != NULL && pixGetDepth(pix) == 32 && blob != NULL);
00035   const TBOX& tbox = blob->bounding_box();
00036   int height = pixGetHeight(pix);
00037   const int box_width = 5;
00038 
00039   // Coordinate translation: tesseract use left bottom as the original, while
00040   // leptonica uses left top as the original.
00041   Box *box = boxCreate(tbox.left(), height - tbox.top(),
00042                          tbox.width(), tbox.height());
00043   switch (blob->special_text_type()) {
00044     case BSTT_MATH:  // Red box.
00045       pixRenderBoxArb(pix, box, box_width, 255, 0, 0);
00046       break;
00047     case BSTT_DIGIT:  // cyan box.
00048       pixRenderBoxArb(pix, box, box_width, 0, 255, 255);
00049       break;
00050     case BSTT_ITALIC:  // Green box.
00051       pixRenderBoxArb(pix, box, box_width, 0, 255, 0);
00052       break;
00053     case BSTT_UNCLEAR:  // blue box.
00054       pixRenderBoxArb(pix, box, box_width, 0, 255, 0);
00055       break;
00056     case BSTT_NONE:
00057     default:
00058       // yellow box.
00059       pixRenderBoxArb(pix, box, box_width, 255, 255, 0);
00060       break;
00061   }
00062   boxDestroy(&box);
00063 }
00064 
00065 };  // namespace tesseract