#include <textlineprojection.h>
|
| TextlineProjection (int resolution) |
|
| ~TextlineProjection () |
|
void | ConstructProjection (TO_BLOCK *input_block, const FCOORD &rotation, Pix *nontext_map) |
|
void | PlotGradedBlobs (BLOBNBOX_LIST *blobs, ScrollView *win) |
|
void | MoveNonTextlineBlobs (BLOBNBOX_LIST *blobs, BLOBNBOX_LIST *small_blobs) const |
|
void | DisplayProjection () const |
|
int | DistanceOfBoxFromPartition (const TBOX &box, const ColPartition &part, const DENORM *denorm, bool debug) const |
|
int | DistanceOfBoxFromBox (const TBOX &from_box, const TBOX &to_box, bool horizontal_textline, const DENORM *denorm, bool debug) const |
|
int | VerticalDistance (bool debug, int x, int y1, int y2) const |
|
int | HorizontalDistance (bool debug, int x1, int x2, int y) const |
|
bool | BoxOutOfHTextline (const TBOX &box, const DENORM *denorm, bool debug) const |
|
int | EvaluateColPartition (const ColPartition &part, const DENORM *denorm, bool debug) const |
|
int | EvaluateBox (const TBOX &box, const DENORM *denorm, bool debug) const |
|
Definition at line 33 of file textlineprojection.h.
◆ TextlineProjection()
tesseract::TextlineProjection::TextlineProjection |
( |
int |
resolution | ) |
|
|
explicit |
Definition at line 45 of file textlineprojection.cpp.
46 : x_origin_(0), y_origin_(0), pix_(NULL) {
49 if (scale_factor_ < 1) scale_factor_ = 1;
int IntCastRounded(double x)
◆ ~TextlineProjection()
tesseract::TextlineProjection::~TextlineProjection |
( |
| ) |
|
◆ BoxOutOfHTextline()
bool tesseract::TextlineProjection::BoxOutOfHTextline |
( |
const TBOX & |
box, |
|
|
const DENORM * |
denorm, |
|
|
bool |
debug |
|
) |
| const |
Definition at line 342 of file textlineprojection.cpp.
347 EvaluateBoxInternal(box, denorm, debug, &grad1, &grad2, NULL, NULL);
348 int worst_result =
MIN(grad1, grad2);
349 int total_result = grad1 + grad2;
350 if (total_result >= 6)
return false;
353 if (worst_result < 0)
◆ ConstructProjection()
void tesseract::TextlineProjection::ConstructProjection |
( |
TO_BLOCK * |
input_block, |
|
|
const FCOORD & |
rotation, |
|
|
Pix * |
nontext_map |
|
) |
| |
Definition at line 62 of file textlineprojection.cpp.
66 TBOX image_box(0, 0, pixGetWidth(nontext_map), pixGetHeight(nontext_map));
68 y_origin_ = image_box.height();
69 int width = (image_box.width() + scale_factor_ - 1) / scale_factor_;
70 int height = (image_box.height() + scale_factor_ - 1) / scale_factor_;
72 pix_ = pixCreate(width, height, 8);
73 ProjectBlobs(&input_block->
blobs, rotation, image_box, nontext_map);
74 ProjectBlobs(&input_block->
large_blobs, rotation, image_box, nontext_map);
75 Pix* final_pix = pixBlockconv(pix_, 1, 1);
BLOBNBOX_LIST large_blobs
◆ DisplayProjection()
void tesseract::TextlineProjection::DisplayProjection |
( |
| ) |
const |
Definition at line 121 of file textlineprojection.cpp.
122 int width = pixGetWidth(pix_);
123 int height = pixGetHeight(pix_);
124 Pix* pixc = pixCreate(width, height, 32);
125 int src_wpl = pixGetWpl(pix_);
126 int col_wpl = pixGetWpl(pixc);
127 uinT32* src_data = pixGetData(pix_);
128 uinT32* col_data = pixGetData(pixc);
129 for (
int y = 0; y < height; ++y, src_data += src_wpl, col_data += col_wpl) {
130 for (
int x = 0; x < width; ++x) {
131 int pixel = GET_DATA_BYTE(src_data, x);
134 composeRGBPixel(0, 0, pixel * 15, &result);
135 else if (pixel <= 145)
136 composeRGBPixel(0, (pixel - 17) * 2, 255, &result);
138 composeRGBPixel((pixel - 145) * 2, 255, 255, &result);
139 col_data[x] = result;
145 width, height, width, height);
146 win->
Image(pixc, 0, 0);
149 pixWrite(
"projection.png", pixc, IFF_PNG);
void Image(struct Pix *image, int x_pos, int y_pos)
◆ DistanceOfBoxFromBox()
int tesseract::TextlineProjection::DistanceOfBoxFromBox |
( |
const TBOX & |
from_box, |
|
|
const TBOX & |
to_box, |
|
|
bool |
horizontal_textline, |
|
|
const DENORM * |
denorm, |
|
|
bool |
debug |
|
) |
| const |
Definition at line 198 of file textlineprojection.cpp.
205 int parallel_gap = 0;
210 if (horizontal_textline) {
211 parallel_gap = from_box.
x_gap(to_box) + from_box.
width();
212 start_pt.
x = (from_box.
left() + from_box.
right()) / 2;
213 end_pt.
x = start_pt.
x;
215 start_pt.
y = from_box.
top();
216 end_pt.
y =
MIN(to_box.
top(), start_pt.
y);
218 start_pt.
y = from_box.
bottom();
222 parallel_gap = from_box.
y_gap(to_box) + from_box.
height();
224 start_pt.
x = from_box.
right();
227 start_pt.
x = from_box.
left();
228 end_pt.
x =
MAX(to_box.
left(), start_pt.
x);
230 start_pt.
y = (from_box.
bottom() + from_box.
top()) / 2;
231 end_pt.
y = start_pt.
y;
237 int perpendicular_gap = 0;
241 if (start_pt.
x != end_pt.
x || start_pt.
y != end_pt.
y) {
242 if (denorm != NULL) {
247 if (abs(start_pt.
y - end_pt.
y) >= abs(start_pt.
x - end_pt.
x)) {
int HorizontalDistance(bool debug, int x1, int x2, int y) const
void DenormTransform(const DENORM *last_denorm, const TPOINT &pt, TPOINT *original) const
int y_gap(const TBOX &box) const
int x_gap(const TBOX &box) const
int VerticalDistance(bool debug, int x, int y1, int y2) const
const int kParaPerpDistRatio
◆ DistanceOfBoxFromPartition()
int tesseract::TextlineProjection::DistanceOfBoxFromPartition |
( |
const TBOX & |
box, |
|
|
const ColPartition & |
part, |
|
|
const DENORM * |
denorm, |
|
|
bool |
debug |
|
) |
| const |
Definition at line 158 of file textlineprojection.cpp.
164 TBOX part_box = part.bounding_box();
165 if (part.IsHorizontalType()) {
166 part_box.
set_top(part.median_top());
169 part_box.
set_left(part.median_left());
int DistanceOfBoxFromBox(const TBOX &from_box, const TBOX &to_box, bool horizontal_textline, const DENORM *denorm, bool debug) const
◆ EvaluateBox()
int tesseract::TextlineProjection::EvaluateBox |
( |
const TBOX & |
box, |
|
|
const DENORM * |
denorm, |
|
|
bool |
debug |
|
) |
| const |
Definition at line 414 of file textlineprojection.cpp.
416 return EvaluateBoxInternal(box, denorm, debug, NULL, NULL, NULL, NULL);
◆ EvaluateColPartition()
int tesseract::TextlineProjection::EvaluateColPartition |
( |
const ColPartition & |
part, |
|
|
const DENORM * |
denorm, |
|
|
bool |
debug |
|
) |
| const |
Definition at line 363 of file textlineprojection.cpp.
366 if (part.IsSingleton())
367 return EvaluateBox(part.bounding_box(), denorm, debug);
369 TBOX box = part.bounding_box();
376 box = part.bounding_box();
378 box.
set_top(part.median_top());
382 tprintf(
"Partition hresult=%d, vresult=%d from:", hresult, vresult);
383 part.bounding_box().print();
386 return hresult >= -vresult ? hresult : vresult;
int EvaluateBox(const TBOX &box, const DENORM *denorm, bool debug) const
◆ HorizontalDistance()
int tesseract::TextlineProjection::HorizontalDistance |
( |
bool |
debug, |
|
|
int |
x1, |
|
|
int |
x2, |
|
|
int |
y |
|
) |
| const |
Definition at line 310 of file textlineprojection.cpp.
312 x1 = ImageXToProjectionX(x1);
313 x2 = ImageXToProjectionX(x2);
314 y = ImageYToProjectionY(y);
315 if (x1 == x2)
return 0;
316 int wpl = pixGetWpl(pix_);
317 int step = x1 < x2 ? 1 : -1;
318 uinT32* data = pixGetData(pix_) + y * wpl;
319 int prev_pixel = GET_DATA_BYTE(data, x1);
321 int right_way_steps = 0;
322 for (
int x = x1; x != x2; x += step) {
323 int pixel = GET_DATA_BYTE(data, x + step);
325 tprintf(
"At (%d,%d), pix = %d, prev=%d\n",
326 x + step, y, pixel, prev_pixel);
327 if (pixel < prev_pixel)
329 else if (pixel > prev_pixel)
335 return distance * scale_factor_ +
const int kWrongWayPenalty
◆ MoveNonTextlineBlobs()
void tesseract::TextlineProjection::MoveNonTextlineBlobs |
( |
BLOBNBOX_LIST * |
blobs, |
|
|
BLOBNBOX_LIST * |
small_blobs |
|
) |
| const |
Definition at line 104 of file textlineprojection.cpp.
106 BLOBNBOX_IT it(blobs);
107 BLOBNBOX_IT small_it(small_blobs);
108 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
115 small_it.add_to_end(it.extract());
const TBOX & bounding_box() const
bool UniquelyVertical() const
static bool WithinTestRegion(int detail_level, int x, int y)
bool BoxOutOfHTextline(const TBOX &box, const DENORM *denorm, bool debug) const
◆ PlotGradedBlobs()
void tesseract::TextlineProjection::PlotGradedBlobs |
( |
BLOBNBOX_LIST * |
blobs, |
|
|
ScrollView * |
win |
|
) |
| |
Definition at line 82 of file textlineprojection.cpp.
84 #ifndef GRAPHICS_DISABLED 85 BLOBNBOX_IT it(blobs);
86 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
97 #endif // GRAPHICS_DISABLED const TBOX & bounding_box() const
bool UniquelyVertical() const
void Rectangle(int x1, int y1, int x2, int y2)
bool BoxOutOfHTextline(const TBOX &box, const DENORM *denorm, bool debug) const
◆ VerticalDistance()
int tesseract::TextlineProjection::VerticalDistance |
( |
bool |
debug, |
|
|
int |
x, |
|
|
int |
y1, |
|
|
int |
y2 |
|
) |
| const |
Definition at line 277 of file textlineprojection.cpp.
279 x = ImageXToProjectionX(x);
280 y1 = ImageYToProjectionY(y1);
281 y2 = ImageYToProjectionY(y2);
282 if (y1 == y2)
return 0;
283 int wpl = pixGetWpl(pix_);
284 int step = y1 < y2 ? 1 : -1;
285 uinT32* data = pixGetData(pix_) + y1 * wpl;
287 int prev_pixel = GET_DATA_BYTE(data, x);
289 int right_way_steps = 0;
290 for (
int y = y1; y != y2; y += step) {
292 int pixel = GET_DATA_BYTE(data, x);
294 tprintf(
"At (%d,%d), pix = %d, prev=%d\n",
295 x, y + step, pixel, prev_pixel);
296 if (pixel < prev_pixel)
298 else if (pixel > prev_pixel)
304 return distance * scale_factor_ +
const int kWrongWayPenalty
The documentation for this class was generated from the following files: