Merge pull request #514 from stweil/free

Simplify new operations
This commit is contained in:
zdenop 2016-12-01 20:36:24 +01:00 committed by GitHub
commit 690616279c
34 changed files with 66 additions and 520 deletions

View File

@ -819,10 +819,6 @@ bool TessPDFRenderer::imageToPDFObj(Pix *pix,
*pdf_object_size =
b1_len + colorspace_len + b2_len + cid->nbytescomp + b3_len;
*pdf_object = new char[*pdf_object_size];
if (!pdf_object) {
l_CIDataDestroy(&cid);
return false;
}
char *p = *pdf_object;
memcpy(p, b1, b1_len);

View File

@ -179,7 +179,7 @@ bool Tesseract::init_cube_objects(bool load_combiner,
// Create the combiner object and load the combiner net for target languages.
if (load_combiner) {
tess_cube_combiner_ = new tesseract::TesseractCubeCombiner(cube_cntxt_);
if (!tess_cube_combiner_ || !tess_cube_combiner_->LoadCombinerNet()) {
if (!tess_cube_combiner_->LoadCombinerNet()) {
delete cube_cntxt_;
cube_cntxt_ = NULL;
if (tess_cube_combiner_ != NULL) {

View File

@ -131,11 +131,6 @@ bool CubeRecoContext::Load(TessdataManager *tessdata_manager,
lang_mod_ = new TessLangModel(lm_params, data_file_path,
tess_obj_->getDict().load_system_dawg,
tessdata_manager, this);
if (lang_mod_ == NULL) {
fprintf(stderr, "Cube ERROR (CubeRecoContext::Load): unable to create "
"TessLangModel\n");
return false;
}
// Create the optional char bigrams object.
char_bigrams_ = CharBigrams::Create(data_file_path, lang_);
@ -176,11 +171,6 @@ CubeRecoContext * CubeRecoContext::Create(Tesseract *tess_obj,
UNICHARSET *tess_unicharset) {
// create the object
CubeRecoContext *cntxt = new CubeRecoContext(tess_obj);
if (cntxt == NULL) {
fprintf(stderr, "Cube ERROR (CubeRecoContext::Create): unable to create "
"CubeRecoContext object\n");
return NULL;
}
// load the necessary components
if (cntxt->Load(tessdata_manager, tess_unicharset) == false) {
fprintf(stderr, "Cube ERROR (CubeRecoContext::Create): unable to init "

View File

@ -123,11 +123,6 @@ WordAltList * BeamSearch::Search(SearchObject *srch_obj, LangModel *lang_mod) {
// alloc memory for columns
col_ = new SearchColumn *[col_cnt_];
if (!col_) {
fprintf(stderr, "Cube ERROR (BeamSearch::Search): could not construct "
"SearchColumn array\n");
return NULL;
}
memset(col_, 0, col_cnt_ * sizeof(*col_));
// for all possible segments
@ -135,11 +130,6 @@ WordAltList * BeamSearch::Search(SearchObject *srch_obj, LangModel *lang_mod) {
// create a search column
col_[end_seg - 1] = new SearchColumn(end_seg - 1,
cntxt_->Params()->BeamWidth());
if (!col_[end_seg - 1]) {
fprintf(stderr, "Cube ERROR (BeamSearch::Search): could not construct "
"SearchColumn for column %d\n", end_seg - 1);
return NULL;
}
// for all possible start segments
int init_seg = MAX(0, end_seg - cntxt_->Params()->MaxSegPerChar());
@ -402,11 +392,6 @@ CharSamp **BeamSearch::SplitByNode(SearchObject *srch_obj,
// Allocate memory for CharSamp array.
CharSamp **chars = new CharSamp *[*char_cnt];
if (!chars) {
if (char_boxes)
boxaDestroy(char_boxes);
return NULL;
}
int ch_idx = *char_cnt - 1;
int seg_pt_cnt = srch_obj->SegPtCnt();

View File

@ -72,17 +72,10 @@ unsigned char **Bmp8::CreateBmpBuffer(unsigned char init_val) {
stride_ = ((wid_ % 4) == 0) ? wid_ : (4 * (1 + (wid_ / 4)));
buff = (unsigned char **) new unsigned char *[hgt_ * sizeof(*buff)];
if (!buff) {
return NULL;
}
// alloc and init memory for buffer and line buffer
buff[0] = (unsigned char *)
new unsigned char[stride_ * hgt_ * sizeof(*buff[0])];
if (!buff[0]) {
delete []buff;
return NULL;
}
memset(buff[0], init_val, stride_ * hgt_ * sizeof(*buff[0]));
@ -100,16 +93,9 @@ unsigned int ** Bmp8::CreateBmpBuffer(int wid, int hgt,
// compute stride (align on 4 byte boundries)
buff = (unsigned int **) new unsigned int *[hgt * sizeof(*buff)];
if (!buff) {
return NULL;
}
// alloc and init memory for buffer and line buffer
buff[0] = (unsigned int *) new unsigned int[wid * hgt * sizeof(*buff[0])];
if (!buff[0]) {
delete []buff;
return NULL;
}
memset(buff[0], init_val, wid * hgt * sizeof(*buff[0]));
@ -172,9 +158,6 @@ bool Bmp8::LoadFromCharDumpFile(CachedFile *fp) {
// alloc memory & read the 3 channel buffer
buff = new unsigned char[buf_size];
if (buff == NULL) {
return false;
}
if (fp->Read(buff, buf_size) != buf_size) {
delete []buff;
@ -213,9 +196,6 @@ bool Bmp8::LoadFromCharDumpFile(CachedFile *fp) {
Bmp8 * Bmp8::FromCharDumpFile(CachedFile *fp) {
// create a Bmp8 object
Bmp8 *bmp_obj = new Bmp8(0, 0);
if (bmp_obj == NULL) {
return NULL;
}
if (bmp_obj->LoadFromCharDumpFile(fp) == false) {
delete bmp_obj;
@ -267,9 +247,6 @@ bool Bmp8::LoadFromCharDumpFile(FILE *fp) {
// alloc memory & read the 3 channel buffer
buff = new unsigned char[buf_size];
if (buff == NULL) {
return false;
}
if (fread(buff, 1, buf_size, fp) != buf_size) {
delete []buff;
@ -308,9 +285,6 @@ bool Bmp8::LoadFromCharDumpFile(FILE *fp) {
Bmp8 * Bmp8::FromCharDumpFile(FILE *fp) {
// create a Bmp8 object
Bmp8 *bmp_obj = new Bmp8(0, 0);
if (bmp_obj == NULL) {
return NULL;
}
if (bmp_obj->LoadFromCharDumpFile(fp) == false) {
delete bmp_obj;
@ -545,9 +519,6 @@ bool Bmp8::SaveBmp2CharDumpFile(FILE *fp) const {
// alloc memory & write the 3 channel buffer
buff = new unsigned char[buf_size];
if (buff == NULL) {
return false;
}
// copy the data
for (y = 0, pix = 0; y < hgt_; y++) {
@ -699,7 +670,7 @@ ConComp ** Bmp8::FindConComps(int *concomp_cnt, int min_size) const {
// if there was no foreground pix, then create a new concomp
if (master_concomp == NULL) {
master_concomp = new ConComp();
if (master_concomp == NULL || master_concomp->Add(x, y) == false) {
if (master_concomp->Add(x, y) == false) {
fprintf(stderr, "Cube ERROR (Bmp8::FindConComps): could not "
"allocate or add a connected component\n");
FreeBmpBuffer(out_bmp_array);
@ -711,13 +682,6 @@ ConComp ** Bmp8::FindConComps(int *concomp_cnt, int min_size) const {
if ((alloc_concomp_cnt % kConCompAllocChunk) == 0) {
ConComp **temp_con_comp =
new ConComp *[alloc_concomp_cnt + kConCompAllocChunk];
if (temp_con_comp == NULL) {
fprintf(stderr, "Cube ERROR (Bmp8::FindConComps): could not "
"extend array of connected components\n");
FreeBmpBuffer(out_bmp_array);
delete []concomp_array;
return NULL;
}
if (alloc_concomp_cnt > 0) {
memcpy(temp_con_comp, concomp_array,
@ -774,9 +738,6 @@ bool Bmp8::ComputeTanTable() {
// alloc memory for tan table
delete []tan_table_;
tan_table_ = new float[kDeslantAngleCount];
if (tan_table_ == NULL) {
return false;
}
for (ang_idx = 0, ang_val = kMinDeslantAngle;
ang_idx < kDeslantAngleCount; ang_idx++) {
@ -821,10 +782,6 @@ bool Bmp8::Deslant() {
int **angle_hist = new int*[kDeslantAngleCount];
for (ang_idx = 0; ang_idx < kDeslantAngleCount; ang_idx++) {
angle_hist[ang_idx] = new int[des_wid];
if (angle_hist[ang_idx] == NULL) {
delete[] angle_hist;
return false;
}
memset(angle_hist[ang_idx], 0, des_wid * sizeof(*angle_hist[ang_idx]));
}
@ -1006,10 +963,6 @@ bool Bmp8::HorizontalDeslant(double *deslant_angle) {
int **angle_hist = new int*[kDeslantAngleCount];
for (ang_idx = 0; ang_idx < kDeslantAngleCount; ang_idx++) {
angle_hist[ang_idx] = new int[des_hgt];
if (angle_hist[ang_idx] == NULL) {
delete[] angle_hist;
return false;
}
memset(angle_hist[ang_idx], 0, des_hgt * sizeof(*angle_hist[ang_idx]));
}
@ -1118,9 +1071,6 @@ float Bmp8::MeanHorizontalHistogramEntropy() const {
int *Bmp8::HorizontalHistogram() const {
int *hist = new int[hgt_];
if (hist == NULL) {
return NULL;
}
// compute histograms
for (int y = 0; y < hgt_; y++) {

View File

@ -68,9 +68,6 @@ bool CachedFile::Open() {
rewind(fp_);
// alloc memory for buffer
buff_ = new unsigned char[kCacheSize];
if (buff_ == NULL) {
return false;
}
// init counters
buff_size_ = 0;
buff_pos_ = 0;

View File

@ -56,10 +56,6 @@ bool CharAltList::Insert(int class_id, int cost, void *tag) {
alt_cost_ = new int[max_alt_];
alt_tag_ = new void *[max_alt_];
if (class_id_alt_ == NULL || alt_cost_ == NULL || alt_tag_ == NULL) {
return false;
}
memset(alt_tag_, 0, max_alt_ * sizeof(*alt_tag_));
}
@ -67,9 +63,6 @@ bool CharAltList::Insert(int class_id, int cost, void *tag) {
int class_cnt = char_set_->ClassCount();
class_id_cost_ = new int[class_cnt];
if (class_id_cost_ == NULL) {
return false;
}
for (int ich = 0; ich < class_cnt; ich++) {
class_id_cost_[ich] = WORST_COST;

View File

@ -61,11 +61,6 @@ CharBigrams *CharBigrams::Create(const string &data_file_path,
// construct a new object
CharBigrams *char_bigrams_obj = new CharBigrams();
if (char_bigrams_obj == NULL) {
fprintf(stderr, "Cube ERROR (CharBigrams::Create): could not create "
"character bigrams object.\n");
return NULL;
}
CharBigramTable *table = &char_bigrams_obj->bigram_table_;
table->total_cnt = 0;
@ -90,11 +85,6 @@ CharBigrams *CharBigrams::Create(const string &data_file_path,
// expand the bigram table
if (ch1 > table->max_char) {
CharBigram *char_bigram = new CharBigram[ch1 + 1];
if (char_bigram == NULL) {
fprintf(stderr, "Cube ERROR (CharBigrams::Create): error allocating "
"additional memory for character bigram table.\n");
return NULL;
}
if (table->char_bigram != NULL && table->max_char >= 0) {
memcpy(char_bigram, table->char_bigram,
@ -115,12 +105,6 @@ CharBigrams *CharBigrams::Create(const string &data_file_path,
if (ch2 > table->char_bigram[ch1].max_char) {
Bigram *bigram = new Bigram[ch2 + 1];
if (bigram == NULL) {
fprintf(stderr, "Cube ERROR (CharBigrams::Create): error allocating "
"memory for bigram.\n");
delete char_bigrams_obj;
return NULL;
}
if (table->char_bigram[ch1].bigram != NULL &&
table->char_bigram[ch1].max_char >= 0) {

View File

@ -106,9 +106,6 @@ CharSamp *CharSamp::FromCharDumpFile(CachedFile *fp) {
// the label is not null terminated in the file
if (val32 > 0 && val32 < MAX_UINT32) {
label32 = new char_32[val32 + 1];
if (label32 == NULL) {
return NULL;
}
// read label
if (fp->Read(label32, val32 * sizeof(*label32)) !=
(val32 * sizeof(*label32))) {
@ -156,10 +153,6 @@ CharSamp *CharSamp::FromCharDumpFile(CachedFile *fp) {
}
// create the object
CharSamp *char_samp = new CharSamp();
if (char_samp == NULL) {
delete [] label32;
return NULL;
}
// init
char_samp->label32_ = label32;
char_samp->page_ = page;
@ -206,9 +199,6 @@ CharSamp *CharSamp::FromCharDumpFile(FILE *fp) {
// the label is not null terminated in the file
if (val32 > 0 && val32 < MAX_UINT32) {
label32 = new char_32[val32 + 1];
if (label32 == NULL) {
return NULL;
}
// read label
if (fread(label32, 1, val32 * sizeof(*label32), fp) !=
(val32 * sizeof(*label32))) {
@ -235,10 +225,6 @@ CharSamp *CharSamp::FromCharDumpFile(FILE *fp) {
}
// create the object
CharSamp *char_samp = new CharSamp();
if (char_samp == NULL) {
delete [] label32;
return NULL;
}
// init
char_samp->label32_ = label32;
char_samp->page_ = page;
@ -261,9 +247,6 @@ CharSamp *CharSamp::FromCharDumpFile(FILE *fp) {
// specified width and height
CharSamp *CharSamp::Scale(int wid, int hgt, bool isotropic) {
CharSamp *scaled_samp = new CharSamp(wid, hgt);
if (scaled_samp == NULL) {
return NULL;
}
if (scaled_samp->ScaleFrom(this, isotropic) == false) {
delete scaled_samp;
return NULL;
@ -285,9 +268,6 @@ CharSamp *CharSamp::FromRawData(int left, int top, int wid, int hgt,
unsigned char *data) {
// create the object
CharSamp *char_samp = new CharSamp(left, top, wid, hgt);
if (char_samp == NULL) {
return NULL;
}
if (char_samp->LoadFromRawData(data) == false) {
delete char_samp;
return NULL;
@ -432,14 +412,6 @@ ConComp **CharSamp::Segment(int *segment_cnt, bool right_2_left,
if ((seg_cnt % kConCompAllocChunk) == 0) {
ConComp **temp_segm_array =
new ConComp *[seg_cnt + kConCompAllocChunk];
if (temp_segm_array == NULL) {
fprintf(stderr, "Cube ERROR (CharSamp::Segment): could not "
"allocate additional connected components\n");
delete []concomp_seg_array;
delete []concomp_array;
delete []seg_array;
return NULL;
}
if (seg_cnt > 0) {
memcpy(temp_segm_array, seg_array, seg_cnt * sizeof(*seg_array));
delete []seg_array;
@ -497,8 +469,6 @@ CharSamp *CharSamp::FromConComps(ConComp **concomp_array, int strt_concomp,
bool *id_exist = new bool[id_cnt];
bool *left_most_exist = new bool[id_cnt];
bool *right_most_exist = new bool[id_cnt];
if (!id_exist || !left_most_exist || !right_most_exist)
return NULL;
memset(id_exist, 0, id_cnt * sizeof(*id_exist));
memset(left_most_exist, 0, id_cnt * sizeof(*left_most_exist));
memset(right_most_exist, 0, id_cnt * sizeof(*right_most_exist));
@ -555,9 +525,6 @@ CharSamp *CharSamp::FromConComps(ConComp **concomp_array, int strt_concomp,
(*right_most) = (unq_right_most >= unq_ids);
// create the char sample object
CharSamp *samp = new CharSamp(left, top, right - left + 1, bottom - top + 1);
if (!samp) {
return NULL;
}
// set the foreground pixels
for (concomp = strt_concomp; concomp < end_concomp; concomp++) {
@ -605,9 +572,6 @@ CharSamp *CharSamp::FromCharDumpFile(unsigned char **raw_data_ptr) {
// the label is not null terminated in the file
if (val32 > 0 && val32 < MAX_UINT32) {
label32 = new char_32[val32 + 1];
if (label32 == NULL) {
return NULL;
}
// read label
memcpy(label32, raw_data, val32 * sizeof(*label32));
raw_data += (val32 * sizeof(*label32));
@ -619,9 +583,6 @@ CharSamp *CharSamp::FromCharDumpFile(unsigned char **raw_data_ptr) {
// create the object
CharSamp *char_samp = new CharSamp();
if (char_samp == NULL) {
return NULL;
}
// read coordinates
char_samp->label32_ = label32;

View File

@ -66,20 +66,14 @@ class CharSamp : public Bmp8 {
void SetTop(unsigned short top) { top_ = top; }
void SetPage(unsigned short page) { page_ = page; }
void SetLabel(char_32 label) {
if (label32_ != NULL) {
delete []label32_;
}
delete []label32_;
label32_ = new char_32[2];
if (label32_ != NULL) {
label32_[0] = label;
label32_[1] = 0;
}
label32_[0] = label;
label32_[1] = 0;
}
void SetLabel(const char_32 *label32) {
if (label32_ != NULL) {
delete []label32_;
label32_ = NULL;
}
delete []label32_;
label32_ = NULL;
if (label32 != NULL) {
// remove any byte order marks if any
if (label32[0] == 0xfeff) {
@ -87,10 +81,8 @@ class CharSamp : public Bmp8 {
}
int len = LabelLen(label32);
label32_ = new char_32[len + 1];
if (label32_ != NULL) {
memcpy(label32_, label32, len * sizeof(*label32));
label32_[len] = 0;
}
memcpy(label32_, label32, len * sizeof(*label32));
label32_[len] = 0;
}
}
void SetLabel(string str);

View File

@ -55,9 +55,6 @@ bool CharSampSet::Add(CharSamp *char_samp) {
// create an extended buffer
CharSamp **new_samp_buff =
reinterpret_cast<CharSamp **>(new CharSamp *[cnt_ + SAMP_ALLOC_BLOCK]);
if (new_samp_buff == NULL) {
return false;
}
// copy old contents
if (cnt_ > 0) {
memcpy(new_samp_buff, samp_buff_, cnt_ * sizeof(*samp_buff_));
@ -107,10 +104,6 @@ CharSampSet * CharSampSet::FromCharDumpFile(string file_name) {
}
// create an object
CharSampSet *samp_set = new CharSampSet();
if (samp_set == NULL) {
fclose(fp);
return NULL;
}
if (samp_set->LoadCharSamples(fp) == false) {
delete samp_set;
samp_set = NULL;
@ -146,9 +139,6 @@ bool CharSampSet::EnumSamples(string file_name, CharSampEnum *enum_obj) {
i64_pos;
// open the file
fp_in = new CachedFile(file_name);
if (fp_in == NULL) {
return false;
}
i64_size = fp_in->Size();
if (i64_size < 1) {
return false;

View File

@ -54,9 +54,6 @@ CharSet::~CharSet() {
CharSet *CharSet::Create(TessdataManager *tessdata_manager,
UNICHARSET *tess_unicharset) {
CharSet *char_set = new CharSet();
if (char_set == NULL) {
return NULL;
}
// First look for Cube's unicharset; if not there, use tesseract's
bool cube_unicharset_exists;
@ -119,19 +116,9 @@ bool CharSet::LoadSupportedCharList(FILE *fp, UNICHARSET *tess_unicharset) {
}
// memory for class strings
class_strings_ = new string_32*[class_cnt_];
if (class_strings_ == NULL) {
fprintf(stderr, "Cube ERROR (CharSet::InitMemory): could not "
"allocate memory for class strings.\n");
return false;
}
// memory for unicharset map
if (tess_unicharset) {
unicharset_map_ = new int[class_cnt_];
if (unicharset_map_ == NULL) {
fprintf(stderr, "Cube ERROR (CharSet::InitMemory): could not "
"allocate memory for unicharset map.\n");
return false;
}
}
// Read in character strings and add to hash table
@ -154,11 +141,6 @@ bool CharSet::LoadSupportedCharList(FILE *fp, UNICHARSET *tess_unicharset) {
}
CubeUtils::UTF8ToUTF32(str_line, &str32);
class_strings_[class_id] = new string_32(str32);
if (class_strings_[class_id] == NULL) {
fprintf(stderr, "Cube ERROR (CharSet::ReadAndHashStrings): could not "
"allocate memory for class string with class_id=%d.\n", class_id);
return false;
}
// Add to hash-table
int hash_val = Hash(reinterpret_cast<const char_32 *>(str32.c_str()));

View File

@ -56,12 +56,6 @@ CharClassifier *CharClassifierFactory::Create(const string &data_file_path,
return NULL;
}
if (feat_extract == NULL) {
fprintf(stderr, "Cube ERROR (CharClassifierFactory::Create): unable "
"to instantiate feature extraction object.\n");
return NULL;
}
// create the classifier object
CharClassifier *classifier_obj;
switch (params->TypeClassifier()) {
@ -79,12 +73,6 @@ CharClassifier *CharClassifierFactory::Create(const string &data_file_path,
return NULL;
}
if (classifier_obj == NULL) {
fprintf(stderr, "Cube ERROR (CharClassifierFactory::Create): error "
"allocating memory for character classifier object.\n");
return NULL;
}
// Init the classifier
if (!classifier_obj->Init(data_file_path, lang, lang_mod)) {
delete classifier_obj;

View File

@ -52,9 +52,6 @@ ConComp::~ConComp() {
// adds a pt to the conn comp and updates its boundaries
bool ConComp::Add(int x, int y) {
ConCompPt *pt_ptr = new ConCompPt(x, y);
if (pt_ptr == NULL) {
return false;
}
if (head_ == NULL) {
left_ = x;
@ -114,9 +111,6 @@ int *ConComp::CreateHistogram(int max_hist_wnd) {
// alloc memo for histogram
int *hist_array = new int[wid];
if (hist_array == NULL) {
return NULL;
}
memset(hist_array, 0, wid * sizeof(*hist_array));
@ -148,9 +142,6 @@ int *ConComp::SegmentHistogram(int *hist_array, int *seg_pt_cnt) {
hgt = bottom_ - top_ + 1;
int *x_seg_pt = new int[wid];
if (x_seg_pt == NULL) {
return NULL;
}
int seg_pt_wnd = static_cast<int>(hgt * SEG_PT_WND_RATIO);
@ -216,18 +207,9 @@ ConComp **ConComp::Segment(int max_hist_wnd, int *concomp_cnt) {
// create concomp array
ConComp **concomp_array = new ConComp *[seg_pt_cnt + 1];
if (concomp_array == NULL) {
delete []x_seg_pt;
return NULL;
}
for (int concomp = 0; concomp <= seg_pt_cnt; concomp++) {
concomp_array[concomp] = new ConComp();
if (concomp_array[concomp] == NULL) {
delete []x_seg_pt;
delete []concomp_array;
return NULL;
}
// split concomps inherit the ID this concomp
concomp_array[concomp]->SetID(id_);

View File

@ -147,18 +147,7 @@ bool ConvNetCharClassifier::RunNets(CharSamp *char_samp) {
// allocate i/p and o/p buffers if needed
if (net_input_ == NULL) {
net_input_ = new float[feat_cnt];
if (net_input_ == NULL) {
fprintf(stderr, "Cube ERROR (ConvNetCharClassifier::RunNets): "
"unable to allocate memory for input nodes\n");
return false;
}
net_output_ = new float[class_cnt];
if (net_output_ == NULL) {
fprintf(stderr, "Cube ERROR (ConvNetCharClassifier::RunNets): "
"unable to allocate memory for output nodes\n");
return false;
}
}
// compute input features
@ -205,11 +194,6 @@ CharAltList *ConvNetCharClassifier::Classify(CharSamp *char_samp) {
// create an altlist
CharAltList *alt_list = new CharAltList(char_set_, class_cnt);
if (alt_list == NULL) {
fprintf(stderr, "Cube WARNING (ConvNetCharClassifier::Classify): "
"returning emtpy CharAltList\n");
return NULL;
}
for (int out = 1; out < class_cnt; out++) {
int cost = CubeUtils::Prob2Cost(net_output_[out]);
@ -261,14 +245,7 @@ bool ConvNetCharClassifier::LoadFoldingSets(const string &data_file_path,
fold_set_cnt_ = str_vec.size();
fold_sets_ = new int *[fold_set_cnt_];
if (fold_sets_ == NULL) {
return false;
}
fold_set_len_ = new int[fold_set_cnt_];
if (fold_set_len_ == NULL) {
fold_set_cnt_ = 0;
return false;
}
for (int fold_set = 0; fold_set < fold_set_cnt_; fold_set++) {
reinterpret_cast<TessLangModel *>(lang_mod)->RemoveInvalidCharacters(
@ -287,12 +264,6 @@ bool ConvNetCharClassifier::LoadFoldingSets(const string &data_file_path,
CubeUtils::UTF8ToUTF32(str_vec[fold_set].c_str(), &str32);
fold_set_len_[fold_set] = str32.length();
fold_sets_[fold_set] = new int[fold_set_len_[fold_set]];
if (fold_sets_[fold_set] == NULL) {
fprintf(stderr, "Cube ERROR (ConvNetCharClassifier::LoadFoldingSets): "
"could not allocate folding set\n");
fold_set_cnt_ = fold_set;
return false;
}
for (int ch = 0; ch < fold_set_len_[fold_set]; ch++) {
fold_sets_[fold_set][ch] = char_set_->ClassID(str32[ch]);
}
@ -375,14 +346,7 @@ bool ConvNetCharClassifier::LoadNets(const string &data_file_path,
// allocate i/p and o/p buffers if needed
if (net_input_ == NULL) {
net_input_ = new float[feat_cnt];
if (net_input_ == NULL) {
return false;
}
net_output_ = new float[class_cnt];
if (net_output_ == NULL) {
return false;
}
}
return true;

View File

@ -91,68 +91,62 @@ bool CubeLineObject::Process() {
if (word_break_threshold > 0) {
// over-allocate phrases object buffer
phrases_ = new CubeObject *[con_comp_cnt];
if (phrases_ != NULL) {
// create a phrase if the horizontal distance between two consecutive
// concomps is higher than threshold
int start_con_idx = 0;
int current_phrase_limit = rtl ? con_comps[0]->Left() :
con_comps[0]->Right();
// create a phrase if the horizontal distance between two consecutive
// concomps is higher than threshold
int start_con_idx = 0;
int current_phrase_limit = rtl ? con_comps[0]->Left() :
con_comps[0]->Right();
for (int con_idx = 1; con_idx <= con_comp_cnt; con_idx++) {
bool create_new_phrase = true;
// if not at the end, compute the distance between two consecutive
// concomps
if (con_idx < con_comp_cnt) {
int dist = 0;
if (cntxt_->ReadingOrder() == tesseract::CubeRecoContext::R2L) {
dist = current_phrase_limit - con_comps[con_idx]->Right();
} else {
dist = con_comps[con_idx]->Left() - current_phrase_limit;
}
create_new_phrase = (dist > word_break_threshold);
}
// create a new phrase
if (create_new_phrase) {
// create a phrase corresponding to a range on components
bool left_most;
bool right_most;
CharSamp *phrase_char_samp =
CharSamp::FromConComps(con_comps, start_con_idx,
con_idx - start_con_idx, NULL,
&left_most, &right_most,
line_pix_->h);
if (phrase_char_samp == NULL) {
break;
}
phrases_[phrase_cnt_] = new CubeObject(cntxt_, phrase_char_samp);
if (phrases_[phrase_cnt_] == NULL) {
delete phrase_char_samp;
break;
}
// set the ownership of the charsamp to the cube object
phrases_[phrase_cnt_]->SetCharSampOwnership(true);
phrase_cnt_++;
// advance the starting index to the current index
start_con_idx = con_idx;
// set the limit of the newly starting phrase (if any)
if (con_idx < con_comp_cnt) {
current_phrase_limit = rtl ? con_comps[con_idx]->Left() :
con_comps[con_idx]->Right();
}
for (int con_idx = 1; con_idx <= con_comp_cnt; con_idx++) {
bool create_new_phrase = true;
// if not at the end, compute the distance between two consecutive
// concomps
if (con_idx < con_comp_cnt) {
int dist = 0;
if (cntxt_->ReadingOrder() == tesseract::CubeRecoContext::R2L) {
dist = current_phrase_limit - con_comps[con_idx]->Right();
} else {
// update the limit of the current phrase
if (cntxt_->ReadingOrder() == tesseract::CubeRecoContext::R2L) {
current_phrase_limit = MIN(current_phrase_limit,
con_comps[con_idx]->Left());
} else {
current_phrase_limit = MAX(current_phrase_limit,
con_comps[con_idx]->Right());
}
dist = con_comps[con_idx]->Left() - current_phrase_limit;
}
create_new_phrase = (dist > word_break_threshold);
}
// create a new phrase
if (create_new_phrase) {
// create a phrase corresponding to a range on components
bool left_most;
bool right_most;
CharSamp *phrase_char_samp =
CharSamp::FromConComps(con_comps, start_con_idx,
con_idx - start_con_idx, NULL,
&left_most, &right_most,
line_pix_->h);
if (phrase_char_samp == NULL) {
break;
}
phrases_[phrase_cnt_] = new CubeObject(cntxt_, phrase_char_samp);
// set the ownership of the charsamp to the cube object
phrases_[phrase_cnt_]->SetCharSampOwnership(true);
phrase_cnt_++;
// advance the starting index to the current index
start_con_idx = con_idx;
// set the limit of the newly starting phrase (if any)
if (con_idx < con_comp_cnt) {
current_phrase_limit = rtl ? con_comps[con_idx]->Left() :
con_comps[con_idx]->Right();
}
} else {
// update the limit of the current phrase
if (cntxt_->ReadingOrder() == tesseract::CubeRecoContext::R2L) {
current_phrase_limit = MIN(current_phrase_limit,
con_comps[con_idx]->Left());
} else {
current_phrase_limit = MAX(current_phrase_limit,
con_comps[con_idx]->Right());
}
}
ret_val = true;
}
ret_val = true;
}
// clean-up connected comps

View File

@ -126,9 +126,6 @@ Pixa *CubeLineSegmenter::CrackLine(Pix *cracked_line_pix,
Box *cracked_line_box, int line_cnt) {
// create lines pixa array
Pixa **lines_pixa = new Pixa*[line_cnt];
if (lines_pixa == NULL) {
return NULL;
}
memset(lines_pixa, 0, line_cnt * sizeof(*lines_pixa));
@ -620,9 +617,6 @@ bool CubeLineSegmenter::AddLines(Pixa *lines) {
// Index the specific pixa using RTL reading order
int *CubeLineSegmenter::IndexRTL(Pixa *pixa) {
int *pix_index = new int[pixa->n];
if (pix_index == NULL) {
return NULL;
}
for (int pix = 0; pix < pixa->n; pix++) {
pix_index[pix] = pix;

View File

@ -115,21 +115,11 @@ WordAltList *CubeObject::Recognize(LangModel *lang_mod, bool word_mode) {
// create a beam search object
if (beam_obj_ == NULL) {
beam_obj_ = new BeamSearch(cntxt_, word_mode);
if (beam_obj_ == NULL) {
fprintf(stderr, "Cube ERROR (CubeObject::Recognize): could not construct "
"BeamSearch\n");
return NULL;
}
}
// create a cube search object
if (srch_obj_ == NULL) {
srch_obj_ = new CubeSearchObject(cntxt_, char_samp_);
if (srch_obj_ == NULL) {
fprintf(stderr, "Cube ERROR (CubeObject::Recognize): could not construct "
"CubeSearchObject\n");
return NULL;
}
}
// run a beam search against the tesslang model
@ -142,11 +132,6 @@ WordAltList *CubeObject::Recognize(LangModel *lang_mod, bool word_mode) {
if (deslanted_beam_obj_ == NULL) {
deslanted_beam_obj_ = new BeamSearch(cntxt_);
if (deslanted_beam_obj_ == NULL) {
fprintf(stderr, "Cube ERROR (CubeObject::Recognize): could not "
"construct deslanted BeamSearch\n");
return NULL;
}
}
if (deslanted_srch_obj_ == NULL) {
@ -162,11 +147,6 @@ WordAltList *CubeObject::Recognize(LangModel *lang_mod, bool word_mode) {
}
deslanted_srch_obj_ = new CubeSearchObject(cntxt_, deslanted_char_samp_);
if (deslanted_srch_obj_ == NULL) {
fprintf(stderr, "Cube ERROR (CubeObject::Recognize): could not "
"construct deslanted CubeSearchObject\n");
return NULL;
}
}
// run a beam search against the tesslang model
@ -205,9 +185,6 @@ WordAltList *CubeObject::RecognizePhrase(LangModel *lang_mod) {
*/
int CubeObject::WordCost(const char *str) {
WordListLangModel *lang_mod = new WordListLangModel(cntxt_);
if (lang_mod == NULL) {
return WORST_COST;
}
if (lang_mod->AddString(str) == false) {
delete lang_mod;
@ -242,9 +219,6 @@ CharAltList *CubeObject::RecognizeChar() {
bool CubeObject::Normalize() {
// create a cube search object
CubeSearchObject *srch_obj = new CubeSearchObject(cntxt_, char_samp_);
if (srch_obj == NULL) {
return false;
}
// Perform over-segmentation
int seg_cnt = srch_obj->SegPtCnt();
// Only perform normalization if segment count is large enough

View File

@ -127,36 +127,14 @@ bool CubeSearchObject::Init() {
// init cache
reco_cache_ = new CharAltList **[segment_cnt_];
if (reco_cache_ == NULL) {
fprintf(stderr, "Cube ERROR (CubeSearchObject::Init): could not "
"allocate CharAltList array\n");
return false;
}
samp_cache_ = new CharSamp **[segment_cnt_];
if (samp_cache_ == NULL) {
fprintf(stderr, "Cube ERROR (CubeSearchObject::Init): could not "
"allocate CharSamp array\n");
return false;
}
for (int seg = 0; seg < segment_cnt_; seg++) {
reco_cache_[seg] = new CharAltList *[segment_cnt_];
if (reco_cache_[seg] == NULL) {
fprintf(stderr, "Cube ERROR (CubeSearchObject::Init): could not "
"allocate a single segment's CharAltList array\n");
return false;
}
memset(reco_cache_[seg], 0, segment_cnt_ * sizeof(*reco_cache_[seg]));
samp_cache_[seg] = new CharSamp *[segment_cnt_];
if (samp_cache_[seg] == NULL) {
fprintf(stderr, "Cube ERROR (CubeSearchObject::Init): could not "
"allocate a single segment's CharSamp array\n");
return false;
}
memset(samp_cache_[seg], 0, segment_cnt_ * sizeof(*samp_cache_[seg]));
}
@ -305,12 +283,10 @@ CharAltList * CubeSearchObject::RecognizeSegment(int start_pt, int end_pt) {
exp(-fabs(seg_cnt - 2.0)) *
exp(-samp->Width() / static_cast<double>(samp->Height()));
if (alt_list) {
for (int class_idx = 0; class_idx < class_cnt; class_idx++) {
alt_list->Insert(class_idx, CubeUtils::Prob2Cost(prob_val));
}
reco_cache_[start_pt + 1][end_pt] = alt_list;
for (int class_idx = 0; class_idx < class_cnt; class_idx++) {
alt_list->Insert(class_idx, CubeUtils::Prob2Cost(prob_val));
}
reco_cache_[start_pt + 1][end_pt] = alt_list;
}
return reco_cache_[start_pt + 1][end_pt];
@ -353,11 +329,6 @@ bool CubeSearchObject::ComputeSpaceCosts() {
// segmentation point
int *max_left_x = new int[segment_cnt_ - 1];
int *min_right_x = new int[segment_cnt_ - 1];
if (!max_left_x || !min_right_x) {
delete []min_right_x;
delete []max_left_x;
return false;
}
if (rtl_) {
min_right_x[0] = segments_[0]->Left();
max_left_x[segment_cnt_ - 2] = segments_[segment_cnt_ - 1]->Right();
@ -384,11 +355,6 @@ bool CubeSearchObject::ComputeSpaceCosts() {
// trivial cases
space_cost_ = new int[segment_cnt_ - 1];
no_space_cost_ = new int[segment_cnt_ - 1];
if (!space_cost_ || !no_space_cost_) {
delete []min_right_x;
delete []max_left_x;
return false;
}
// go through all segmentation points determining the horizontal gap between
// the images on both sides of each break points. Use the gap to estimate

View File

@ -54,11 +54,6 @@ CubeTuningParams::~CubeTuningParams() {
CubeTuningParams *CubeTuningParams::Create(const string &data_file_path,
const string &lang) {
CubeTuningParams *obj = new CubeTuningParams();
if (!obj) {
fprintf(stderr, "Cube ERROR (CubeTuningParams::Create): unable to "
"allocate new tuning params object\n");
return NULL;
}
string tuning_params_file;
tuning_params_file = data_file_path + lang;

View File

@ -90,9 +90,6 @@ int CubeUtils::StrCmp(const char_32 *str1, const char_32 *str2) {
char_32 *CubeUtils::StrDup(const char_32 *str32) {
int len = StrLen(str32);
char_32 *new_str = new char_32[len + 1];
if (new_str == NULL) {
return NULL;
}
memcpy(new_str, str32, len * sizeof(*str32));
new_str[len] = 0;
return new_str;
@ -165,9 +162,6 @@ unsigned char *CubeUtils::GetImageData(Pix *pix, int left, int top,
// copy the char img to a temp buffer
unsigned char *temp_buff = new unsigned char[wid * hgt];
if (temp_buff == NULL) {
return NULL;
}
l_int32 w;
l_int32 h;
l_int32 d;
@ -211,10 +205,6 @@ bool CubeUtils::ReadFileToString(const string &file_name, string *str) {
// read the contents
rewind(fp);
char *buff = new char[file_size];
if (buff == NULL) {
fclose(fp);
return false;
}
int read_bytes = fread(buff, 1, static_cast<int>(file_size), fp);
if (read_bytes == file_size) {
str->append(buff, file_size);
@ -352,8 +342,6 @@ char_32 *CubeUtils::ToLower(const char_32 *str32, CharSet *char_set) {
UNICHARSET *unicharset = char_set->InternalUnicharset();
int len = StrLen(str32);
char_32 *lower = new char_32[len + 1];
if (!lower)
return NULL;
for (int i = 0; i < len; ++i) {
char_32 ch = str32[i];
if (ch == INVALID_UNICHAR_ID) {
@ -385,8 +373,6 @@ char_32 *CubeUtils::ToUpper(const char_32 *str32, CharSet *char_set) {
UNICHARSET *unicharset = char_set->InternalUnicharset();
int len = StrLen(str32);
char_32 *upper = new char_32[len + 1];
if (!upper)
return NULL;
for (int i = 0; i < len; ++i) {
char_32 ch = str32[i];
if (ch == INVALID_UNICHAR_ID) {

View File

@ -136,14 +136,7 @@ bool HybridNeuralNetCharClassifier::RunNets(CharSamp *char_samp) {
// allocate i/p and o/p buffers if needed
if (net_input_ == NULL) {
net_input_ = new float[feat_cnt];
if (net_input_ == NULL) {
return false;
}
net_output_ = new float[class_cnt];
if (net_output_ == NULL) {
return false;
}
}
// compute input features
@ -196,9 +189,6 @@ CharAltList *HybridNeuralNetCharClassifier::Classify(CharSamp *char_samp) {
// create an altlist
CharAltList *alt_list = new CharAltList(char_set_, class_cnt);
if (alt_list == NULL) {
return NULL;
}
for (int out = 1; out < class_cnt; out++) {
int cost = CubeUtils::Prob2Cost(net_output_[out]);
@ -240,14 +230,7 @@ bool HybridNeuralNetCharClassifier::LoadFoldingSets(
CubeUtils::SplitStringUsing(fold_sets_str, "\r\n", &str_vec);
fold_set_cnt_ = str_vec.size();
fold_sets_ = new int *[fold_set_cnt_];
if (fold_sets_ == NULL) {
return false;
}
fold_set_len_ = new int[fold_set_cnt_];
if (fold_set_len_ == NULL) {
fold_set_cnt_ = 0;
return false;
}
for (int fold_set = 0; fold_set < fold_set_cnt_; fold_set++) {
reinterpret_cast<TessLangModel *>(lang_mod)->RemoveInvalidCharacters(
@ -266,12 +249,6 @@ bool HybridNeuralNetCharClassifier::LoadFoldingSets(
CubeUtils::UTF8ToUTF32(str_vec[fold_set].c_str(), &str32);
fold_set_len_[fold_set] = str32.length();
fold_sets_[fold_set] = new int[fold_set_len_[fold_set]];
if (fold_sets_[fold_set] == NULL) {
fprintf(stderr, "Cube ERROR (ConvNetCharClassifier::LoadFoldingSets): "
"could not allocate folding set\n");
fold_set_cnt_ = fold_set;
return false;
}
for (int ch = 0; ch < fold_set_len_[fold_set]; ch++) {
fold_sets_[fold_set][ch] = char_set_->ClassID(str32[ch]);
}

View File

@ -62,9 +62,6 @@ bool SearchColumn::Init() {
// create hash table
if (node_hash_table_ == NULL) {
node_hash_table_ = new SearchNodeHashTable();
if (node_hash_table_ == NULL) {
return false;
}
}
init_ = true;
@ -144,9 +141,6 @@ SearchNode *SearchColumn::AddNode(LangModEdge *edge, int reco_cost,
// node does not exist
if (new_node == NULL) {
new_node = new SearchNode(cntxt, parent_node, reco_cost, edge, col_idx_);
if (new_node == NULL) {
return NULL;
}
// if the max node count has already been reached, check if the cost of
// the new node exceeds the max cost. This indicates that it will be pruned
@ -161,10 +155,6 @@ SearchNode *SearchColumn::AddNode(LangModEdge *edge, int reco_cost,
// alloc a new buff
SearchNode **new_node_buff =
new SearchNode *[node_cnt_ + kNodeAllocChunk];
if (new_node_buff == NULL) {
delete new_node;
return NULL;
}
// free existing after copying contents
if (node_array_ != NULL) {

View File

@ -147,9 +147,6 @@ char_32 *SearchNode::PathString() {
}
char_32 *char_ptr = new char_32[len + 1];
if (char_ptr == NULL) {
return NULL;
}
int ch_idx = len;

View File

@ -72,9 +72,6 @@ TessLangModEdge::TessLangModEdge(CubeRecoContext *cntxt, const Dawg *dawg,
char *TessLangModEdge::Description() const {
char *char_ptr = new char[256];
if (!char_ptr) {
return NULL;
}
char dawg_str[256];
char edge_str[32];
@ -115,9 +112,8 @@ int TessLangModEdge::CreateChildren(CubeRecoContext *cntxt,
for (int i = 0; i < vec.size(); ++i) {
const NodeChild &child = vec[i];
if (child.unichar_id == INVALID_UNICHAR_ID) continue;
edge_array[edge_cnt] =
edge_array[edge_cnt++] =
new TessLangModEdge(cntxt, dawg, child.edge_ref, child.unichar_id);
if (edge_array[edge_cnt] != NULL) edge_cnt++;
}
return edge_cnt;
}

View File

@ -182,9 +182,6 @@ LangModEdge ** TessLangModel::GetEdges(CharAltList *alt_list,
// preallocate the edge buffer
(*edge_cnt) = dawg_cnt * max_edge_;
edge_array = new LangModEdge *[(*edge_cnt)];
if (edge_array == NULL) {
return NULL;
}
for (int dawg_idx = (*edge_cnt) = 0; dawg_idx < dawg_cnt; dawg_idx++) {
const Dawg *curr_dawg = GetDawg(dawg_idx);
@ -213,9 +210,6 @@ LangModEdge ** TessLangModel::GetEdges(CharAltList *alt_list,
(*edge_cnt) = max_edge_;
// allocate memory for edges
edge_array = new LangModEdge *[(*edge_cnt)];
if (edge_array == NULL) {
return NULL;
}
// get the FanOut edges from the root of each dawg
(*edge_cnt) = FanOut(alt_list,
@ -240,9 +234,6 @@ int TessLangModel::Edges(const char *strng, const Dawg *dawg,
// create an edge object
edge_array[edge_cnt] = new TessLangModEdge(cntxt_, dawg, edge_ref,
class_id);
if (edge_array[edge_cnt] == NULL) {
return 0;
}
reinterpret_cast<TessLangModEdge *>(edge_array[edge_cnt])->
SetEdgeMask(edge_mask);
@ -264,10 +255,6 @@ int TessLangModel::OODEdges(CharAltList *alt_list, EDGE_REF edge_ref,
alt_list->ClassCost(class_id) <= max_ood_shape_cost_)) {
// create an edge object
edge_array[edge_cnt] = new TessLangModEdge(cntxt_, class_id);
if (edge_array[edge_cnt] == NULL) {
return 0;
}
edge_cnt++;
}
}
@ -368,11 +355,9 @@ int TessLangModel::FanOut(CharAltList *alt_list, const Dawg *dawg,
edge_array[edge_cnt] = new TessLangModEdge(cntxt_, dawg,
child_edge->StartEdge(), child_edge->EndEdge(), class_id);
if (edge_array[edge_cnt] != NULL) {
reinterpret_cast<TessLangModEdge *>(edge_array[edge_cnt])->
reinterpret_cast<TessLangModEdge *>(edge_array[edge_cnt])->
SetEdgeMask(edge_mask);
edge_cnt++;
}
edge_cnt++;
}
}
}
@ -486,8 +471,6 @@ void TessLangModel::RemoveInvalidCharacters(string *lm_str) {
int len = CubeUtils::StrLen(lm_str32.c_str());
char_32 *clean_str32 = new char_32[len + 1];
if (!clean_str32)
return;
int clean_len = 0;
for (int i = 0; i < len; ++i) {
int class_id = char_set->ClassID((char_32)lm_str32[i]);

View File

@ -45,11 +45,6 @@ bool WordAltList::Insert(char_32 *word_str, int cost, void *tag) {
word_alt_ = new char_32*[max_alt_];
alt_cost_ = new int[max_alt_];
alt_tag_ = new void *[max_alt_];
if (word_alt_ == NULL || alt_cost_ == NULL || alt_tag_ == NULL) {
return false;
}
memset(alt_tag_, 0, max_alt_ * sizeof(*alt_tag_));
} else {
// check if alt already exists
@ -69,9 +64,6 @@ bool WordAltList::Insert(char_32 *word_str, int cost, void *tag) {
int len = CubeUtils::StrLen(word_str);
word_alt_[alt_cnt_] = new char_32[len + 1];
if (word_alt_[alt_cnt_] == NULL) {
return false;
}
if (len > 0) {
memcpy(word_alt_[alt_cnt_], word_str, len * sizeof(*word_str));

View File

@ -54,9 +54,6 @@ bool WordListLangModel::Init() {
// false for now, until Cube has a way to express its preferred debug level.
dawg_ = new Trie(DAWG_TYPE_WORD, "", NO_PERM,
cntxt_->CharacterSet()->ClassCount(), false);
if (dawg_ == NULL) {
return false;
}
init_ = true;
return true;
}
@ -97,9 +94,6 @@ LangModEdge **WordListLangModel::GetEdges(CharAltList *alt_list,
// allocate memory for edges
LangModEdge **edge_array = new LangModEdge *[kMaxEdge];
if (edge_array == NULL) {
return NULL;
}
// now get all the emerging edges
(*edge_cnt) += TessLangModEdge::CreateChildren(cntxt_, dawg_, edge_ref,

View File

@ -43,11 +43,6 @@ WordSizeModel *WordSizeModel::Create(const string &data_file_path,
CharSet *char_set,
bool contextual) {
WordSizeModel *obj = new WordSizeModel(char_set, contextual);
if (!obj) {
fprintf(stderr, "Cube ERROR (WordSizeModel::Create): unable to allocate "
"new word size model object\n");
return NULL;
}
if (!obj->Init(data_file_path, lang)) {
delete obj;
@ -96,19 +91,9 @@ bool WordSizeModel::Init(const string &data_file_path, const string &lang) {
FontPairSizeInfo fnt_info;
fnt_info.pair_size_info = new PairSizeInfo *[size_class_cnt];
if (!fnt_info.pair_size_info) {
fprintf(stderr, "Cube ERROR (WordSizeModel::Init): error allcoating "
"memory for font pair size info\n");
return false;
}
fnt_info.pair_size_info[0] =
new PairSizeInfo[size_class_cnt * size_class_cnt];
if (!fnt_info.pair_size_info[0]) {
fprintf(stderr, "Cube ERROR (WordSizeModel::Init): error allocating "
"memory for font pair size info\n");
return false;
}
memset(fnt_info.pair_size_info[0], 0, size_class_cnt * size_class_cnt *
sizeof(PairSizeInfo));

View File

@ -76,32 +76,13 @@ WordUnigrams *WordUnigrams::Create(const string &data_file_path,
// allocate memory
WordUnigrams *word_unigrams_obj = new WordUnigrams();
if (word_unigrams_obj == NULL) {
fprintf(stderr, "Cube ERROR (WordUnigrams::Create): could not create "
"word unigrams object.\n");
return NULL;
}
int full_len = str.length();
int word_cnt = str_vec.size() / 2;
word_unigrams_obj->words_ = new char*[word_cnt];
word_unigrams_obj->costs_ = new int[word_cnt];
if (word_unigrams_obj->words_ == NULL ||
word_unigrams_obj->costs_ == NULL) {
fprintf(stderr, "Cube ERROR (WordUnigrams::Create): error allocating "
"word unigram fields.\n");
delete word_unigrams_obj;
return NULL;
}
word_unigrams_obj->words_[0] = new char[full_len];
if (word_unigrams_obj->words_[0] == NULL) {
fprintf(stderr, "Cube ERROR (WordUnigrams::Create): error allocating "
"word unigram fields.\n");
delete word_unigrams_obj;
return NULL;
}
// construct sorted list of words and costs
word_unigrams_obj->word_cnt_ = 0;

View File

@ -276,7 +276,6 @@ bool Trie::add_word_to_dawg(const WERD_CHOICE &word,
NODE_REF Trie::new_dawg_node() {
TRIE_NODE_RECORD *node = new TRIE_NODE_RECORD();
if (node == NULL) return 0; // failed to create new node
nodes_.push_back(node);
return nodes_.length() - 1;
}

View File

@ -157,9 +157,6 @@ bool NeuralNet::CreateFastNet() {
node->fan_in_cnt = neurons_[node_idx].fan_in_cnt();
// allocate memory for fan-in nodes
node->inputs = new WeightedNode[node->fan_in_cnt];
if (node->inputs == NULL) {
return false;
}
for (int fan_in = 0; fan_in < node->fan_in_cnt; fan_in++) {
// identify fan-in neuron
const int id = neurons_[node_idx].fan_in(fan_in)->id();
@ -222,9 +219,6 @@ NeuralNet *NeuralNet::FromFile(const string file_name) {
NeuralNet *NeuralNet::FromInputBuffer(InputFileBuffer *ib) {
// create a new net object
NeuralNet *net_obj = new NeuralNet();
if (net_obj == NULL) {
return NULL;
}
// load the net
if (!net_obj->ReadBinary(ib)) {
delete net_obj;

View File

@ -140,9 +140,6 @@ class NeuralNet {
}
// set the size of the neurons vector
neurons_ = new Neuron[neuron_cnt_];
if (neurons_ == NULL) {
return false;
}
// read & validate inputs
if (input_buff->Read(&read_val, sizeof(read_val)) != sizeof(read_val)) {
return false;

View File

@ -1285,8 +1285,6 @@ float tune_row_pitch2( //find fp cells
return initial_pitch;
}
sum_proj = new STATS[textord_pitch_range * 2 + 1];
if (sum_proj == NULL)
return initial_pitch;
for (pitch_delta = -textord_pitch_range; pitch_delta <= textord_pitch_range;
pitch_delta++)