tesseract  3.04.00
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

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 }
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:92
tesseract::CubeObject::~CubeObject ( )

Definition at line 68 of file cube_object.cpp.

68  {
69  if (char_samp_ != NULL && own_char_samp_ == true) {
70  delete char_samp_;
71  char_samp_ = NULL;
72  }
73 
74  if (srch_obj_ != NULL) {
75  delete srch_obj_;
76  srch_obj_ = NULL;
77  }
78 
79  if (deslanted_srch_obj_ != NULL) {
80  delete deslanted_srch_obj_;
81  deslanted_srch_obj_ = NULL;
82  }
83 
84  if (beam_obj_ != NULL) {
85  delete beam_obj_;
86  beam_obj_ = NULL;
87  }
88 
89  if (deslanted_beam_obj_ != NULL) {
90  delete deslanted_beam_obj_;
91  deslanted_beam_obj_ = NULL;
92  }
93 
94  if (deslanted_char_samp_ != NULL) {
95  delete deslanted_char_samp_;
96  deslanted_char_samp_ = NULL;
97  }
98 
99  Cleanup();
100 }
#define NULL
Definition: host.h:144

Member Function Documentation

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  }
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  }
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  }
bool tesseract::CubeObject::Normalize ( )
protected

Definition at line 248 of file cube_object.cpp.

248  {
249  // create a cube search object
250  CubeSearchObject *srch_obj = new CubeSearchObject(cntxt_, char_samp_);
251  if (srch_obj == NULL) {
252  return false;
253  }
254  // Perform over-segmentation
255  int seg_cnt = srch_obj->SegPtCnt();
256  // Only perform normalization if segment count is large enough
257  if (seg_cnt < kMinNormalizationSegmentCnt) {
258  delete srch_obj;
259  return true;
260  }
261  // compute the mean AR of the segments
262  double ar_mean = 0.0;
263  for (int seg_idx = 0; seg_idx <= seg_cnt; seg_idx++) {
264  CharSamp *seg_samp = srch_obj->CharSample(seg_idx - 1, seg_idx);
265  if (seg_samp != NULL && seg_samp->Width() > 0) {
266  ar_mean += (1.0 * seg_samp->Height() / seg_samp->Width());
267  }
268  }
269  ar_mean /= (seg_cnt + 1);
270  // perform normalization if segment AR is too high
271  if (ar_mean > kMinNormalizationAspectRatio) {
272  // scale down the image in the y-direction to attain AR
273  CharSamp *new_samp = char_samp_->Scale(char_samp_->Width(),
274  2.0 * char_samp_->Height() / ar_mean,
275  false);
276  if (new_samp != NULL) {
277  // free existing char samp if owned
278  if (own_char_samp_) {
279  delete char_samp_;
280  }
281  // update with new scaled charsamp and set ownership flag
282  char_samp_ = new_samp;
283  own_char_samp_ = true;
284  }
285  }
286  delete srch_obj;
287  return true;
288 }
unsigned short Height() const
Definition: bmp_8.h:50
#define NULL
Definition: host.h:144
unsigned short Width() const
Definition: bmp_8.h:48
CharSamp * Scale(int wid, int hgt, bool isotropic=true)
Definition: char_samp.cpp:251
CharAltList * tesseract::CubeObject::RecognizeChar ( )

Definition at line 238 of file cube_object.cpp.

238  {
239  if (char_samp_ == NULL) return NULL;
240  CharAltList* alt_list = NULL;
241  CharClassifier *char_classifier = cntxt_->Classifier();
242  ASSERT_HOST(char_classifier != NULL);
243  alt_list = char_classifier->Classify(char_samp_);
244  return alt_list;
245 }
#define NULL
Definition: host.h:144
CharClassifier * Classifier() const
#define ASSERT_HOST(x)
Definition: errcode.h:84
WordAltList * tesseract::CubeObject::RecognizePhrase ( LangModel lang_mod = NULL)

Definition at line 206 of file cube_object.cpp.

206  {
207  return Recognize(lang_mod, false);
208 }
WordAltList * tesseract::CubeObject::RecognizeWord ( LangModel lang_mod = NULL)

Definition at line 201 of file cube_object.cpp.

201  {
202  return Recognize(lang_mod, true);
203 }
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  }
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  }
int tesseract::CubeObject::WordCost ( const char *  str)

Definition at line 212 of file cube_object.cpp.

212  {
213  WordListLangModel *lang_mod = new WordListLangModel(cntxt_);
214  if (lang_mod == NULL) {
215  return WORST_COST;
216  }
217 
218  if (lang_mod->AddString(str) == false) {
219  delete lang_mod;
220  return WORST_COST;
221  }
222 
223  // run a beam search against the single string wordlist model
224  WordAltList *alt_list = RecognizeWord(lang_mod);
225  delete lang_mod;
226 
227  int cost = WORST_COST;
228  if (alt_list != NULL) {
229  if (alt_list->AltCount() > 0) {
230  cost = alt_list->AltCost(0);
231  }
232  }
233 
234  return cost;
235 }
#define WORST_COST
Definition: cube_const.h:30
#define NULL
Definition: host.h:144
WordAltList * RecognizeWord(LangModel *lang_mod=NULL)

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