mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-27 20:59:36 +08:00
Prepare support for image width and height larger than 32767
Avoid using int16_t and use a new data type TDimension where needed. Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
56f54c24de
commit
59fbad0dd5
@ -28,7 +28,7 @@
|
||||
|
||||
#include <tesseract/publictypes.h> // for OcrEngineMode
|
||||
|
||||
#include <cstdint> // for int16_t
|
||||
#include "tesstypes.h" // for TDimension
|
||||
|
||||
struct Pix;
|
||||
|
||||
@ -46,8 +46,8 @@ class WERD;
|
||||
----------------------------------------------------------------------*/
|
||||
|
||||
struct TPOINT {
|
||||
TPOINT() : x(0), y(0) {}
|
||||
TPOINT(int16_t vx, int16_t vy) : x(vx), y(vy) {}
|
||||
TPOINT() = default;
|
||||
TPOINT(TDimension vx, TDimension vy) : x(vx), y(vy) {}
|
||||
TPOINT(const ICOORD &ic) : x(ic.x()), y(ic.y()) {}
|
||||
|
||||
void operator+=(const TPOINT &other) {
|
||||
@ -86,8 +86,8 @@ struct TPOINT {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
int16_t x; // absolute x coord.
|
||||
int16_t y; // absolute y coord.
|
||||
TDimension x = 0; // absolute x coord.
|
||||
TDimension y = 0; // absolute y coord.
|
||||
};
|
||||
|
||||
using VECTOR = TPOINT; // structure for coordinates.
|
||||
|
@ -31,13 +31,14 @@ namespace tesseract {
|
||||
*
|
||||
* Constructor for a simple rectangular block.
|
||||
*/
|
||||
BLOCK::BLOCK(const char *name, ///< filename
|
||||
bool prop, ///< proportional
|
||||
int16_t kern, ///< kerning
|
||||
int16_t space, ///< spacing
|
||||
int16_t xmin, ///< bottom left
|
||||
int16_t ymin, int16_t xmax, ///< top right
|
||||
int16_t ymax)
|
||||
BLOCK::BLOCK(const char *name, ///< filename
|
||||
bool prop, ///< proportional
|
||||
int16_t kern, ///< kerning
|
||||
int16_t space, ///< spacing
|
||||
TDimension xmin, ///< bottom left
|
||||
TDimension ymin,
|
||||
TDimension xmax, ///< top right
|
||||
TDimension ymax)
|
||||
: pdblk(xmin, ymin, xmax, ymax)
|
||||
, filename(name)
|
||||
, re_rotation_(1.0f, 0.0f)
|
||||
|
@ -39,10 +39,10 @@ public:
|
||||
bool prop, ///< proportional
|
||||
int16_t kern, ///< kerning
|
||||
int16_t space, ///< spacing
|
||||
int16_t xmin, ///< bottom left
|
||||
int16_t ymin,
|
||||
int16_t xmax, ///< top right
|
||||
int16_t ymax);
|
||||
TDimension xmin, ///< bottom left
|
||||
TDimension ymin,
|
||||
TDimension xmax, ///< top right
|
||||
TDimension ymax);
|
||||
|
||||
~BLOCK() = default;
|
||||
|
||||
|
@ -42,9 +42,10 @@ constexpr ERRCODE LOSTBLOCKLINE("Can't find rectangle for line");
|
||||
* Constructor for a simple rectangular block.
|
||||
**********************************************************************/
|
||||
PDBLK::PDBLK( // rectangular block
|
||||
int16_t xmin, // bottom left
|
||||
int16_t ymin, int16_t xmax, // top right
|
||||
int16_t ymax)
|
||||
TDimension xmin, // bottom left
|
||||
TDimension ymin,
|
||||
TDimension xmax, // top right
|
||||
TDimension ymax)
|
||||
: box(ICOORD(xmin, ymin), ICOORD(xmax, ymax)) {
|
||||
// boundaries
|
||||
ICOORDELT_IT left_it = &leftside;
|
||||
@ -349,9 +350,9 @@ void BLOCK_RECT_IT::forward() { // next rectangle
|
||||
* Get the the start and width of a line in the block.
|
||||
**********************************************************************/
|
||||
|
||||
int16_t BLOCK_LINE_IT::get_line( // get a line
|
||||
int16_t y, // line to get
|
||||
int16_t &xext // output extent
|
||||
TDimension BLOCK_LINE_IT::get_line( // get a line
|
||||
TDimension y, // line to get
|
||||
TDimension &xext // output extent
|
||||
) {
|
||||
ICOORD bleft; // bounding box
|
||||
ICOORD tright; // of block & rect
|
||||
|
@ -41,10 +41,10 @@ public:
|
||||
index_ = 0;
|
||||
}
|
||||
/// simple constructor
|
||||
PDBLK(int16_t xmin, ///< bottom left
|
||||
int16_t ymin,
|
||||
int16_t xmax, ///< top right
|
||||
int16_t ymax);
|
||||
PDBLK(TDimension xmin, ///< bottom left
|
||||
TDimension ymin,
|
||||
TDimension xmax, ///< top right
|
||||
TDimension ymax);
|
||||
|
||||
/// set vertex lists
|
||||
///@param left list of left vertices
|
||||
@ -145,8 +145,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
int16_t ymin = 0; ///< bottom of rectangle
|
||||
int16_t ymax = 0; ///< top of rectangle
|
||||
TDimension ymin = 0; ///< bottom of rectangle
|
||||
TDimension ymax = 0; ///< top of rectangle
|
||||
PDBLK *block = nullptr; ///< block to iterate
|
||||
ICOORDELT_IT left_it; ///< boundary iterators
|
||||
ICOORDELT_IT right_it;
|
||||
@ -172,7 +172,7 @@ public:
|
||||
/// get a line
|
||||
///@param y line to get
|
||||
///@param xext output extent
|
||||
int16_t get_line(int16_t y, int16_t &xext);
|
||||
TDimension get_line(TDimension y, TDimension &xext);
|
||||
|
||||
private:
|
||||
PDBLK *block; ///< block to iterate
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "elst.h"
|
||||
#include "errcode.h" // for ASSERT_HOST
|
||||
#include "tesstypes.h" // for TDimension
|
||||
|
||||
#include <tesseract/export.h> // for DLLSYM
|
||||
|
||||
@ -43,7 +44,7 @@ public:
|
||||
/// constructor
|
||||
///@param xin x value
|
||||
///@param yin y value
|
||||
ICOORD(int16_t xin, int16_t yin) {
|
||||
ICOORD(TDimension xin, TDimension yin) {
|
||||
xcoord = xin;
|
||||
ycoord = yin;
|
||||
}
|
||||
@ -54,20 +55,20 @@ public:
|
||||
bool Serialize(TFile *f) const;
|
||||
|
||||
/// access function
|
||||
int16_t x() const {
|
||||
TDimension x() const {
|
||||
return xcoord;
|
||||
}
|
||||
/// access_function
|
||||
int16_t y() const {
|
||||
TDimension y() const {
|
||||
return ycoord;
|
||||
}
|
||||
|
||||
/// rewrite function
|
||||
void set_x(int16_t xin) {
|
||||
void set_x(TDimension xin) {
|
||||
xcoord = xin; // write new value
|
||||
}
|
||||
/// rewrite function
|
||||
void set_y(int16_t yin) { // value to set
|
||||
void set_y(TDimension yin) { // value to set
|
||||
ycoord = yin;
|
||||
}
|
||||
|
||||
@ -128,15 +129,15 @@ public:
|
||||
/// cross product
|
||||
friend int32_t operator*(const ICOORD &, const ICOORD &);
|
||||
/// multiply
|
||||
friend ICOORD operator*(const ICOORD &, int16_t);
|
||||
friend ICOORD operator*(const ICOORD &, TDimension);
|
||||
/// multiply
|
||||
friend ICOORD operator*(int16_t, const ICOORD &);
|
||||
friend ICOORD operator*(TDimension, const ICOORD &);
|
||||
/// multiply
|
||||
friend ICOORD &operator*=(ICOORD &, int16_t);
|
||||
friend ICOORD &operator*=(ICOORD &, TDimension);
|
||||
/// divide
|
||||
friend ICOORD operator/(const ICOORD &, int16_t);
|
||||
friend ICOORD operator/(const ICOORD &, TDimension);
|
||||
/// divide
|
||||
friend ICOORD &operator/=(ICOORD &, int16_t);
|
||||
friend ICOORD &operator/=(ICOORD &, TDimension);
|
||||
/// rotate
|
||||
///@param vec by vector
|
||||
void rotate(const FCOORD &vec);
|
||||
@ -155,8 +156,8 @@ public:
|
||||
bool DeSerialize(bool swap, FILE *fp);
|
||||
|
||||
protected:
|
||||
int16_t xcoord; ///< x value
|
||||
int16_t ycoord; ///< y value
|
||||
TDimension xcoord; ///< x value
|
||||
TDimension ycoord; ///< y value
|
||||
};
|
||||
|
||||
class ICOORDELT : public ELIST_LINK,
|
||||
@ -171,7 +172,7 @@ public:
|
||||
/// constructor
|
||||
///@param xin x value
|
||||
///@param yin y value
|
||||
ICOORDELT(int16_t xin, int16_t yin) {
|
||||
ICOORDELT(TDimension xin, TDimension yin) {
|
||||
xcoord = xin;
|
||||
ycoord = yin;
|
||||
}
|
||||
@ -438,7 +439,7 @@ inline int32_t operator*( // cross product
|
||||
|
||||
inline ICOORD operator*( // scalar multiply
|
||||
const ICOORD &op1, // operands
|
||||
int16_t scale) {
|
||||
TDimension scale) {
|
||||
ICOORD result; // output
|
||||
|
||||
result.xcoord = op1.xcoord * scale;
|
||||
@ -447,7 +448,7 @@ inline ICOORD operator*( // scalar multiply
|
||||
}
|
||||
|
||||
inline ICOORD operator*( // scalar multiply
|
||||
int16_t scale,
|
||||
TDimension scale,
|
||||
const ICOORD &op1 // operands
|
||||
) {
|
||||
ICOORD result; // output
|
||||
@ -465,7 +466,7 @@ inline ICOORD operator*( // scalar multiply
|
||||
|
||||
inline ICOORD &operator*=( // scalar multiply
|
||||
ICOORD &op1, // operands
|
||||
int16_t scale) {
|
||||
TDimension scale) {
|
||||
op1.xcoord *= scale;
|
||||
op1.ycoord *= scale;
|
||||
return op1;
|
||||
@ -479,7 +480,7 @@ inline ICOORD &operator*=( // scalar multiply
|
||||
|
||||
inline ICOORD operator/( // scalar divide
|
||||
const ICOORD &op1, // operands
|
||||
int16_t scale) {
|
||||
TDimension scale) {
|
||||
ICOORD result; // output
|
||||
|
||||
result.xcoord = op1.xcoord / scale;
|
||||
@ -495,7 +496,7 @@ inline ICOORD operator/( // scalar divide
|
||||
|
||||
inline ICOORD &operator/=( // scalar divide
|
||||
ICOORD &op1, // operands
|
||||
int16_t scale) {
|
||||
TDimension scale) {
|
||||
op1.xcoord /= scale;
|
||||
op1.ycoord /= scale;
|
||||
return op1;
|
||||
@ -509,8 +510,8 @@ inline ICOORD &operator/=( // scalar divide
|
||||
|
||||
inline void ICOORD::rotate( // rotate by vector
|
||||
const FCOORD &vec) {
|
||||
auto tmp = static_cast<int16_t>(std::floor(xcoord * vec.x() - ycoord * vec.y() + 0.5f));
|
||||
ycoord = static_cast<int16_t>(std::floor(ycoord * vec.x() + xcoord * vec.y() + 0.5f));
|
||||
auto tmp = static_cast<TDimension>(std::floor(xcoord * vec.x() - ycoord * vec.y() + 0.5f));
|
||||
ycoord = static_cast<TDimension>(std::floor(ycoord * vec.x() + xcoord * vec.y() + 0.5f));
|
||||
xcoord = tmp;
|
||||
}
|
||||
|
||||
|
@ -198,8 +198,8 @@ void POLY_BLOCK::rotate(FCOORD rotation) {
|
||||
pos.set_x(pt->x());
|
||||
pos.set_y(pt->y());
|
||||
pos.rotate(rotation);
|
||||
pt->set_x(static_cast<int16_t>(floor(pos.x() + 0.5)));
|
||||
pt->set_y(static_cast<int16_t>(floor(pos.y() + 0.5)));
|
||||
pt->set_x(static_cast<TDimension>(floor(pos.x() + 0.5)));
|
||||
pt->set_y(static_cast<TDimension>(floor(pos.y() + 0.5)));
|
||||
pts.forward();
|
||||
} while (!pts.at_first());
|
||||
compute_bb();
|
||||
@ -270,15 +270,12 @@ void POLY_BLOCK::plot(ScrollView *window, int32_t num) {
|
||||
}
|
||||
|
||||
void POLY_BLOCK::fill(ScrollView *window, ScrollView::Color colour) {
|
||||
int16_t y;
|
||||
int16_t width;
|
||||
PB_LINE_IT *lines;
|
||||
ICOORDELT_IT s_it;
|
||||
|
||||
lines = new PB_LINE_IT(this);
|
||||
std::unique_ptr<PB_LINE_IT> lines(new PB_LINE_IT(this));
|
||||
window->Pen(colour);
|
||||
|
||||
for (y = this->bounding_box()->bottom(); y <= this->bounding_box()->top(); y++) {
|
||||
for (auto y = this->bounding_box()->bottom(); y <= this->bounding_box()->top(); y++) {
|
||||
const std::unique_ptr</*non-const*/ ICOORDELT_LIST> segments(lines->get_line(y));
|
||||
if (!segments->empty()) {
|
||||
s_it.set_to_list(segments.get());
|
||||
@ -286,14 +283,12 @@ void POLY_BLOCK::fill(ScrollView *window, ScrollView::Color colour) {
|
||||
// Note different use of ICOORDELT, x coord is x coord of pixel
|
||||
// at the start of line segment, y coord is length of line segment
|
||||
// Last pixel is start pixel + length.
|
||||
width = s_it.data()->y();
|
||||
auto width = s_it.data()->y();
|
||||
window->SetCursor(s_it.data()->x(), y);
|
||||
window->DrawTo(s_it.data()->x() + static_cast<float>(width), y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete lines;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -339,7 +334,7 @@ bool POLY_BLOCK::overlap(POLY_BLOCK *other) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ICOORDELT_LIST *PB_LINE_IT::get_line(int16_t y) {
|
||||
ICOORDELT_LIST *PB_LINE_IT::get_line(TDimension y) {
|
||||
ICOORDELT_IT v, r;
|
||||
ICOORDELT_LIST *result;
|
||||
ICOORDELT *x, *current, *previous;
|
||||
@ -356,7 +351,7 @@ ICOORDELT_LIST *PB_LINE_IT::get_line(int16_t y) {
|
||||
float fx =
|
||||
0.5f + previous->x() +
|
||||
(current->x() - previous->x()) * (fy - previous->y()) / (current->y() - previous->y());
|
||||
x = new ICOORDELT(static_cast<int16_t>(fx), 0);
|
||||
x = new ICOORDELT(static_cast<TDimension>(fx), 0);
|
||||
r.add_to_end(x);
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public:
|
||||
// Each element of the returned list is the start (x) and extent(y) of
|
||||
// a run inside the region.
|
||||
// Delete the returned list after use.
|
||||
ICOORDELT_LIST *get_line(int16_t y);
|
||||
ICOORDELT_LIST *get_line(TDimension y);
|
||||
|
||||
private:
|
||||
POLY_BLOCK *block;
|
||||
|
@ -83,10 +83,10 @@ void TBOX::rotate_large(const FCOORD &vec) {
|
||||
|
||||
TBOX TBOX::intersection( // shared area box
|
||||
const TBOX &box) const {
|
||||
int16_t left;
|
||||
int16_t bottom;
|
||||
int16_t right;
|
||||
int16_t top;
|
||||
TDimension left;
|
||||
TDimension bottom;
|
||||
TDimension right;
|
||||
TDimension top;
|
||||
if (overlap(box)) {
|
||||
if (box.bot_left.x() > bot_left.x()) {
|
||||
left = box.bot_left.x();
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "points.h" // for ICOORD, FCOORD
|
||||
#include "scrollview.h" // for ScrollView, ScrollView::Color
|
||||
#include "tesstypes.h" // for TDimension
|
||||
#include "tprintf.h" // for tprintf
|
||||
|
||||
#include <tesseract/export.h> // for DLLSYM
|
||||
@ -50,7 +51,7 @@ public:
|
||||
// in the right order.
|
||||
//*********************************************************************
|
||||
TBOX( // constructor
|
||||
int16_t left, int16_t bottom, int16_t right, int16_t top)
|
||||
TDimension left, TDimension bottom, TDimension right, TDimension top)
|
||||
: bot_left(left, bottom), top_right(right, top) {}
|
||||
|
||||
TBOX( // box around FCOORD
|
||||
@ -64,28 +65,28 @@ public:
|
||||
return bot_left == other.bot_left && top_right == other.top_right;
|
||||
}
|
||||
|
||||
int16_t top() const { // coord of top
|
||||
TDimension top() const { // coord of top
|
||||
return top_right.y();
|
||||
}
|
||||
void set_top(int y) {
|
||||
top_right.set_y(y);
|
||||
}
|
||||
|
||||
int16_t bottom() const { // coord of bottom
|
||||
TDimension bottom() const { // coord of bottom
|
||||
return bot_left.y();
|
||||
}
|
||||
void set_bottom(int y) {
|
||||
bot_left.set_y(y);
|
||||
}
|
||||
|
||||
int16_t left() const { // coord of left
|
||||
TDimension left() const { // coord of left
|
||||
return bot_left.x();
|
||||
}
|
||||
void set_left(int x) {
|
||||
bot_left.set_x(x);
|
||||
}
|
||||
|
||||
int16_t right() const { // coord of right
|
||||
TDimension right() const { // coord of right
|
||||
return top_right.x();
|
||||
}
|
||||
void set_right(int x) {
|
||||
@ -114,7 +115,7 @@ public:
|
||||
return top_right;
|
||||
}
|
||||
|
||||
int16_t height() const { // how high is it?
|
||||
TDimension height() const { // how high is it?
|
||||
if (!null_box()) {
|
||||
return top_right.y() - bot_left.y();
|
||||
} else {
|
||||
@ -122,7 +123,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
int16_t width() const { // how high is it?
|
||||
TDimension width() const { // how high is it?
|
||||
if (!null_box()) {
|
||||
return top_right.x() - bot_left.x();
|
||||
} else {
|
||||
@ -147,22 +148,22 @@ public:
|
||||
}
|
||||
|
||||
void move_bottom_edge( // move one edge
|
||||
const int16_t y) { // by +/- y
|
||||
const TDimension y) { // by +/- y
|
||||
bot_left += ICOORD(0, y);
|
||||
}
|
||||
|
||||
void move_left_edge( // move one edge
|
||||
const int16_t x) { // by +/- x
|
||||
const TDimension x) { // by +/- x
|
||||
bot_left += ICOORD(x, 0);
|
||||
}
|
||||
|
||||
void move_right_edge( // move one edge
|
||||
const int16_t x) { // by +/- x
|
||||
const TDimension x) { // by +/- x
|
||||
top_right += ICOORD(x, 0);
|
||||
}
|
||||
|
||||
void move_top_edge( // move one edge
|
||||
const int16_t y) { // by +/- y
|
||||
const TDimension y) { // by +/- y
|
||||
top_right += ICOORD(0, y);
|
||||
}
|
||||
|
||||
@ -174,33 +175,33 @@ public:
|
||||
|
||||
void move( // move box
|
||||
const FCOORD vec) { // by float vector
|
||||
bot_left.set_x(static_cast<int16_t>(std::floor(bot_left.x() + vec.x())));
|
||||
bot_left.set_x(static_cast<TDimension>(std::floor(bot_left.x() + vec.x())));
|
||||
// round left
|
||||
bot_left.set_y(static_cast<int16_t>(std::floor(bot_left.y() + vec.y())));
|
||||
bot_left.set_y(static_cast<TDimension>(std::floor(bot_left.y() + vec.y())));
|
||||
// round down
|
||||
top_right.set_x(static_cast<int16_t>(std::ceil(top_right.x() + vec.x())));
|
||||
top_right.set_x(static_cast<TDimension>(std::ceil(top_right.x() + vec.x())));
|
||||
// round right
|
||||
top_right.set_y(static_cast<int16_t>(std::ceil(top_right.y() + vec.y())));
|
||||
top_right.set_y(static_cast<TDimension>(std::ceil(top_right.y() + vec.y())));
|
||||
// round up
|
||||
}
|
||||
|
||||
void scale( // scale box
|
||||
const float f) { // by multiplier
|
||||
// round left
|
||||
bot_left.set_x(static_cast<int16_t>(std::floor(bot_left.x() * f)));
|
||||
bot_left.set_x(static_cast<TDimension>(std::floor(bot_left.x() * f)));
|
||||
// round down
|
||||
bot_left.set_y(static_cast<int16_t>(std::floor(bot_left.y() * f)));
|
||||
bot_left.set_y(static_cast<TDimension>(std::floor(bot_left.y() * f)));
|
||||
// round right
|
||||
top_right.set_x(static_cast<int16_t>(std::ceil(top_right.x() * f)));
|
||||
top_right.set_x(static_cast<TDimension>(std::ceil(top_right.x() * f)));
|
||||
// round up
|
||||
top_right.set_y(static_cast<int16_t>(std::ceil(top_right.y() * f)));
|
||||
top_right.set_y(static_cast<TDimension>(std::ceil(top_right.y() * f)));
|
||||
}
|
||||
void scale( // scale box
|
||||
const FCOORD vec) { // by float vector
|
||||
bot_left.set_x(static_cast<int16_t>(std::floor(bot_left.x() * vec.x())));
|
||||
bot_left.set_y(static_cast<int16_t>(std::floor(bot_left.y() * vec.y())));
|
||||
top_right.set_x(static_cast<int16_t>(std::ceil(top_right.x() * vec.x())));
|
||||
top_right.set_y(static_cast<int16_t>(std::ceil(top_right.y() * vec.y())));
|
||||
bot_left.set_x(static_cast<TDimension>(std::floor(bot_left.x() * vec.x())));
|
||||
bot_left.set_y(static_cast<TDimension>(std::floor(bot_left.y() * vec.y())));
|
||||
top_right.set_x(static_cast<TDimension>(std::ceil(top_right.x() * vec.x())));
|
||||
top_right.set_y(static_cast<TDimension>(std::ceil(top_right.y() * vec.y())));
|
||||
}
|
||||
|
||||
// rotate doesn't enlarge the box - it just rotates the bottom-left
|
||||
@ -330,9 +331,9 @@ inline TBOX::TBOX( // constructor
|
||||
const FCOORD pt // floating centre
|
||||
) {
|
||||
bot_left =
|
||||
ICOORD(static_cast<int16_t>(std::floor(pt.x())), static_cast<int16_t>(std::floor(pt.y())));
|
||||
ICOORD(static_cast<TDimension>(std::floor(pt.x())), static_cast<TDimension>(std::floor(pt.y())));
|
||||
top_right =
|
||||
ICOORD(static_cast<int16_t>(std::ceil(pt.x())), static_cast<int16_t>(std::ceil(pt.y())));
|
||||
ICOORD(static_cast<TDimension>(std::ceil(pt.x())), static_cast<TDimension>(std::ceil(pt.y())));
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
@ -416,7 +417,7 @@ inline bool TBOX::x_overlap(const TBOX &box) const {
|
||||
**********************************************************************/
|
||||
|
||||
inline bool TBOX::major_x_overlap(const TBOX &box) const {
|
||||
int16_t overlap = box.width();
|
||||
TDimension overlap = box.width();
|
||||
if (this->left() > box.left()) {
|
||||
overlap -= this->left() - box.left();
|
||||
}
|
||||
@ -442,7 +443,7 @@ inline bool TBOX::y_overlap(const TBOX &box) const {
|
||||
**********************************************************************/
|
||||
|
||||
inline bool TBOX::major_y_overlap(const TBOX &box) const {
|
||||
int16_t overlap = box.height();
|
||||
TDimension overlap = box.height();
|
||||
if (this->bottom() > box.bottom()) {
|
||||
overlap -= this->bottom() - box.bottom();
|
||||
}
|
||||
|
@ -21,12 +21,16 @@
|
||||
# include "config_auto.h" // FAST_FLOAT
|
||||
#endif
|
||||
|
||||
#include <cstdint> // for int16_t
|
||||
#include <cstdint> // for int16_t, int32_t
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// Image dimensions (width and height, coordinates).
|
||||
#if defined(LARGE_IMAGES)
|
||||
using TDimension = int32_t;
|
||||
#else
|
||||
using TDimension = int16_t;
|
||||
#endif
|
||||
|
||||
// Floating point data type used for LSTM calculations.
|
||||
#if defined(FAST_FLOAT)
|
||||
|
@ -50,16 +50,11 @@ bool test_underline( // look for underlines
|
||||
int16_t baseline, ///< coords of baseline
|
||||
int16_t xheight ///< height of line
|
||||
) {
|
||||
int16_t occ;
|
||||
int16_t blob_width; // width of blob
|
||||
TBOX blob_box; // bounding box
|
||||
int32_t desc_occ;
|
||||
int32_t x_occ;
|
||||
int32_t asc_occ;
|
||||
TDimension occ;
|
||||
STATS projection;
|
||||
|
||||
blob_box = blob->bounding_box();
|
||||
blob_width = blob->bounding_box().width();
|
||||
auto blob_box = blob->bounding_box();
|
||||
auto blob_width = blob->bounding_box().width();
|
||||
projection.set_range(blob_box.bottom(), blob_box.top() + 1);
|
||||
if (testing_on) {
|
||||
// blob->plot(to_win,GOLDENROD,GOLDENROD);
|
||||
@ -73,21 +68,21 @@ bool test_underline( // look for underlines
|
||||
blob->bounding_box().right(), blob->bounding_box().top(), baseline);
|
||||
}
|
||||
horizontal_cblob_projection(blob, &projection);
|
||||
desc_occ = 0;
|
||||
int32_t desc_occ = 0;
|
||||
for (occ = blob_box.bottom(); occ < baseline; occ++) {
|
||||
if (occ <= blob_box.top() && projection.pile_count(occ) > desc_occ) {
|
||||
// max in region
|
||||
desc_occ = projection.pile_count(occ);
|
||||
}
|
||||
}
|
||||
x_occ = 0;
|
||||
int32_t x_occ = 0;
|
||||
for (occ = baseline; occ <= baseline + xheight; occ++) {
|
||||
if (occ >= blob_box.bottom() && occ <= blob_box.top() && projection.pile_count(occ) > x_occ) {
|
||||
// max in region
|
||||
x_occ = projection.pile_count(occ);
|
||||
}
|
||||
}
|
||||
asc_occ = 0;
|
||||
int32_t asc_occ = 0;
|
||||
for (occ = baseline + xheight + 1; occ <= blob_box.top(); occ++) {
|
||||
if (occ >= blob_box.bottom() && projection.pile_count(occ) > asc_occ) {
|
||||
asc_occ = projection.pile_count(occ);
|
||||
|
@ -77,8 +77,8 @@ OL_BUCKETS::OL_BUCKETS(ICOORD bleft, // corners
|
||||
*/
|
||||
|
||||
C_OUTLINE_LIST *OL_BUCKETS::operator()( // array access
|
||||
int16_t x, // image coords
|
||||
int16_t y) {
|
||||
TDimension x, // image coords
|
||||
TDimension y) {
|
||||
return &buckets[(y - bl.y()) / BUCKETSIZE * bxdim +
|
||||
(x - bl.x()) / BUCKETSIZE];
|
||||
}
|
||||
@ -122,9 +122,8 @@ int32_t OL_BUCKETS::outline_complexity(C_OUTLINE *outline, // parent outline
|
||||
int32_t max_count, // max output
|
||||
int16_t depth // recurion depth
|
||||
) {
|
||||
int16_t xmin, xmax; // coord limits
|
||||
int16_t ymin, ymax;
|
||||
int16_t xindex, yindex; // current bucket
|
||||
TDimension xmin, xmax; // coord limits
|
||||
TDimension ymin, ymax;
|
||||
C_OUTLINE *child; // current child
|
||||
int32_t child_count; // no of children
|
||||
int32_t grandchild_count; // no of grandchildren
|
||||
@ -141,8 +140,8 @@ int32_t OL_BUCKETS::outline_complexity(C_OUTLINE *outline, // parent outline
|
||||
return max_count + depth;
|
||||
}
|
||||
|
||||
for (yindex = ymin; yindex <= ymax; yindex++) {
|
||||
for (xindex = xmin; xindex <= xmax; xindex++) {
|
||||
for (auto yindex = ymin; yindex <= ymax; yindex++) {
|
||||
for (auto xindex = xmin; xindex <= xmax; xindex++) {
|
||||
child_it.set_to_list(&buckets[yindex * bxdim + xindex]);
|
||||
if (child_it.empty()) {
|
||||
continue;
|
||||
@ -198,9 +197,8 @@ int32_t OL_BUCKETS::count_children( // recursive count
|
||||
int32_t max_count // max output
|
||||
) {
|
||||
bool parent_box; // could it be boxy
|
||||
int16_t xmin, xmax; // coord limits
|
||||
int16_t ymin, ymax;
|
||||
int16_t xindex, yindex; // current bucket
|
||||
TDimension xmin, xmax; // coord limits
|
||||
TDimension ymin, ymax;
|
||||
C_OUTLINE *child; // current child
|
||||
int32_t child_count; // no of children
|
||||
int32_t grandchild_count; // no of grandchildren
|
||||
@ -221,8 +219,8 @@ int32_t OL_BUCKETS::count_children( // recursive count
|
||||
parent_area = 0;
|
||||
max_parent_area = 0;
|
||||
parent_box = true;
|
||||
for (yindex = ymin; yindex <= ymax; yindex++) {
|
||||
for (xindex = xmin; xindex <= xmax; xindex++) {
|
||||
for (auto yindex = ymin; yindex <= ymax; yindex++) {
|
||||
for (auto xindex = xmin; xindex <= xmax; xindex++) {
|
||||
child_it.set_to_list(&buckets[yindex * bxdim + xindex]);
|
||||
if (child_it.empty()) {
|
||||
continue;
|
||||
@ -321,9 +319,8 @@ void OL_BUCKETS::extract_children( // recursive count
|
||||
C_OUTLINE *outline, // parent outline
|
||||
C_OUTLINE_IT *it // destination iterator
|
||||
) {
|
||||
int16_t xmin, xmax; // coord limits
|
||||
int16_t ymin, ymax;
|
||||
int16_t xindex, yindex; // current bucket
|
||||
TDimension xmin, xmax; // coord limits
|
||||
TDimension ymin, ymax;
|
||||
TBOX olbox;
|
||||
C_OUTLINE_IT child_it; // search iterator
|
||||
|
||||
@ -332,8 +329,8 @@ void OL_BUCKETS::extract_children( // recursive count
|
||||
xmax = (olbox.right() - bl.x()) / BUCKETSIZE;
|
||||
ymin = (olbox.bottom() - bl.y()) / BUCKETSIZE;
|
||||
ymax = (olbox.top() - bl.y()) / BUCKETSIZE;
|
||||
for (yindex = ymin; yindex <= ymax; yindex++) {
|
||||
for (xindex = xmin; xindex <= xmax; xindex++) {
|
||||
for (auto yindex = ymin; yindex <= ymax; yindex++) {
|
||||
for (auto xindex = xmin; xindex <= xmax; xindex++) {
|
||||
child_it.set_to_list(&buckets[yindex * bxdim + xindex]);
|
||||
for (child_it.mark_cycle_pt(); !child_it.cycled_list();
|
||||
child_it.forward()) {
|
||||
|
@ -34,8 +34,8 @@ public:
|
||||
ICOORD tright);
|
||||
|
||||
C_OUTLINE_LIST *operator()( // array access
|
||||
int16_t x, // image coords
|
||||
int16_t y);
|
||||
TDimension x, // image coords
|
||||
TDimension y);
|
||||
// first non-empty bucket
|
||||
C_OUTLINE_LIST *start_scan();
|
||||
// next non-empty bucket
|
||||
|
@ -44,11 +44,11 @@ static void free_crackedges(CRACKEDGE *start);
|
||||
static void join_edges(CRACKEDGE *edge1, CRACKEDGE *edge2, CRACKEDGE **free_cracks,
|
||||
C_OUTLINE_IT *outline_it);
|
||||
|
||||
static void line_edges(int16_t x, int16_t y, int16_t xext, uint8_t uppercolour, uint8_t *bwpos,
|
||||
static void line_edges(TDimension x, TDimension y, TDimension xext, uint8_t uppercolour, uint8_t *bwpos,
|
||||
CRACKEDGE **prevline, CRACKEDGE **free_cracks, C_OUTLINE_IT *outline_it);
|
||||
|
||||
static void make_margins(PDBLK *block, BLOCK_LINE_IT *line_it, uint8_t *pixels, uint8_t margin,
|
||||
int16_t left, int16_t right, int16_t y);
|
||||
TDimension left, TDimension right, TDimension y);
|
||||
|
||||
static CRACKEDGE *h_edge(int sign, CRACKEDGE *join, CrackPos *pos);
|
||||
static CRACKEDGE *v_edge(int sign, CRACKEDGE *join, CrackPos *pos);
|
||||
@ -114,14 +114,11 @@ static void make_margins( // get a line
|
||||
BLOCK_LINE_IT *line_it, // for old style
|
||||
uint8_t *pixels, // pixels to strip
|
||||
uint8_t margin, // white-out pixel
|
||||
int16_t left, // block edges
|
||||
int16_t right,
|
||||
int16_t y // line coord
|
||||
TDimension left, // block edges
|
||||
TDimension right,
|
||||
TDimension y // line coord
|
||||
) {
|
||||
ICOORDELT_IT seg_it;
|
||||
int32_t start; // of segment
|
||||
int16_t xext; // of segment
|
||||
int xindex; // index to pixel
|
||||
|
||||
if (block->poly_block() != nullptr) {
|
||||
std::unique_ptr<PB_LINE_IT> lines(new PB_LINE_IT(block->poly_block()));
|
||||
@ -129,9 +126,9 @@ static void make_margins( // get a line
|
||||
if (!segments->empty()) {
|
||||
seg_it.set_to_list(segments.get());
|
||||
seg_it.mark_cycle_pt();
|
||||
start = seg_it.data()->x();
|
||||
xext = seg_it.data()->y();
|
||||
for (xindex = left; xindex < right; xindex++) {
|
||||
auto start = seg_it.data()->x();
|
||||
auto xext = seg_it.data()->y();
|
||||
for (auto xindex = left; xindex < right; xindex++) {
|
||||
if (xindex >= start && !seg_it.cycled_list()) {
|
||||
xindex = start + xext - 1;
|
||||
seg_it.forward();
|
||||
@ -142,16 +139,17 @@ static void make_margins( // get a line
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (xindex = left; xindex < right; xindex++) {
|
||||
for (auto xindex = left; xindex < right; xindex++) {
|
||||
pixels[xindex - left] = margin;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
start = line_it->get_line(y, xext);
|
||||
for (xindex = left; xindex < start; xindex++) {
|
||||
TDimension xext; // of segment
|
||||
auto start = line_it->get_line(y, xext);
|
||||
for (auto xindex = left; xindex < start; xindex++) {
|
||||
pixels[xindex - left] = margin;
|
||||
}
|
||||
for (xindex = start + xext; xindex < right; xindex++) {
|
||||
for (auto xindex = start + xext; xindex < right; xindex++) {
|
||||
pixels[xindex - left] = margin;
|
||||
}
|
||||
}
|
||||
@ -164,9 +162,9 @@ static void make_margins( // get a line
|
||||
* When edges close into loops, send them for approximation.
|
||||
**********************************************************************/
|
||||
|
||||
static void line_edges(int16_t x, // coord of line start
|
||||
int16_t y, // coord of line
|
||||
int16_t xext, // width of line
|
||||
static void line_edges(TDimension x, // coord of line start
|
||||
TDimension y, // coord of line
|
||||
TDimension xext, // width of line
|
||||
uint8_t uppercolour, // start of prev line
|
||||
uint8_t *bwpos, // thresholded line
|
||||
CRACKEDGE **prevline, // edges in progress
|
||||
|
@ -162,7 +162,6 @@ void find_underlined_blobs( // get chop points
|
||||
float baseline_offset, // amount to shrinke it
|
||||
ICOORDELT_LIST *chop_cells // places to chop
|
||||
) {
|
||||
int16_t x, y; // sides of blob
|
||||
ICOORD blob_chop; // sides of blob
|
||||
TBOX blob_box = u_line->bounding_box();
|
||||
// cell iterator
|
||||
@ -180,9 +179,10 @@ void find_underlined_blobs( // get chop points
|
||||
&middle_proj, &upper_proj);
|
||||
}
|
||||
|
||||
for (x = blob_box.left(); x < blob_box.right(); x++) {
|
||||
for (auto x = blob_box.left(); x < blob_box.right(); x++) {
|
||||
if (middle_proj.pile_count(x) > 0) {
|
||||
for (y = x + 1; y < blob_box.right() && middle_proj.pile_count(y) > 0; y++) {
|
||||
auto y = x + 1;
|
||||
for (; y < blob_box.right() && middle_proj.pile_count(y) > 0; y++) {
|
||||
;
|
||||
}
|
||||
blob_chop = ICOORD(x, y);
|
||||
|
Loading…
Reference in New Issue
Block a user