From fef5972d2344862060c97d5810fd77147346072e Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 30 Apr 2017 14:41:29 +0200 Subject: [PATCH] EquationDetect: Remove unneeded new / delete operations Signed-off-by: Stefan Weil --- ccmain/equationdetect.cpp | 27 +++++++++------------------ ccmain/equationdetect.h | 3 ++- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/ccmain/equationdetect.cpp b/ccmain/equationdetect.cpp index 91c3620e55..7e1d2a232d 100644 --- a/ccmain/equationdetect.cpp +++ b/ccmain/equationdetect.cpp @@ -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) { @@ -186,7 +177,7 @@ void EquationDetect::IdentifySpecialText( normed_blob->Normalize(NULL, NULL, NULL, x_orig, y_orig, scaling, scaling, 0.0f, static_cast(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; @@ -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; @@ -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) { diff --git a/ccmain/equationdetect.h b/ccmain/equationdetect.h index ddfdf5f5c9..9dff5a7681 100644 --- a/ccmain/equationdetect.h +++ b/ccmain/equationdetect.h @@ -23,6 +23,7 @@ #include "blobbox.h" #include "equationdetectbase.h" #include "genericvector.h" +#include "tesseractclass.h" #include "unichar.h" class BLOBNBOX; @@ -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.