From 5c964ea6da12a04caf78b5b5830328673258e8f2 Mon Sep 17 00:00:00 2001 From: theraysmith Date: Tue, 30 Dec 2008 21:31:01 +0000 Subject: [PATCH] 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 --- ccstruct/ocrblock.cpp | 1 + ccstruct/ocrblock.h | 7 +++++++ ccstruct/pageres.cpp | 3 +++ ccstruct/points.cpp | 38 ++++++++++++++++++++++++++++++++++++++ ccstruct/rect.h | 37 ++++++++++++++++++++++++++++++++++++- 5 files changed, 85 insertions(+), 1 deletion(-) diff --git a/ccstruct/ocrblock.cpp b/ccstruct/ocrblock.cpp index 9fca1e1c..a1bae378 100644 --- a/ccstruct/ocrblock.cpp +++ b/ccstruct/ocrblock.cpp @@ -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); diff --git a/ccstruct/ocrblock.h b/ccstruct/ocrblock.h index cb794b80..1a755ab8 100644 --- a/ccstruct/ocrblock.h +++ b/ccstruct/ocrblock.h @@ -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 diff --git a/ccstruct/pageres.cpp b/ccstruct/pageres.cpp index 0aec3eb6..d6783012 100644 --- a/ccstruct/pageres.cpp +++ b/ccstruct/pageres.cpp @@ -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; diff --git a/ccstruct/points.cpp b/ccstruct/points.cpp index 60babf6d..6a285c1e 100644 --- a/ccstruct/points.cpp +++ b/ccstruct/points.cpp @@ -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 diff --git a/ccstruct/rect.h b/ccstruct/rect.h index 8216d559..43ad55ca 100644 --- a/ccstruct/rect.h +++ b/ccstruct/rect.h @@ -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