#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.
| tesseract::TextlineProjection::TextlineProjection |
( |
int |
resolution | ) |
|
|
explicit |
Definition at line 41 of file textlineprojection.cpp.
42 : x_origin_(0), y_origin_(0), pix_(
NULL) {
45 if (scale_factor_ < 1) scale_factor_ = 1;
int IntCastRounded(double x)
| tesseract::TextlineProjection::~TextlineProjection |
( |
| ) |
|
| bool tesseract::TextlineProjection::BoxOutOfHTextline |
( |
const TBOX & |
box, |
|
|
const DENORM * |
denorm, |
|
|
bool |
debug |
|
) |
| const |
Definition at line 338 of file textlineprojection.cpp.
343 EvaluateBoxInternal(box, denorm, debug, &grad1, &grad2,
NULL,
NULL);
344 int worst_result =
MIN(grad1, grad2);
345 int total_result = grad1 + grad2;
346 if (total_result >= 6)
return false;
349 if (worst_result < 0)
| void tesseract::TextlineProjection::ConstructProjection |
( |
TO_BLOCK * |
input_block, |
|
|
const FCOORD & |
rotation, |
|
|
Pix * |
nontext_map |
|
) |
| |
Definition at line 58 of file textlineprojection.cpp.
62 TBOX image_box(0, 0, pixGetWidth(nontext_map), pixGetHeight(nontext_map));
64 y_origin_ = image_box.height();
65 int width = (image_box.width() + scale_factor_ - 1) / scale_factor_;
66 int height = (image_box.height() + scale_factor_ - 1) / scale_factor_;
68 pix_ = pixCreate(width, height, 8);
69 ProjectBlobs(&input_block->
blobs, rotation, image_box, nontext_map);
70 ProjectBlobs(&input_block->
large_blobs, rotation, image_box, nontext_map);
71 Pix* final_pix = pixBlockconv(pix_, 1, 1);
BLOBNBOX_LIST large_blobs
| void tesseract::TextlineProjection::DisplayProjection |
( |
| ) |
const |
Definition at line 117 of file textlineprojection.cpp.
118 int width = pixGetWidth(pix_);
119 int height = pixGetHeight(pix_);
120 Pix* pixc = pixCreate(width, height, 32);
121 int src_wpl = pixGetWpl(pix_);
122 int col_wpl = pixGetWpl(pixc);
123 uinT32* src_data = pixGetData(pix_);
124 uinT32* col_data = pixGetData(pixc);
125 for (
int y = 0; y < height; ++y, src_data += src_wpl, col_data += col_wpl) {
126 for (
int x = 0; x < width; ++x) {
127 int pixel = GET_DATA_BYTE(src_data, x);
130 composeRGBPixel(0, 0, pixel * 15, &result);
131 else if (pixel <= 145)
132 composeRGBPixel(0, (pixel - 17) * 2, 255, &result);
134 composeRGBPixel((pixel - 145) * 2, 255, 255, &result);
135 col_data[x] = result;
141 width, height, width, height);
142 win->
Image(pixc, 0, 0);
145 pixWrite(
"projection.png", pixc, IFF_PNG);
| int tesseract::TextlineProjection::DistanceOfBoxFromBox |
( |
const TBOX & |
from_box, |
|
|
const TBOX & |
to_box, |
|
|
bool |
horizontal_textline, |
|
|
const DENORM * |
denorm, |
|
|
bool |
debug |
|
) |
| const |
Definition at line 194 of file textlineprojection.cpp.
201 int parallel_gap = 0;
206 if (horizontal_textline) {
207 parallel_gap = from_box.
x_gap(to_box) + from_box.
width();
208 start_pt.
x = (from_box.
left() + from_box.
right()) / 2;
209 end_pt.
x = start_pt.
x;
211 start_pt.
y = from_box.
top();
212 end_pt.
y =
MIN(to_box.
top(), start_pt.
y);
214 start_pt.
y = from_box.
bottom();
218 parallel_gap = from_box.
y_gap(to_box) + from_box.
height();
220 start_pt.
x = from_box.
right();
223 start_pt.
x = from_box.
left();
224 end_pt.
x =
MAX(to_box.
left(), start_pt.
x);
226 start_pt.
y = (from_box.
bottom() + from_box.
top()) / 2;
227 end_pt.
y = start_pt.
y;
233 int perpendicular_gap = 0;
237 if (start_pt.
x != end_pt.
x || start_pt.
y != end_pt.
y) {
238 if (denorm !=
NULL) {
243 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
const int kParaPerpDistRatio
void DenormTransform(const TPOINT &pt, TPOINT *original) const
int VerticalDistance(bool debug, int x, int y1, int y2) const
int y_gap(const TBOX &box) const
int x_gap(const TBOX &box) const
| int tesseract::TextlineProjection::DistanceOfBoxFromPartition |
( |
const TBOX & |
box, |
|
|
const ColPartition & |
part, |
|
|
const DENORM * |
denorm, |
|
|
bool |
debug |
|
) |
| const |
Definition at line 154 of file textlineprojection.cpp.
160 TBOX part_box = part.bounding_box();
161 if (part.IsHorizontalType()) {
162 part_box.
set_top(part.median_top());
165 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
| int tesseract::TextlineProjection::EvaluateBox |
( |
const TBOX & |
box, |
|
|
const DENORM * |
denorm, |
|
|
bool |
debug |
|
) |
| const |
| int tesseract::TextlineProjection::EvaluateColPartition |
( |
const ColPartition & |
part, |
|
|
const DENORM * |
denorm, |
|
|
bool |
debug |
|
) |
| const |
Definition at line 359 of file textlineprojection.cpp.
362 if (part.IsSingleton())
363 return EvaluateBox(part.bounding_box(), denorm, debug);
365 TBOX box = part.bounding_box();
372 box = part.bounding_box();
374 box.
set_top(part.median_top());
378 tprintf(
"Partition hresult=%d, vresult=%d from:", hresult, vresult);
379 part.bounding_box().print();
382 return hresult >= -vresult ? hresult : vresult;
DLLSYM void tprintf(const char *format,...)
int EvaluateBox(const TBOX &box, const DENORM *denorm, bool debug) const
| int tesseract::TextlineProjection::HorizontalDistance |
( |
bool |
debug, |
|
|
int |
x1, |
|
|
int |
x2, |
|
|
int |
y |
|
) |
| const |
Definition at line 306 of file textlineprojection.cpp.
308 x1 = ImageXToProjectionX(x1);
309 x2 = ImageXToProjectionX(x2);
310 y = ImageYToProjectionY(y);
311 if (x1 == x2)
return 0;
312 int wpl = pixGetWpl(pix_);
313 int step = x1 < x2 ? 1 : -1;
314 uinT32* data = pixGetData(pix_) + y * wpl;
315 int prev_pixel = GET_DATA_BYTE(data, x1);
317 int right_way_steps = 0;
318 for (
int x = x1; x != x2; x += step) {
319 int pixel = GET_DATA_BYTE(data, x + step);
321 tprintf(
"At (%d,%d), pix = %d, prev=%d\n",
322 x + step, y, pixel, prev_pixel);
323 if (pixel < prev_pixel)
325 else if (pixel > prev_pixel)
331 return distance * scale_factor_ +
const int kWrongWayPenalty
DLLSYM void tprintf(const char *format,...)
| void tesseract::TextlineProjection::MoveNonTextlineBlobs |
( |
BLOBNBOX_LIST * |
blobs, |
|
|
BLOBNBOX_LIST * |
small_blobs |
|
) |
| const |
Definition at line 100 of file textlineprojection.cpp.
102 BLOBNBOX_IT it(blobs);
103 BLOBNBOX_IT small_it(small_blobs);
104 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
111 small_it.add_to_end(it.extract());
const TBOX & bounding_box() const
bool BoxOutOfHTextline(const TBOX &box, const DENORM *denorm, bool debug) const
static bool WithinTestRegion(int detail_level, int x, int y)
bool UniquelyVertical() const
| void tesseract::TextlineProjection::PlotGradedBlobs |
( |
BLOBNBOX_LIST * |
blobs, |
|
|
ScrollView * |
win |
|
) |
| |
Definition at line 78 of file textlineprojection.cpp.
80 #ifndef GRAPHICS_DISABLED
81 BLOBNBOX_IT it(blobs);
82 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
93 #endif // GRAPHICS_DISABLED
const TBOX & bounding_box() const
bool BoxOutOfHTextline(const TBOX &box, const DENORM *denorm, bool debug) const
bool UniquelyVertical() const
| int tesseract::TextlineProjection::VerticalDistance |
( |
bool |
debug, |
|
|
int |
x, |
|
|
int |
y1, |
|
|
int |
y2 |
|
) |
| const |
Definition at line 273 of file textlineprojection.cpp.
275 x = ImageXToProjectionX(x);
276 y1 = ImageYToProjectionY(y1);
277 y2 = ImageYToProjectionY(y2);
278 if (y1 == y2)
return 0;
279 int wpl = pixGetWpl(pix_);
280 int step = y1 < y2 ? 1 : -1;
281 uinT32* data = pixGetData(pix_) + y1 * wpl;
283 int prev_pixel = GET_DATA_BYTE(data, x);
285 int right_way_steps = 0;
286 for (
int y = y1; y != y2; y += step) {
288 int pixel = GET_DATA_BYTE(data, x);
290 tprintf(
"At (%d,%d), pix = %d, prev=%d\n",
291 x, y + step, pixel, prev_pixel);
292 if (pixel < prev_pixel)
294 else if (pixel > prev_pixel)
300 return distance * scale_factor_ +
const int kWrongWayPenalty
DLLSYM void tprintf(const char *format,...)
The documentation for this class was generated from the following files: