Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tesseract::CubeTuningParams Class Reference

#include <cube_tuning_params.h>

Inheritance diagram for tesseract::CubeTuningParams:
tesseract::TuningParams

List of all members.

Public Member Functions

 CubeTuningParams ()
 ~CubeTuningParams ()
double OODWgt ()
double NumWgt ()
void SetOODWgt (double wgt)
void SetNumWgt (double wgt)
bool Save (string file_name)
bool Load (string file_name)
- Public Member Functions inherited from tesseract::TuningParams
 TuningParams ()
virtual ~TuningParams ()
double RecoWgt () const
double SizeWgt () const
double CharBigramWgt () const
double WordUnigramWgt () const
int MaxSegPerChar () const
int BeamWidth () const
int TypeClassifier () const
int TypeFeature () const
int ConvGridSize () const
int HistWindWid () const
int MinConCompSize () const
double MaxWordAspectRatio () const
double MinSpaceHeightRatio () const
double MaxSpaceHeightRatio () const
double CombinerRunThresh () const
double CombinerClassifierThresh () const
void SetRecoWgt (double wgt)
void SetSizeWgt (double wgt)
void SetCharBigramWgt (double wgt)
void SetWordUnigramWgt (double wgt)
void SetMaxSegPerChar (int max_seg_per_char)
void SetBeamWidth (int beam_width)
void SetTypeClassifier (type_classifer tp_classifier)
void SetTypeFeature (type_feature tp_feat)
void SetHistWindWid (int hist_wind_wid)

Static Public Member Functions

static CubeTuningParamsCreate (const string &data_file, const string &lang)

Additional Inherited Members

- Public Types inherited from tesseract::TuningParams
enum  type_classifer { NN, HYBRID_NN }
enum  type_feature { BMP, CHEBYSHEV, HYBRID }
- Protected Attributes inherited from tesseract::TuningParams
double reco_wgt_
double size_wgt_
double char_bigrams_wgt_
double word_unigrams_wgt_
int max_seg_per_char_
int beam_width_
type_classifer tp_classifier_
type_feature tp_feat_
int conv_grid_size_
int hist_wind_wid_
int min_con_comp_size_
double max_word_aspect_ratio_
double min_space_height_ratio_
double max_space_height_ratio_
double combiner_run_thresh_
double combiner_classifier_thresh_

Detailed Description

Definition at line 31 of file cube_tuning_params.h.


Constructor & Destructor Documentation

tesseract::CubeTuningParams::CubeTuningParams ( )
tesseract::CubeTuningParams::~CubeTuningParams ( )

Definition at line 49 of file cube_tuning_params.cpp.

{
}

Member Function Documentation

CubeTuningParams * tesseract::CubeTuningParams::Create ( const string &  data_file,
const string &  lang 
)
static

Definition at line 54 of file cube_tuning_params.cpp.

{
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;
tuning_params_file += ".cube.params";
if (!obj->Load(tuning_params_file)) {
fprintf(stderr, "Cube ERROR (CubeTuningParams::Create): unable to "
"load tuning parameters from %s\n", tuning_params_file.c_str());
delete obj;
obj = NULL;
}
return obj;
}
bool tesseract::CubeTuningParams::Load ( string  file_name)
virtual

Implements tesseract::TuningParams.

Definition at line 78 of file cube_tuning_params.cpp.

{
// load the string into memory
string param_str;
if (CubeUtils::ReadFileToString(tuning_params_file, &param_str) == false) {
fprintf(stderr, "Cube ERROR (CubeTuningParams::Load): unable to read "
"file %s\n", tuning_params_file.c_str());
return false;
}
// split into lines
vector<string> str_vec;
CubeUtils::SplitStringUsing(param_str, "\r\n", &str_vec);
if (str_vec.size() < 8) {
fprintf(stderr, "Cube ERROR (CubeTuningParams::Load): number of rows "
"in parameter file is too low\n");
return false;
}
// for all entries
for (int entry = 0; entry < str_vec.size(); entry++) {
// tokenize
vector<string> str_tok;
// should be only two tokens
CubeUtils::SplitStringUsing(str_vec[entry], "=", &str_tok);
if (str_tok.size() != 2) {
fprintf(stderr, "Cube ERROR (CubeTuningParams::Load): invalid format in "
"line: %s.\n", str_vec[entry].c_str());
return false;
}
double val = 0;
char peekchar = (str_tok[1].c_str())[0];
if ((peekchar >= '0' && peekchar <= '9') ||
peekchar == '-' || peekchar == '+' ||
peekchar == '.') {
// read the value
if (sscanf(str_tok[1].c_str(), "%lf", &val) != 1) {
fprintf(stderr, "Cube ERROR (CubeTuningParams::Load): invalid format "
"in line: %s.\n", str_vec[entry].c_str());
return false;
}
}
// token type
if (str_tok[0] == "RecoWgt") {
reco_wgt_ = val;
} else if (str_tok[0] == "SizeWgt") {
size_wgt_ = val;
} else if (str_tok[0] == "CharBigramsWgt") {
} else if (str_tok[0] == "WordUnigramsWgt") {
} else if (str_tok[0] == "MaxSegPerChar") {
max_seg_per_char_ = static_cast<int>(val);
} else if (str_tok[0] == "BeamWidth") {
beam_width_ = static_cast<int>(val);
} else if (str_tok[0] == "Classifier") {
if (str_tok[1] == "NN") {
} else if (str_tok[1] == "HYBRID_NN") {
} else {
fprintf(stderr, "Cube ERROR (CubeTuningParams::Load): invalid "
"classifier type in line: %s.\n", str_vec[entry].c_str());
return false;
}
} else if (str_tok[0] == "FeatureType") {
if (str_tok[1] == "BMP") {
} else if (str_tok[1] == "CHEBYSHEV") {
} else if (str_tok[1] == "HYBRID") {
} else {
fprintf(stderr, "Cube ERROR (CubeTuningParams::Load): invalid feature "
"type in line: %s.\n", str_vec[entry].c_str());
return false;
}
} else if (str_tok[0] == "ConvGridSize") {
conv_grid_size_ = static_cast<int>(val);
} else if (str_tok[0] == "HistWindWid") {
} else if (str_tok[0] == "MinConCompSize") {
} else if (str_tok[0] == "MaxWordAspectRatio") {
} else if (str_tok[0] == "MinSpaceHeightRatio") {
} else if (str_tok[0] == "MaxSpaceHeightRatio") {
} else if (str_tok[0] == "CombinerRunThresh") {
} else if (str_tok[0] == "CombinerClassifierThresh") {
} else if (str_tok[0] == "OODWgt") {
ood_wgt_ = val;
} else if (str_tok[0] == "NumWgt") {
num_wgt_ = val;
} else {
fprintf(stderr, "Cube ERROR (CubeTuningParams::Load): unknown parameter "
"in line: %s.\n", str_vec[entry].c_str());
return false;
}
}
return true;
}
double tesseract::CubeTuningParams::NumWgt ( )
inline

Definition at line 38 of file cube_tuning_params.h.

{ return num_wgt_; }
double tesseract::CubeTuningParams::OODWgt ( )
inline

Definition at line 37 of file cube_tuning_params.h.

{ return ood_wgt_; }
bool tesseract::CubeTuningParams::Save ( string  file_name)
virtual

Implements tesseract::TuningParams.

Definition at line 189 of file cube_tuning_params.cpp.

{
FILE *params_file = fopen(file_name.c_str(), "wb");
if (params_file == NULL) {
fprintf(stderr, "Cube ERROR (CubeTuningParams::Save): error opening file "
"%s for write.\n", file_name.c_str());
return false;
}
fprintf(params_file, "RecoWgt=%.4f\n", reco_wgt_);
fprintf(params_file, "SizeWgt=%.4f\n", size_wgt_);
fprintf(params_file, "CharBigramsWgt=%.4f\n", char_bigrams_wgt_);
fprintf(params_file, "WordUnigramsWgt=%.4f\n", word_unigrams_wgt_);
fprintf(params_file, "MaxSegPerChar=%d\n", max_seg_per_char_);
fprintf(params_file, "BeamWidth=%d\n", beam_width_);
fprintf(params_file, "ConvGridSize=%d\n", conv_grid_size_);
fprintf(params_file, "HistWindWid=%d\n", hist_wind_wid_);
fprintf(params_file, "MinConCompSize=%d\n", min_con_comp_size_);
fprintf(params_file, "MaxWordAspectRatio=%.4f\n", max_word_aspect_ratio_);
fprintf(params_file, "MinSpaceHeightRatio=%.4f\n", min_space_height_ratio_);
fprintf(params_file, "MaxSpaceHeightRatio=%.4f\n", max_space_height_ratio_);
fprintf(params_file, "CombinerRunThresh=%.4f\n", combiner_run_thresh_);
fprintf(params_file, "CombinerClassifierThresh=%.4f\n",
fprintf(params_file, "OODWgt=%.4f\n", ood_wgt_);
fprintf(params_file, "NumWgt=%.4f\n", num_wgt_);
fclose(params_file);
return true;
}
void tesseract::CubeTuningParams::SetNumWgt ( double  wgt)
inline

Definition at line 41 of file cube_tuning_params.h.

{ num_wgt_ = wgt; }
void tesseract::CubeTuningParams::SetOODWgt ( double  wgt)
inline

Definition at line 40 of file cube_tuning_params.h.

{ ood_wgt_ = wgt; }

The documentation for this class was generated from the following files: