28 char_samp_ = char_samp;
33 int left,
int top,
int wid,
int hgt) {
36 own_char_samp_ =
true;
41 void CubeObject::Init() {
43 own_char_samp_ =
false;
46 deslanted_alt_list_ = NULL;
47 deslanted_srch_obj_ = NULL;
49 deslanted_char_samp_ = NULL;
51 deslanted_beam_obj_ = NULL;
56 void CubeObject::Cleanup() {
60 delete deslanted_alt_list_;
61 deslanted_alt_list_ = NULL;
65 if (own_char_samp_ ==
true) {
73 delete deslanted_srch_obj_;
74 deslanted_srch_obj_ = NULL;
79 delete deslanted_beam_obj_;
80 deslanted_beam_obj_ = NULL;
82 delete deslanted_char_samp_;
83 deslanted_char_samp_ = NULL;
95 if (char_samp_ == NULL) {
103 if (lang_mod == NULL) {
116 if (beam_obj_ == NULL) {
117 beam_obj_ =
new BeamSearch(cntxt_, word_mode);
121 if (srch_obj_ == NULL) {
122 srch_obj_ =
new CubeSearchObject(cntxt_, char_samp_);
126 alt_list_ = beam_obj_->
Search(srch_obj_, lang_mod);
130 (alt_list_ == NULL || alt_list_->
AltCount() < 1 ||
133 if (deslanted_beam_obj_ == NULL) {
134 deslanted_beam_obj_ =
new BeamSearch(cntxt_);
137 if (deslanted_srch_obj_ == NULL) {
138 deslanted_char_samp_ = char_samp_->
Clone();
139 if (deslanted_char_samp_ == NULL) {
140 fprintf(stderr,
"Cube ERROR (CubeObject::Recognize): could not " 141 "construct deslanted CharSamp\n");
145 if (deslanted_char_samp_->
Deslant() ==
false) {
149 deslanted_srch_obj_ =
new CubeSearchObject(cntxt_, deslanted_char_samp_);
153 deslanted_alt_list_ = deslanted_beam_obj_->
Search(deslanted_srch_obj_,
156 if (deslanted_alt_list_ != NULL && deslanted_alt_list_->
AltCount() > 0) {
157 if (alt_list_ == NULL || alt_list_->
AltCount() < 1 ||
160 return deslanted_alt_list_;
172 return Recognize(lang_mod,
true);
179 return Recognize(lang_mod,
false);
199 if (alt_list != NULL) {
210 if (char_samp_ == NULL)
return NULL;
214 alt_list = char_classifier->
Classify(char_samp_);
225 if (seg_cnt < kMinNormalizationSegmentCnt) {
230 double ar_mean = 0.0;
231 for (
int seg_idx = 0; seg_idx <= seg_cnt; seg_idx++) {
233 if (seg_samp != NULL && seg_samp->
Width() > 0) {
234 ar_mean += (1.0 * seg_samp->
Height() / seg_samp->
Width());
237 ar_mean /= (seg_cnt + 1);
239 if (ar_mean > kMinNormalizationAspectRatio) {
242 2.0 * char_samp_->
Height() / ar_mean,
244 if (new_samp != NULL) {
246 if (own_char_samp_) {
250 char_samp_ = new_samp;
251 own_char_samp_ =
true;
WordAltList * Search(SearchObject *srch_obj, LangModel *lang_mod=NULL)
unsigned short Height() const
virtual CharAltList * Classify(CharSamp *char_samp)=0
CharSamp * Scale(int wid, int hgt, bool isotropic=true)
WordAltList * RecognizePhrase(LangModel *lang_mod=NULL)
int WordCost(const char *str)
unsigned short Width() const
CharClassifier * Classifier() const
LangModel * LangMod() const
static int Prob2Cost(double prob_val)
CharAltList * RecognizeChar()
CubeObject(CubeRecoContext *cntxt, CharSamp *char_samp)
WordAltList * RecognizeWord(LangModel *lang_mod=NULL)
bool AddString(const char *char_ptr)
CharSamp * CharSample(int start_pt, int end_pt)
static CharSamp * CharSampleFromPix(Pix *pix, int left, int top, int wid, int hgt)
int AltCost(int alt_idx) const
bool SizeNormalization() const