tesseract  3.05.02
tesseract::CubeObject Class Reference

#include <cube_object.h>

Public Member Functions

 CubeObject (CubeRecoContext *cntxt, CharSamp *char_samp)
 
 CubeObject (CubeRecoContext *cntxt, Pix *pix, int left, int top, int wid, int hgt)
 
 ~CubeObject ()
 
WordAltListRecognizeWord (LangModel *lang_mod=NULL)
 
WordAltListRecognizePhrase (LangModel *lang_mod=NULL)
 
int WordCost (const char *str)
 
CharAltListRecognizeChar ()
 
BeamSearchBeamObj () const
 
WordAltListAlternateList () const
 
CubeSearchObjectSrchObj () const
 
CharSampCharSample () const
 
void SetCharSampOwnership (bool own_char_samp)
 

Protected Member Functions

bool Normalize ()
 

Detailed Description

Definition at line 90 of file cube_object.h.

Constructor & Destructor Documentation

◆ CubeObject() [1/2]

tesseract::CubeObject::CubeObject ( CubeRecoContext cntxt,
CharSamp char_samp 
)

Definition at line 26 of file cube_object.cpp.

26  {
27  Init();
28  char_samp_ = char_samp;
29  cntxt_ = cntxt;
30 }

◆ CubeObject() [2/2]

tesseract::CubeObject::CubeObject ( CubeRecoContext cntxt,
Pix *  pix,
int  left,
int  top,
int  wid,
int  hgt 
)

Definition at line 32 of file cube_object.cpp.

33  {
34  Init();
35  char_samp_ = CubeUtils::CharSampleFromPix(pix, left, top, wid, hgt);
36  own_char_samp_ = true;
37  cntxt_ = cntxt;
38 }
static CharSamp * CharSampleFromPix(Pix *pix, int left, int top, int wid, int hgt)
Definition: cube_utils.cpp:101

◆ ~CubeObject()

tesseract::CubeObject::~CubeObject ( )

Definition at line 64 of file cube_object.cpp.

64  {
65  if (own_char_samp_ == true) {
66  delete char_samp_;
67  char_samp_ = NULL;
68  }
69 
70  delete srch_obj_;
71  srch_obj_ = NULL;
72 
73  delete deslanted_srch_obj_;
74  deslanted_srch_obj_ = NULL;
75 
76  delete beam_obj_;
77  beam_obj_ = NULL;
78 
79  delete deslanted_beam_obj_;
80  deslanted_beam_obj_ = NULL;
81 
82  delete deslanted_char_samp_;
83  deslanted_char_samp_ = NULL;
84 
85  Cleanup();
86 }

Member Function Documentation

◆ AlternateList()

WordAltList* tesseract::CubeObject::AlternateList ( ) const
inline

Definition at line 119 of file cube_object.h.

119  {
120  return (deslanted_ == true ? deslanted_alt_list_ : alt_list_);
121  }

◆ BeamObj()

BeamSearch* tesseract::CubeObject::BeamObj ( ) const
inline

Definition at line 114 of file cube_object.h.

114  {
115  return (deslanted_ == true ? deslanted_beam_obj_ : beam_obj_);
116  }

◆ CharSample()

CharSamp* tesseract::CubeObject::CharSample ( ) const
inline

Definition at line 130 of file cube_object.h.

130  {
131  return (deslanted_ == true ? deslanted_char_samp_ : char_samp_);
132  }

◆ Normalize()

bool tesseract::CubeObject::Normalize ( )
protected

Definition at line 219 of file cube_object.cpp.

219  {
220  // create a cube search object
221  CubeSearchObject *srch_obj = new CubeSearchObject(cntxt_, char_samp_);
222  // Perform over-segmentation
223  int seg_cnt = srch_obj->SegPtCnt();
224  // Only perform normalization if segment count is large enough
225  if (seg_cnt < kMinNormalizationSegmentCnt) {
226  delete srch_obj;
227  return true;
228  }
229  // compute the mean AR of the segments
230  double ar_mean = 0.0;
231  for (int seg_idx = 0; seg_idx <= seg_cnt; seg_idx++) {
232  CharSamp *seg_samp = srch_obj->CharSample(seg_idx - 1, seg_idx);
233  if (seg_samp != NULL && seg_samp->Width() > 0) {
234  ar_mean += (1.0 * seg_samp->Height() / seg_samp->Width());
235  }
236  }
237  ar_mean /= (seg_cnt + 1);
238  // perform normalization if segment AR is too high
239  if (ar_mean > kMinNormalizationAspectRatio) {
240  // scale down the image in the y-direction to attain AR
241  CharSamp *new_samp = char_samp_->Scale(char_samp_->Width(),
242  2.0 * char_samp_->Height() / ar_mean,
243  false);
244  if (new_samp != NULL) {
245  // free existing char samp if owned
246  if (own_char_samp_) {
247  delete char_samp_;
248  }
249  // update with new scaled charsamp and set ownership flag
250  char_samp_ = new_samp;
251  own_char_samp_ = true;
252  }
253  }
254  delete srch_obj;
255  return true;
256 }
unsigned short Height() const
Definition: bmp_8.h:50
CharSamp * Scale(int wid, int hgt, bool isotropic=true)
Definition: char_samp.cpp:247
unsigned short Width() const
Definition: bmp_8.h:48

◆ RecognizeChar()

CharAltList * tesseract::CubeObject::RecognizeChar ( )

Definition at line 209 of file cube_object.cpp.

209  {
210  if (char_samp_ == NULL) return NULL;
211  CharAltList* alt_list = NULL;
212  CharClassifier *char_classifier = cntxt_->Classifier();
213  ASSERT_HOST(char_classifier != NULL);
214  alt_list = char_classifier->Classify(char_samp_);
215  return alt_list;
216 }
CharClassifier * Classifier() const
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ RecognizePhrase()

WordAltList * tesseract::CubeObject::RecognizePhrase ( LangModel lang_mod = NULL)

Recognize the member char sample as a phrase

Definition at line 178 of file cube_object.cpp.

178  {
179  return Recognize(lang_mod, false);
180 }

◆ RecognizeWord()

WordAltList * tesseract::CubeObject::RecognizeWord ( LangModel lang_mod = NULL)

Recognize the member char sample as a word

Definition at line 171 of file cube_object.cpp.

171  {
172  return Recognize(lang_mod, true);
173 }

◆ SetCharSampOwnership()

void tesseract::CubeObject::SetCharSampOwnership ( bool  own_char_samp)
inline

Definition at line 135 of file cube_object.h.

135  {
136  own_char_samp_ = own_char_samp;
137  }

◆ SrchObj()

CubeSearchObject* tesseract::CubeObject::SrchObj ( ) const
inline

Definition at line 124 of file cube_object.h.

124  {
125  return (deslanted_ == true ? deslanted_srch_obj_ : srch_obj_);
126  }

◆ WordCost()

int tesseract::CubeObject::WordCost ( const char *  str)

Computes the cost of a specific string. This is done by performing recognition of a language model that allows only the specified word

Definition at line 186 of file cube_object.cpp.

186  {
187  WordListLangModel *lang_mod = new WordListLangModel(cntxt_);
188 
189  if (lang_mod->AddString(str) == false) {
190  delete lang_mod;
191  return WORST_COST;
192  }
193 
194  // run a beam search against the single string wordlist model
195  WordAltList *alt_list = RecognizeWord(lang_mod);
196  delete lang_mod;
197 
198  int cost = WORST_COST;
199  if (alt_list != NULL) {
200  if (alt_list->AltCount() > 0) {
201  cost = alt_list->AltCost(0);
202  }
203  }
204 
205  return cost;
206 }
#define WORST_COST
Definition: cube_const.h:30
WordAltList * RecognizeWord(LangModel *lang_mod=NULL)

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