mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-06-07 18:02:40 +08:00
Merge pull request #930 from stweil/opt
EquationDetect: Remove unneeded new / delete operations
This commit is contained in:
commit
482cd82ca6
@ -108,30 +108,21 @@ EquationDetect::EquationDetect(const char* equ_datapath,
|
|||||||
if (equ_name == NULL) {
|
if (equ_name == NULL) {
|
||||||
equ_name = default_name;
|
equ_name = default_name;
|
||||||
}
|
}
|
||||||
equ_tesseract_ = lang_tesseract_ = NULL;
|
lang_tesseract_ = NULL;
|
||||||
resolution_ = 0;
|
resolution_ = 0;
|
||||||
page_count_ = 0;
|
page_count_ = 0;
|
||||||
|
|
||||||
// Construct equ_tesseract_.
|
if (equ_tesseract_.init_tesseract(equ_datapath, equ_name,
|
||||||
equ_tesseract_ = new Tesseract();
|
OEM_TESSERACT_ONLY)) {
|
||||||
if (equ_tesseract_->init_tesseract(equ_datapath, equ_name,
|
|
||||||
OEM_TESSERACT_ONLY)) {
|
|
||||||
tprintf("Warning: equation region detection requested,"
|
tprintf("Warning: equation region detection requested,"
|
||||||
" but %s failed to load from %s\n", equ_name, equ_datapath);
|
" but %s failed to load from %s\n", equ_name, equ_datapath);
|
||||||
delete equ_tesseract_;
|
|
||||||
equ_tesseract_ = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cps_super_bbox_ = NULL;
|
cps_super_bbox_ = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
EquationDetect::~EquationDetect() {
|
EquationDetect::~EquationDetect() {
|
||||||
if (equ_tesseract_) {
|
delete(cps_super_bbox_);
|
||||||
delete (equ_tesseract_);
|
|
||||||
}
|
|
||||||
if (cps_super_bbox_) {
|
|
||||||
delete(cps_super_bbox_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EquationDetect::SetLangTesseract(Tesseract* lang_tesseract) {
|
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,
|
normed_blob->Normalize(NULL, NULL, NULL, x_orig, y_orig, scaling, scaling,
|
||||||
0.0f, static_cast<float>(kBlnBaselineOffset),
|
0.0f, static_cast<float>(kBlnBaselineOffset),
|
||||||
false, NULL);
|
false, NULL);
|
||||||
equ_tesseract_->AdaptiveClassifier(normed_blob, &ratings_equ);
|
equ_tesseract_.AdaptiveClassifier(normed_blob, &ratings_equ);
|
||||||
lang_tesseract_->AdaptiveClassifier(normed_blob, &ratings_lang);
|
lang_tesseract_->AdaptiveClassifier(normed_blob, &ratings_lang);
|
||||||
delete normed_blob;
|
delete normed_blob;
|
||||||
delete tblob;
|
delete tblob;
|
||||||
@ -272,8 +263,8 @@ BlobSpecialTextType EquationDetect::EstimateTypeForUnichar(
|
|||||||
|
|
||||||
void EquationDetect::IdentifySpecialText() {
|
void EquationDetect::IdentifySpecialText() {
|
||||||
// Set configuration for Tesseract::AdaptiveClassifier.
|
// Set configuration for Tesseract::AdaptiveClassifier.
|
||||||
equ_tesseract_->tess_cn_matching.set_value(true); // turn it on
|
equ_tesseract_.tess_cn_matching.set_value(true); // turn it on
|
||||||
equ_tesseract_->tess_bn_matching.set_value(false);
|
equ_tesseract_.tess_bn_matching.set_value(false);
|
||||||
|
|
||||||
// Set the multiplier to zero for lang_tesseract_ to improve the accuracy.
|
// Set the multiplier to zero for lang_tesseract_ to improve the accuracy.
|
||||||
int classify_class_pruner = lang_tesseract_->classify_class_pruner_multiplier;
|
int classify_class_pruner = lang_tesseract_->classify_class_pruner_multiplier;
|
||||||
@ -372,8 +363,8 @@ void EquationDetect::IdentifyBlobsToSkip(ColPartition* part) {
|
|||||||
|
|
||||||
int EquationDetect::FindEquationParts(
|
int EquationDetect::FindEquationParts(
|
||||||
ColPartitionGrid* part_grid, ColPartitionSet** best_columns) {
|
ColPartitionGrid* part_grid, ColPartitionSet** best_columns) {
|
||||||
if (!equ_tesseract_ || !lang_tesseract_) {
|
if (!lang_tesseract_) {
|
||||||
tprintf("Warning: equ_tesseract_/lang_tesseract_ is NULL!\n");
|
tprintf("Warning: lang_tesseract_ is NULL!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!part_grid || !best_columns) {
|
if (!part_grid || !best_columns) {
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "blobbox.h"
|
#include "blobbox.h"
|
||||||
#include "equationdetectbase.h"
|
#include "equationdetectbase.h"
|
||||||
#include "genericvector.h"
|
#include "genericvector.h"
|
||||||
|
#include "tesseractclass.h"
|
||||||
#include "unichar.h"
|
#include "unichar.h"
|
||||||
|
|
||||||
class BLOBNBOX;
|
class BLOBNBOX;
|
||||||
@ -244,7 +245,7 @@ class EquationDetect : public EquationDetectBase {
|
|||||||
void PrintSpecialBlobsDensity(const ColPartition* part) const;
|
void PrintSpecialBlobsDensity(const ColPartition* part) const;
|
||||||
|
|
||||||
// The tesseract engine intialized from equation training data.
|
// 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,
|
// The tesseract engine used for OCR. This pointer is passed in by the caller,
|
||||||
// so do NOT destroy it in this class.
|
// so do NOT destroy it in this class.
|
||||||
|
Loading…
Reference in New Issue
Block a user