Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tesseract::CubeObject Class Reference

#include <cube_object.h>

Public Member Functions

 CubeObject (CubeRecoContext *cntxt, CharSamp *char_samp)
 
 CubeObject (CubeRecoContext *cntxt, IMAGE *img, int left, int top, int wid, int hgt)
 
 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 91 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,
IMAGE img,
int  left,
int  top,
int  wid,
int  hgt 
)

Definition at line 32 of file cube_object.cpp.

33  {
34  Init();
35  char_samp_ = CubeUtils::CharSampleFromImg(img, left, top, wid, hgt);
36  own_char_samp_ = true;
37  cntxt_ = cntxt;
38 }
static CharSamp * CharSampleFromImg(IMAGE *img, int left, int top, int wid, int hgt)
Definition: cube_utils.cpp:121
tesseract::CubeObject::CubeObject ( CubeRecoContext cntxt,
Pix *  pix,
int  left,
int  top,
int  wid,
int  hgt 
)

Definition at line 40 of file cube_object.cpp.

41  {
42  Init();
43  char_samp_ = CubeUtils::CharSampleFromPix(pix, left, top, wid, hgt);
44  own_char_samp_ = true;
45  cntxt_ = cntxt;
46 }
static CharSamp * CharSampleFromPix(Pix *pix, int left, int top, int wid, int hgt)
Definition: cube_utils.cpp:138
tesseract::CubeObject::~CubeObject ( )

Definition at line 76 of file cube_object.cpp.

76  {
77  if (char_samp_ != NULL && own_char_samp_ == true) {
78  delete char_samp_;
79  char_samp_ = NULL;
80  }
81 
82  if (srch_obj_ != NULL) {
83  delete srch_obj_;
84  srch_obj_ = NULL;
85  }
86 
87  if (deslanted_srch_obj_ != NULL) {
88  delete deslanted_srch_obj_;
89  deslanted_srch_obj_ = NULL;
90  }
91 
92  if (beam_obj_ != NULL) {
93  delete beam_obj_;
94  beam_obj_ = NULL;
95  }
96 
97  if (deslanted_beam_obj_ != NULL) {
98  delete deslanted_beam_obj_;
99  deslanted_beam_obj_ = NULL;
100  }
101 
102  if (deslanted_char_samp_ != NULL) {
103  delete deslanted_char_samp_;
104  deslanted_char_samp_ = NULL;
105  }
106 
107  Cleanup();
108 }
#define NULL
Definition: host.h:144

Member Function Documentation

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

Definition at line 122 of file cube_object.h.

122  {
123  return (deslanted_ == true ? deslanted_alt_list_ : alt_list_);
124  }
BeamSearch* tesseract::CubeObject::BeamObj ( ) const
inline

Definition at line 117 of file cube_object.h.

117  {
118  return (deslanted_ == true ? deslanted_beam_obj_ : beam_obj_);
119  }
CharSamp* tesseract::CubeObject::CharSample ( ) const
inline

Definition at line 133 of file cube_object.h.

133  {
134  return (deslanted_ == true ? deslanted_char_samp_ : char_samp_);
135  }
bool tesseract::CubeObject::Normalize ( )
protected

Definition at line 256 of file cube_object.cpp.

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

Definition at line 246 of file cube_object.cpp.

246  {
247  if (char_samp_ == NULL) return NULL;
248  CharAltList* alt_list = NULL;
249  CharClassifier *char_classifier = cntxt_->Classifier();
250  ASSERT_HOST(char_classifier != NULL);
251  alt_list = char_classifier->Classify(char_samp_);
252  return alt_list;
253 }
#define NULL
Definition: host.h:144
#define ASSERT_HOST(x)
Definition: errcode.h:84
CharClassifier * Classifier() const
WordAltList * tesseract::CubeObject::RecognizePhrase ( LangModel lang_mod = NULL)

Definition at line 214 of file cube_object.cpp.

214  {
215  return Recognize(lang_mod, false);
216 }
WordAltList * tesseract::CubeObject::RecognizeWord ( LangModel lang_mod = NULL)

Definition at line 209 of file cube_object.cpp.

209  {
210  return Recognize(lang_mod, true);
211 }
void tesseract::CubeObject::SetCharSampOwnership ( bool  own_char_samp)
inline

Definition at line 138 of file cube_object.h.

138  {
139  own_char_samp_ = own_char_samp;
140  }
CubeSearchObject* tesseract::CubeObject::SrchObj ( ) const
inline

Definition at line 127 of file cube_object.h.

127  {
128  return (deslanted_ == true ? deslanted_srch_obj_ : srch_obj_);
129  }
int tesseract::CubeObject::WordCost ( const char *  str)

Definition at line 220 of file cube_object.cpp.

220  {
221  WordListLangModel *lang_mod = new WordListLangModel(cntxt_);
222  if (lang_mod == NULL) {
223  return WORST_COST;
224  }
225 
226  if (lang_mod->AddString(str) == false) {
227  delete lang_mod;
228  return WORST_COST;
229  }
230 
231  // run a beam search against the single string wordlist model
232  WordAltList *alt_list = RecognizeWord(lang_mod);
233  delete lang_mod;
234 
235  int cost = WORST_COST;
236  if (alt_list != NULL) {
237  if (alt_list->AltCount() > 0) {
238  cost = alt_list->AltCost(0);
239  }
240  }
241 
242  return cost;
243 }
#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: