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;
107 if (char_samp_ ==
NULL) {
115 if (lang_mod ==
NULL) {
128 if (beam_obj_ ==
NULL) {
129 beam_obj_ =
new BeamSearch(cntxt_, word_mode);
130 if (beam_obj_ ==
NULL) {
131 fprintf(stderr,
"Cube ERROR (CubeObject::Recognize): could not construct " 138 if (srch_obj_ ==
NULL) {
140 if (srch_obj_ ==
NULL) {
141 fprintf(stderr,
"Cube ERROR (CubeObject::Recognize): could not construct " 142 "CubeSearchObject\n");
148 alt_list_ = beam_obj_->
Search(srch_obj_, lang_mod);
155 if (deslanted_beam_obj_ ==
NULL) {
157 if (deslanted_beam_obj_ ==
NULL) {
158 fprintf(stderr,
"Cube ERROR (CubeObject::Recognize): could not " 159 "construct deslanted BeamSearch\n");
164 if (deslanted_srch_obj_ ==
NULL) {
165 deslanted_char_samp_ = char_samp_->
Clone();
166 if (deslanted_char_samp_ ==
NULL) {
167 fprintf(stderr,
"Cube ERROR (CubeObject::Recognize): could not " 168 "construct deslanted CharSamp\n");
172 if (deslanted_char_samp_->
Deslant() ==
false) {
177 if (deslanted_srch_obj_ ==
NULL) {
178 fprintf(stderr,
"Cube ERROR (CubeObject::Recognize): could not " 179 "construct deslanted CubeSearchObject\n");
185 deslanted_alt_list_ = deslanted_beam_obj_->
Search(deslanted_srch_obj_,
188 if (deslanted_alt_list_ !=
NULL && deslanted_alt_list_->
AltCount() > 0) {
192 return deslanted_alt_list_;
202 return Recognize(lang_mod,
true);
207 return Recognize(lang_mod,
false);
214 if (lang_mod ==
NULL) {
228 if (alt_list !=
NULL) {
239 if (char_samp_ ==
NULL)
return NULL;
243 alt_list = char_classifier->
Classify(char_samp_);
251 if (srch_obj ==
NULL) {
257 if (seg_cnt < kMinNormalizationSegmentCnt) {
262 double ar_mean = 0.0;
263 for (
int seg_idx = 0; seg_idx <= seg_cnt; seg_idx++) {
265 if (seg_samp !=
NULL && seg_samp->
Width() > 0) {
266 ar_mean += (1.0 * seg_samp->
Height() / seg_samp->
Width());
269 ar_mean /= (seg_cnt + 1);
271 if (ar_mean > kMinNormalizationAspectRatio) {
274 2.0 * char_samp_->
Height() / ar_mean,
276 if (new_samp !=
NULL) {
278 if (own_char_samp_) {
282 char_samp_ = new_samp;
283 own_char_samp_ =
true;
unsigned short Height() const
CharSamp * CharSample(int start_pt, int end_pt)
int WordCost(const char *str)
bool SizeNormalization() const
unsigned short Width() const
CharClassifier * Classifier() const
static CharSamp * CharSampleFromPix(Pix *pix, int left, int top, int wid, int hgt)
CubeObject(CubeRecoContext *cntxt, CharSamp *char_samp)
WordAltList * Search(SearchObject *srch_obj, LangModel *lang_mod=NULL)
LangModel * LangMod() const
WordAltList * RecognizePhrase(LangModel *lang_mod=NULL)
WordAltList * RecognizeWord(LangModel *lang_mod=NULL)
CharAltList * RecognizeChar()
int AltCost(int alt_idx) const
virtual CharAltList * Classify(CharSamp *char_samp)=0
static int Prob2Cost(double prob_val)
bool AddString(const char *char_ptr)
CharSamp * Scale(int wid, int hgt, bool isotropic=true)