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() {
57 if (alt_list_ !=
NULL) {
62 if (deslanted_alt_list_ !=
NULL) {
63 delete deslanted_alt_list_;
64 deslanted_alt_list_ =
NULL;
69 if (char_samp_ !=
NULL && own_char_samp_ ==
true) {
74 if (srch_obj_ !=
NULL) {
79 if (deslanted_srch_obj_ !=
NULL) {
80 delete deslanted_srch_obj_;
81 deslanted_srch_obj_ =
NULL;
84 if (beam_obj_ !=
NULL) {
89 if (deslanted_beam_obj_ !=
NULL) {
90 delete deslanted_beam_obj_;
91 deslanted_beam_obj_ =
NULL;
94 if (deslanted_char_samp_ !=
NULL) {
95 delete deslanted_char_samp_;
96 deslanted_char_samp_ =
NULL;
109 if (char_samp_ ==
NULL) {
117 if (lang_mod ==
NULL) {
130 if (beam_obj_ ==
NULL) {
131 beam_obj_ =
new BeamSearch(cntxt_, word_mode);
132 if (beam_obj_ ==
NULL) {
133 fprintf(stderr,
"Cube ERROR (CubeObject::Recognize): could not construct "
140 if (srch_obj_ ==
NULL) {
141 srch_obj_ =
new CubeSearchObject(cntxt_, char_samp_);
142 if (srch_obj_ ==
NULL) {
143 fprintf(stderr,
"Cube ERROR (CubeObject::Recognize): could not construct "
144 "CubeSearchObject\n");
150 alt_list_ = beam_obj_->
Search(srch_obj_, lang_mod);
157 if (deslanted_beam_obj_ ==
NULL) {
158 deslanted_beam_obj_ =
new BeamSearch(cntxt_);
159 if (deslanted_beam_obj_ ==
NULL) {
160 fprintf(stderr,
"Cube ERROR (CubeObject::Recognize): could not "
161 "construct deslanted BeamSearch\n");
166 if (deslanted_srch_obj_ ==
NULL) {
167 deslanted_char_samp_ = char_samp_->
Clone();
168 if (deslanted_char_samp_ ==
NULL) {
169 fprintf(stderr,
"Cube ERROR (CubeObject::Recognize): could not "
170 "construct deslanted CharSamp\n");
174 if (deslanted_char_samp_->
Deslant() ==
false) {
178 deslanted_srch_obj_ =
new CubeSearchObject(cntxt_, deslanted_char_samp_);
179 if (deslanted_srch_obj_ ==
NULL) {
180 fprintf(stderr,
"Cube ERROR (CubeObject::Recognize): could not "
181 "construct deslanted CubeSearchObject\n");
187 deslanted_alt_list_ = deslanted_beam_obj_->
Search(deslanted_srch_obj_,
190 if (deslanted_alt_list_ !=
NULL && deslanted_alt_list_->
AltCount() > 0) {
194 return deslanted_alt_list_;
206 return Recognize(lang_mod,
true);
213 return Recognize(lang_mod,
false);
222 if (lang_mod ==
NULL) {
236 if (alt_list !=
NULL) {
247 if (char_samp_ ==
NULL)
return NULL;
251 alt_list = char_classifier->
Classify(char_samp_);
259 if (srch_obj ==
NULL) {
265 if (seg_cnt < kMinNormalizationSegmentCnt) {
270 double ar_mean = 0.0;
271 for (
int seg_idx = 0; seg_idx <= seg_cnt; seg_idx++) {
273 if (seg_samp !=
NULL && seg_samp->
Width() > 0) {
274 ar_mean += (1.0 * seg_samp->
Height() / seg_samp->
Width());
277 ar_mean /= (seg_cnt + 1);
279 if (ar_mean > kMinNormalizationAspectRatio) {
282 2.0 * char_samp_->
Height() / ar_mean,
284 if (new_samp !=
NULL) {
286 if (own_char_samp_) {
290 char_samp_ = new_samp;
291 own_char_samp_ =
true;
int WordCost(const char *str)
LangModel * LangMod() const
static int Prob2Cost(double prob_val)
int AltCost(int alt_idx) const
bool SizeNormalization() const
unsigned short Width() const
WordAltList * RecognizeWord(LangModel *lang_mod=NULL)
CubeObject(CubeRecoContext *cntxt, CharSamp *char_samp)
CharSamp * CharSample(int start_pt, int end_pt)
CharSamp * Scale(int wid, int hgt, bool isotropic=true)
virtual CharAltList * Classify(CharSamp *char_samp)=0
CharClassifier * Classifier() const
CharAltList * RecognizeChar()
WordAltList * RecognizePhrase(LangModel *lang_mod=NULL)
unsigned short Height() const
bool AddString(const char *char_ptr)
WordAltList * Search(SearchObject *srch_obj, LangModel *lang_mod=NULL)
static CharSamp * CharSampleFromPix(Pix *pix, int left, int top, int wid, int hgt)