mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-24 02:59:07 +08:00
More harmless improvements from 3.00 in 2.04
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@217 d0cd1f9f-072b-0410-8dd7-cf729c803f20
This commit is contained in:
parent
f371564306
commit
5c964ea6da
@ -49,6 +49,7 @@ filename(name) { //box(ICOORD(xmin,ymin),ICOORD(xmax,ymax))
|
||||
kerning = kern;
|
||||
spacing = space;
|
||||
font_class = -1; //not assigned
|
||||
cell_over_xheight_ = 2.0f;
|
||||
hand_block = NULL;
|
||||
hand_poly = NULL;
|
||||
left_it.set_to_list (&leftside);
|
||||
|
@ -118,6 +118,12 @@ class BLOCK:public ELIST_LINK, public PDBLK
|
||||
inT32 x_height() const { //return xheight
|
||||
return xheight;
|
||||
}
|
||||
float cell_over_xheight() const {
|
||||
return cell_over_xheight_;
|
||||
}
|
||||
void set_cell_over_xheight(float ratio) {
|
||||
cell_over_xheight_ = ratio;
|
||||
}
|
||||
ROW_LIST *row_list() { //get rows
|
||||
return &rows;
|
||||
}
|
||||
@ -211,6 +217,7 @@ class BLOCK:public ELIST_LINK, public PDBLK
|
||||
inT16 pitch; //pitch of non-props
|
||||
inT16 font_class; //correct font class
|
||||
inT32 xheight; //height of chars
|
||||
float cell_over_xheight_; // Ratio of cell height to xheight.
|
||||
STRING filename; //name of block
|
||||
// TEXT_REGION* hand_block; //if it exists
|
||||
// POLY_BLOCK* hand_poly; //wierd as well
|
||||
|
@ -212,6 +212,9 @@ WERD_RES::~WERD_RES () {
|
||||
WERD_RES *PAGE_RES_IT::restart_page() {
|
||||
block_res_it.set_to_list (&page_res->block_res_list);
|
||||
block_res_it.mark_cycle_pt ();
|
||||
prev_block_res = NULL;
|
||||
prev_row_res = NULL;
|
||||
prev_word_res = NULL;
|
||||
block_res = NULL;
|
||||
row_res = NULL;
|
||||
word_res = NULL;
|
||||
|
@ -33,6 +33,44 @@ bool FCOORD::normalise() { //Convert to unit vec
|
||||
return true;
|
||||
}
|
||||
|
||||
// The fortran/basic sgn function returns -1, 0, 1 if x < 0, x == 0, x > 0
|
||||
// respectively.
|
||||
static int sign(int x) {
|
||||
if (x < 0)
|
||||
return -1;
|
||||
else
|
||||
return x > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
// Setup for iterating over the pixels in a vector by the well-known
|
||||
// Bresenham rendering algorithm.
|
||||
// Starting with major/2 in the accumulator, on each step add major_step,
|
||||
// and then add minor to the accumulator. When the accumulator >= major
|
||||
// subtract major and step a minor step.
|
||||
|
||||
void ICOORD::setup_render(ICOORD* major_step, ICOORD* minor_step,
|
||||
int* major, int* minor) {
|
||||
int abs_x = abs(xcoord);
|
||||
int abs_y = abs(ycoord);
|
||||
if (abs_x >= abs_y) {
|
||||
// X-direction is major.
|
||||
major_step->xcoord = sign(xcoord);
|
||||
major_step->ycoord = 0;
|
||||
minor_step->xcoord = 0;
|
||||
minor_step->ycoord = sign(ycoord);
|
||||
*major = abs_x;
|
||||
*minor = abs_y;
|
||||
} else {
|
||||
// Y-direction is major.
|
||||
major_step->xcoord = 0;
|
||||
major_step->ycoord = sign(ycoord);
|
||||
minor_step->xcoord = sign(xcoord);
|
||||
minor_step->ycoord = 0;
|
||||
*major = abs_y;
|
||||
*minor = abs_x;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ICOORD::serialise_asc( //convert to ascii
|
||||
FILE *f //file to write
|
||||
|
@ -46,18 +46,30 @@ class DLLSYM TBOX //bounding box
|
||||
inT16 top() const { // coord of top
|
||||
return top_right.y ();
|
||||
}
|
||||
void set_top(int y) {
|
||||
top_right.set_y(y);
|
||||
}
|
||||
|
||||
inT16 bottom() const { // coord of bottom
|
||||
return bot_left.y ();
|
||||
}
|
||||
void set_bottom(int y) {
|
||||
bot_left.set_y(y);
|
||||
}
|
||||
|
||||
inT16 left() const { // coord of left
|
||||
return bot_left.x ();
|
||||
}
|
||||
void set_left(int x) {
|
||||
bot_left.set_x(x);
|
||||
}
|
||||
|
||||
inT16 right() const { // coord of right
|
||||
return top_right.x ();
|
||||
}
|
||||
void set_right(int x) {
|
||||
top_right.set_x(x);
|
||||
}
|
||||
|
||||
//access function
|
||||
const ICOORD &botleft() const {
|
||||
@ -170,10 +182,17 @@ class DLLSYM TBOX //bounding box
|
||||
BOOL8 contains( //is box inside box
|
||||
const TBOX &box) const;
|
||||
|
||||
// Do boxes overlap on x axis.
|
||||
BOOL8 x_overlap(const TBOX &box) const;
|
||||
|
||||
// Do boxes overlap on x axis by more than
|
||||
// half of the width of the narrower box.
|
||||
BOOL8 major_x_overlap(const TBOX &box) const;
|
||||
|
||||
BOOL8 overlap( //do boxes overlap
|
||||
const TBOX &box) const;
|
||||
|
||||
BOOL8 major_overlap( // Do boxes overlap more than half.
|
||||
BOOL8 major_overlap( // do boxes overlap more than half
|
||||
const TBOX &box) const;
|
||||
|
||||
TBOX intersection( //shared area box
|
||||
@ -282,4 +301,20 @@ inline BOOL8 TBOX::major_overlap( // Do boxes overlap more that half.
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline BOOL8 TBOX::x_overlap(const TBOX &box) const {
|
||||
return ((box.bot_left.x() <= top_right.x()) &&
|
||||
(box.top_right.x() >= bot_left.x()));
|
||||
}
|
||||
|
||||
inline BOOL8 TBOX::major_x_overlap(const TBOX &box) const {
|
||||
inT16 overlap = box.width();
|
||||
if (this->left() > box.left()) {
|
||||
overlap -= this->left() - box.left();
|
||||
}
|
||||
if (this->right() < box.right()) {
|
||||
overlap -= box.right() - this->right();
|
||||
}
|
||||
return (overlap >= box.width() / 2 || overlap >= this->width() / 2);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user