Skip to content

Commit

Permalink
Merge pull request #930 from stweil/opt
Browse files Browse the repository at this point in the history
EquationDetect: Remove unneeded new / delete operations
  • Loading branch information
zdenop authored May 18, 2017
2 parents 8bd2fa7 + fef5972 commit 482cd82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
27 changes: 9 additions & 18 deletions ccmain/equationdetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,21 @@ EquationDetect::EquationDetect(const char* equ_datapath,
if (equ_name == NULL) {
equ_name = default_name;
}
equ_tesseract_ = lang_tesseract_ = NULL;
lang_tesseract_ = NULL;
resolution_ = 0;
page_count_ = 0;

// Construct equ_tesseract_.
equ_tesseract_ = new Tesseract();
if (equ_tesseract_->init_tesseract(equ_datapath, equ_name,
OEM_TESSERACT_ONLY)) {
if (equ_tesseract_.init_tesseract(equ_datapath, equ_name,
OEM_TESSERACT_ONLY)) {
tprintf("Warning: equation region detection requested,"
" but %s failed to load from %s\n", equ_name, equ_datapath);
delete equ_tesseract_;
equ_tesseract_ = NULL;
}

cps_super_bbox_ = NULL;
}

EquationDetect::~EquationDetect() {
if (equ_tesseract_) {
delete (equ_tesseract_);
}
if (cps_super_bbox_) {
delete(cps_super_bbox_);
}
delete(cps_super_bbox_);
}

void EquationDetect::SetLangTesseract(Tesseract* lang_tesseract) {
Expand Down Expand Up @@ -186,7 +177,7 @@ void EquationDetect::IdentifySpecialText(
normed_blob->Normalize(NULL, NULL, NULL, x_orig, y_orig, scaling, scaling,
0.0f, static_cast<float>(kBlnBaselineOffset),
false, NULL);
equ_tesseract_->AdaptiveClassifier(normed_blob, &ratings_equ);
equ_tesseract_.AdaptiveClassifier(normed_blob, &ratings_equ);
lang_tesseract_->AdaptiveClassifier(normed_blob, &ratings_lang);
delete normed_blob;
delete tblob;
Expand Down Expand Up @@ -272,8 +263,8 @@ BlobSpecialTextType EquationDetect::EstimateTypeForUnichar(

void EquationDetect::IdentifySpecialText() {
// Set configuration for Tesseract::AdaptiveClassifier.
equ_tesseract_->tess_cn_matching.set_value(true); // turn it on
equ_tesseract_->tess_bn_matching.set_value(false);
equ_tesseract_.tess_cn_matching.set_value(true); // turn it on
equ_tesseract_.tess_bn_matching.set_value(false);

// Set the multiplier to zero for lang_tesseract_ to improve the accuracy.
int classify_class_pruner = lang_tesseract_->classify_class_pruner_multiplier;
Expand Down Expand Up @@ -372,8 +363,8 @@ void EquationDetect::IdentifyBlobsToSkip(ColPartition* part) {

int EquationDetect::FindEquationParts(
ColPartitionGrid* part_grid, ColPartitionSet** best_columns) {
if (!equ_tesseract_ || !lang_tesseract_) {
tprintf("Warning: equ_tesseract_/lang_tesseract_ is NULL!\n");
if (!lang_tesseract_) {
tprintf("Warning: lang_tesseract_ is NULL!\n");
return -1;
}
if (!part_grid || !best_columns) {
Expand Down
3 changes: 2 additions & 1 deletion ccmain/equationdetect.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "blobbox.h"
#include "equationdetectbase.h"
#include "genericvector.h"
#include "tesseractclass.h"
#include "unichar.h"

class BLOBNBOX;
Expand Down Expand Up @@ -244,7 +245,7 @@ class EquationDetect : public EquationDetectBase {
void PrintSpecialBlobsDensity(const ColPartition* part) const;

// The tesseract engine intialized from equation training data.
Tesseract* equ_tesseract_;
Tesseract equ_tesseract_;

// The tesseract engine used for OCR. This pointer is passed in by the caller,
// so do NOT destroy it in this class.
Expand Down

0 comments on commit 482cd82

Please sign in to comment.