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

#include <normalis.h>

Public Member Functions

 DENORM ()
 
 DENORM (float x, float scaling, ROW *src)
 
 DENORM (float x, float scaling, double line_m, double line_c, inT16 seg_count, DENORM_SEG *seg_pts, BOOL8 using_row, ROW *src)
 
 DENORM (const DENORM &)
 
DENORMoperator= (const DENORM &)
 
 ~DENORM ()
 
void SetupBLNormalize (const BLOCK *block, const ROW *row, float x_height, const TBOX &word_box, int num_segs, const DENORM_SEG *segs)
 
void SetupNormalization (const BLOCK *block, const ROW *row, const FCOORD *rotation, const DENORM *predecessor, const DENORM_SEG *segs, int num_segs, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift)
 
void LocalNormTransform (const TPOINT &pt, TPOINT *transformed) const
 
void LocalNormTransform (const FCOORD &pt, FCOORD *transformed) const
 
void NormTransform (const TPOINT &pt, TPOINT *transformed) const
 
void NormTransform (const FCOORD &pt, FCOORD *transformed) const
 
void LocalDenormTransform (const TPOINT &pt, TPOINT *original) const
 
void LocalDenormTransform (const FCOORD &pt, FCOORD *original) const
 
void DenormTransform (const TPOINT &pt, TPOINT *original) const
 
void DenormTransform (const FCOORD &pt, FCOORD *original) const
 
void LocalNormBlob (TBLOB *blob) const
 
bool XHeightRange (int unichar_id, const UNICHARSET &unicharset, const TBOX &bbox, inT16 *min_xht, inT16 *max_xht) const
 
Pix * pix () const
 
void set_pix (Pix *pix)
 
bool inverse () const
 
void set_inverse (bool value)
 
const DENORMRootDenorm () const
 
const DENORMpredecessor () const
 
float x_scale () const
 
float y_scale () const
 
const ROWrow () const
 
void set_row (ROW *row)
 
const BLOCKblock () const
 
void set_block (const BLOCK *block)
 

Detailed Description

Definition at line 59 of file normalis.h.

Constructor & Destructor Documentation

DENORM::DENORM ( )

Definition at line 33 of file normalis.cpp.

33  {
34  Init();
35 }
DENORM::DENORM ( float  x,
float  scaling,
ROW src 
)

Definition at line 38 of file normalis.cpp.

38  {
39  Init();
40  x_origin_ = x; // just copy
41  y_origin_ = 0.0f;
42  x_scale_ = y_scale_ = scaling;
43  row_ = src;
44 }
DENORM::DENORM ( float  x,
float  scaling,
double  line_m,
double  line_c,
inT16  seg_count,
DENORM_SEG seg_pts,
BOOL8  using_row,
ROW src 
)

Definition at line 46 of file normalis.cpp.

53  {
54  Init();
55  x_origin_ = x; // just copy
56  y_origin_ = line_c;
57  ASSERT_HOST(line_m == 0.0);
58  x_scale_ = y_scale_ = scaling;
59  SetSegments(seg_pts, seg_count);
60 }
#define ASSERT_HOST(x)
Definition: errcode.h:84
DENORM::DENORM ( const DENORM src)

Definition at line 63 of file normalis.cpp.

63  {
64  num_segs_ = 0;
65  segs_ = NULL;
66  rotation_ = NULL;
67  *this = src;
68 }
#define NULL
Definition: host.h:144
DENORM::~DENORM ( )

Definition at line 92 of file normalis.cpp.

92  {
93  Clear();
94 }

Member Function Documentation

const BLOCK* DENORM::block ( ) const
inline

Definition at line 276 of file normalis.h.

276  {
277  return block_;
278  }
void DENORM::DenormTransform ( const TPOINT pt,
TPOINT original 
) const

Definition at line 233 of file normalis.cpp.

233  {
234  FCOORD src_pt(pt.x, pt.y);
235  FCOORD float_result;
236  DenormTransform(src_pt, &float_result);
237  original->x = IntCastRounded(float_result.x());
238  original->y = IntCastRounded(float_result.y());
239 }
int IntCastRounded(double x)
Definition: helpers.h:121
void DenormTransform(const TPOINT &pt, TPOINT *original) const
Definition: normalis.cpp:233
inT16 y
Definition: blobs.h:68
inT16 x
Definition: blobs.h:67
Definition: points.h:189
float y() const
Definition: points.h:212
float x() const
Definition: points.h:209
void DENORM::DenormTransform ( const FCOORD pt,
FCOORD original 
) const

Definition at line 240 of file normalis.cpp.

240  {
241  LocalDenormTransform(pt, original);
242  if (predecessor_ != NULL) {
243  predecessor_->DenormTransform(*original, original);
244  } else if (block_ != NULL) {
245  original->rotate(block_->re_rotation());
246  }
247 }
void LocalDenormTransform(const TPOINT &pt, TPOINT *original) const
Definition: normalis.cpp:210
#define NULL
Definition: host.h:144
void DenormTransform(const TPOINT &pt, TPOINT *original) const
Definition: normalis.cpp:233
void rotate(const FCOORD vec)
Definition: ipoints.h:471
FCOORD re_rotation() const
Definition: ocrblock.h:139
bool DENORM::inverse ( ) const
inline

Definition at line 249 of file normalis.h.

249  {
250  return inverse_;
251  }
void DENORM::LocalDenormTransform ( const TPOINT pt,
TPOINT original 
) const

Definition at line 210 of file normalis.cpp.

210  {
211  FCOORD src_pt(pt.x, pt.y);
212  FCOORD float_result;
213  LocalDenormTransform(src_pt, &float_result);
214  original->x = IntCastRounded(float_result.x());
215  original->y = IntCastRounded(float_result.y());
216 }
int IntCastRounded(double x)
Definition: helpers.h:121
void LocalDenormTransform(const TPOINT &pt, TPOINT *original) const
Definition: normalis.cpp:210
inT16 y
Definition: blobs.h:68
inT16 x
Definition: blobs.h:67
Definition: points.h:189
float y() const
Definition: points.h:212
float x() const
Definition: points.h:209
void DENORM::LocalDenormTransform ( const FCOORD pt,
FCOORD original 
) const

Definition at line 217 of file normalis.cpp.

217  {
218  FCOORD rotated(pt.x() - final_xshift_, pt.y() - final_yshift_);
219  if (rotation_ != NULL) {
220  FCOORD inverse_rotation(rotation_->x(), -rotation_->y());
221  rotated.rotate(inverse_rotation);
222  }
223  original->set_x(rotated.x() / x_scale_ + x_origin_);
224  float y_scale = y_scale_;
225  if (num_segs_ > 0)
226  y_scale = YScaleAtOrigX(original->x());
227  original->set_y(rotated.y() / y_scale + YOriginAtOrigX(original->x()));
228 }
#define NULL
Definition: host.h:144
void set_x(float xin)
rewrite function
Definition: points.h:216
void rotate(const FCOORD vec)
Definition: ipoints.h:471
Definition: points.h:189
float y_scale() const
Definition: normalis.h:267
float y() const
Definition: points.h:212
void set_y(float yin)
rewrite function
Definition: points.h:220
float x() const
Definition: points.h:209
void DENORM::LocalNormBlob ( TBLOB blob) const

Definition at line 251 of file normalis.cpp.

251  {
252  TBOX blob_box = blob->bounding_box();
253  float x_center = (blob_box.left() + blob_box.right()) / 2.0f;
254  ICOORD translation(-IntCastRounded(x_origin_),
255  -IntCastRounded(YOriginAtOrigX(x_center)));
256  blob->Move(translation);
257  // Note that the old way of scaling only allowed for a single
258  // scale factor.
259  float scale = YScaleAtOrigX(x_center);
260  if (scale != 1.0f)
261  blob->Scale(scale);
262  if (rotation_ != NULL)
263  blob->Rotate(*rotation_);
264  translation.set_x(IntCastRounded(final_xshift_));
265  translation.set_y(IntCastRounded(final_yshift_));
266  blob->Move(translation);
267 }
int IntCastRounded(double x)
Definition: helpers.h:121
void Rotate(const FCOORD rotation)
Definition: blobs.cpp:343
void Move(const ICOORD vec)
Definition: blobs.cpp:350
#define NULL
Definition: host.h:144
inT16 left() const
Definition: rect.h:67
Definition: rect.h:29
#define f(xc, yc)
Definition: imgscale.cpp:39
inT16 right() const
Definition: rect.h:74
TBOX bounding_box() const
Definition: blobs.cpp:384
integer coordinate
Definition: points.h:30
void Scale(float factor)
Definition: blobs.cpp:357
void DENORM::LocalNormTransform ( const TPOINT pt,
TPOINT transformed 
) const

Definition at line 170 of file normalis.cpp.

170  {
171  FCOORD src_pt(pt.x, pt.y);
172  FCOORD float_result;
173  LocalNormTransform(src_pt, &float_result);
174  transformed->x = IntCastRounded(float_result.x());
175  transformed->y = IntCastRounded(float_result.y());
176 }
int IntCastRounded(double x)
Definition: helpers.h:121
inT16 y
Definition: blobs.h:68
inT16 x
Definition: blobs.h:67
Definition: points.h:189
void LocalNormTransform(const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:170
float y() const
Definition: points.h:212
float x() const
Definition: points.h:209
void DENORM::LocalNormTransform ( const FCOORD pt,
FCOORD transformed 
) const

Definition at line 177 of file normalis.cpp.

177  {
178  FCOORD translated(pt.x() - x_origin_, pt.y() - YOriginAtOrigX(pt.x()));
179  translated.set_x(translated.x() * x_scale_);
180  translated.set_y(translated.y() * YScaleAtOrigX(pt.x()));
181  if (rotation_ != NULL)
182  translated.rotate(*rotation_);
183  transformed->set_x(translated.x() + final_xshift_);
184  transformed->set_y(translated.y() + final_yshift_);
185 }
#define NULL
Definition: host.h:144
void set_x(float xin)
rewrite function
Definition: points.h:216
Definition: points.h:189
float y() const
Definition: points.h:212
void set_y(float yin)
rewrite function
Definition: points.h:220
float x() const
Definition: points.h:209
void DENORM::NormTransform ( const TPOINT pt,
TPOINT transformed 
) const

Definition at line 190 of file normalis.cpp.

190  {
191  FCOORD src_pt(pt.x, pt.y);
192  FCOORD float_result;
193  NormTransform(src_pt, &float_result);
194  transformed->x = IntCastRounded(float_result.x());
195  transformed->y = IntCastRounded(float_result.y());
196 }
int IntCastRounded(double x)
Definition: helpers.h:121
void NormTransform(const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:190
inT16 y
Definition: blobs.h:68
inT16 x
Definition: blobs.h:67
Definition: points.h:189
float y() const
Definition: points.h:212
float x() const
Definition: points.h:209
void DENORM::NormTransform ( const FCOORD pt,
FCOORD transformed 
) const

Definition at line 197 of file normalis.cpp.

197  {
198  FCOORD src_pt(pt);
199  if (predecessor_ != NULL) {
200  predecessor_->NormTransform(pt, &src_pt);
201  } else if (block_ != NULL) {
202  FCOORD fwd_rotation(block_->re_rotation().x(), -block_->re_rotation().y());
203  src_pt.rotate(fwd_rotation);
204  }
205  LocalNormTransform(src_pt, transformed);
206 }
#define NULL
Definition: host.h:144
void NormTransform(const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:190
void rotate(const FCOORD vec)
Definition: ipoints.h:471
Definition: points.h:189
void LocalNormTransform(const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:170
float y() const
Definition: points.h:212
FCOORD re_rotation() const
Definition: ocrblock.h:139
float x() const
Definition: points.h:209
DENORM & DENORM::operator= ( const DENORM src)

Definition at line 71 of file normalis.cpp.

71  {
72  Clear();
73  inverse_ = src.inverse_;
74  pix_ = src.pix_;
75  block_ = src.block_;
76  row_ = src.row_;
77  if (src.rotation_ == NULL)
78  rotation_ = NULL;
79  else
80  rotation_ = new FCOORD(*src.rotation_);
81  predecessor_ = src.predecessor_;
82  SetSegments(src.segs_, src.num_segs_);
83  x_origin_ = src.x_origin_;
84  y_origin_ = src.y_origin_;
85  x_scale_ = src.x_scale_;
86  y_scale_ = src.y_scale_;
87  final_xshift_ = src.final_xshift_;
88  final_yshift_ = src.final_yshift_;
89  return *this;
90 }
#define NULL
Definition: host.h:144
Definition: points.h:189
Pix* DENORM::pix ( ) const
inline

Definition at line 243 of file normalis.h.

243  {
244  return pix_;
245  }
const DENORM* DENORM::predecessor ( ) const
inline

Definition at line 260 of file normalis.h.

260  {
261  return predecessor_;
262  }
const DENORM* DENORM::RootDenorm ( ) const
inline

Definition at line 255 of file normalis.h.

255  {
256  if (predecessor_ != NULL)
257  return predecessor_->RootDenorm();
258  return this;
259  }
#define NULL
Definition: host.h:144
const DENORM * RootDenorm() const
Definition: normalis.h:255
const ROW* DENORM::row ( ) const
inline

Definition at line 270 of file normalis.h.

270  {
271  return row_;
272  }
void DENORM::set_block ( const BLOCK block)
inline

Definition at line 279 of file normalis.h.

279  {
280  block_ = block;
281  }
const BLOCK * block() const
Definition: normalis.h:276
void DENORM::set_inverse ( bool  value)
inline

Definition at line 252 of file normalis.h.

252  {
253  inverse_ = value;
254  }
void DENORM::set_pix ( Pix *  pix)
inline

Definition at line 246 of file normalis.h.

246  {
247  pix_ = pix;
248  }
Pix * pix() const
Definition: normalis.h:243
void DENORM::set_row ( ROW row)
inline

Definition at line 273 of file normalis.h.

273  {
274  row_ = row;
275  }
const ROW * row() const
Definition: normalis.h:270
void DENORM::SetupBLNormalize ( const BLOCK block,
const ROW row,
float  x_height,
const TBOX word_box,
int  num_segs,
const DENORM_SEG segs 
)

Definition at line 99 of file normalis.cpp.

101  {
102  float scale = kBlnXHeight / x_height;
103  float x_origin = (word_box.left() + word_box.right()) / 2.0f;
104  float y_origin = 0.0f;
105  if (num_segs == 0 && row == NULL) {
106  y_origin = word_box.bottom();
107  }
108  SetupNormalization(block, row, NULL, NULL, segs, num_segs,
109  x_origin, y_origin, scale, scale,
110  0.0f, static_cast<float>(kBlnBaselineOffset));
111 }
const int kBlnXHeight
Definition: normalis.h:27
const int kBlnBaselineOffset
Definition: normalis.h:28
#define NULL
Definition: host.h:144
inT16 left() const
Definition: rect.h:67
#define f(xc, yc)
Definition: imgscale.cpp:39
inT16 right() const
Definition: rect.h:74
void SetupNormalization(const BLOCK *block, const ROW *row, const FCOORD *rotation, const DENORM *predecessor, const DENORM_SEG *segs, int num_segs, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift)
Definition: normalis.cpp:143
inT16 bottom() const
Definition: rect.h:60
void DENORM::SetupNormalization ( const BLOCK block,
const ROW row,
const FCOORD rotation,
const DENORM predecessor,
const DENORM_SEG segs,
int  num_segs,
float  x_origin,
float  y_origin,
float  x_scale,
float  y_scale,
float  final_xshift,
float  final_yshift 
)

Definition at line 143 of file normalis.cpp.

150  {
151  Clear();
152  block_ = block;
153  row_ = row;
154  if (rotation == NULL)
155  rotation_ = NULL;
156  else
157  rotation_ = new FCOORD(*rotation);
158  predecessor_ = predecessor;
159  SetSegments(segs, num_segs);
160  x_origin_ = x_origin;
161  y_origin_ = y_origin;
162  x_scale_ = x_scale;
163  y_scale_ = y_scale;
164  final_xshift_ = final_xshift;
165  final_yshift_ = final_yshift;
166 }
const ROW * row() const
Definition: normalis.h:270
const DENORM * predecessor() const
Definition: normalis.h:260
float x_scale() const
Definition: normalis.h:264
#define NULL
Definition: host.h:144
Definition: points.h:189
float y_scale() const
Definition: normalis.h:267
const BLOCK * block() const
Definition: normalis.h:276
float DENORM::x_scale ( ) const
inline

Definition at line 264 of file normalis.h.

264  {
265  return x_scale_;
266  }
bool DENORM::XHeightRange ( int  unichar_id,
const UNICHARSET unicharset,
const TBOX bbox,
inT16 min_xht,
inT16 max_xht 
) const

Definition at line 275 of file normalis.cpp.

277  {
278  // Clip the top and bottom to the limit of normalized feature space.
279  int top = ClipToRange<int>(bbox.top(), 0, kBlnCellHeight - 1);
280  int bottom = ClipToRange<int>(bbox.bottom(), 0, kBlnCellHeight - 1);
281  // A tolerance of yscale corresponds to 1 pixel in the image.
282  double tolerance = y_scale();
283  int min_bottom, max_bottom, min_top, max_top;
284  unicharset.get_top_bottom(unichar_id, &min_bottom, &max_bottom,
285  &min_top, &max_top);
286  // Default returns indicate a mis-fit.
287  *min_xht = 0;
288  *max_xht = 0;
289  // Chars with a misfitting bottom might be sub/superscript/dropcap, or might
290  // just be wrongly classified. Return an empty range so they have to be
291  // good to be considered.
292  if (bottom < min_bottom - tolerance || bottom > max_bottom + tolerance) {
293  return false;
294  }
295  // To help very high cap/xheight ratio fonts accept the correct x-height,
296  // and to allow the large caps in small caps to accept the xheight of the
297  // small caps, add kBlnBaselineOffset to chars with a maximum max.
298  if (max_top == kBlnCellHeight - 1)
299  max_top += kBlnBaselineOffset;
300  int height = top - kBlnBaselineOffset;
301  double min_height = min_top - kBlnBaselineOffset - tolerance;
302  double max_height = max_top - kBlnBaselineOffset + tolerance;
303  if (min_height <= 0.0) {
304  if (height <= 0 || max_height > 0)
305  *max_xht = MAX_INT16; // Anything will do.
306  } else if (height > 0) {
307  int result = IntCastRounded(height * kBlnXHeight / y_scale() / min_height);
308  *max_xht = static_cast<inT16>(ClipToRange(result, 0, MAX_INT16));
309  }
310  if (max_height > 0.0 && height > 0) {
311  int result = IntCastRounded(height * kBlnXHeight / y_scale() / max_height);
312  *min_xht = static_cast<inT16>(ClipToRange(result, 0, MAX_INT16));
313  }
314  return true;
315 }
int IntCastRounded(double x)
Definition: helpers.h:121
const int kBlnXHeight
Definition: normalis.h:27
const int kBlnCellHeight
Definition: normalis.h:26
const int kBlnBaselineOffset
Definition: normalis.h:28
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
Definition: unicharset.h:459
inT16 top() const
Definition: rect.h:53
short inT16
Definition: host.h:100
float y_scale() const
Definition: normalis.h:267
size_t top
Definition: tessarray.h:52
#define MAX_INT16
Definition: host.h:119
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:64
inT16 bottom() const
Definition: rect.h:60
float DENORM::y_scale ( ) const
inline

Definition at line 267 of file normalis.h.

267  {
268  return y_scale_;
269  }

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