mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-06-08 02:12:40 +08:00
finished? doxygen ccstruct/coutln.cpp
This commit is contained in:
parent
b81c766e28
commit
40fc4154ab
@ -631,7 +631,7 @@ bool C_OUTLINE::IsLegallyNested() const {
|
|||||||
* On entry, *it must be an iterator pointing to this. If this gets deleted
|
* On entry, *it must be an iterator pointing to this. If this gets deleted
|
||||||
* then this is extracted from *it, so an iteration can continue.
|
* then this is extracted from *it, so an iteration can continue.
|
||||||
* @param min_size minimum size for outline
|
* @param min_size minimum size for outline
|
||||||
* @parm it outline iterator
|
* @param it outline iterator
|
||||||
*/
|
*/
|
||||||
void C_OUTLINE::RemoveSmallRecursive(int min_size, C_OUTLINE_IT* it) {
|
void C_OUTLINE::RemoveSmallRecursive(int min_size, C_OUTLINE_IT* it) {
|
||||||
if (box.width() < min_size || box.height() < min_size) {
|
if (box.width() < min_size || box.height() < min_size) {
|
||||||
@ -652,9 +652,11 @@ void C_OUTLINE::RemoveSmallRecursive(int min_size, C_OUTLINE_IT* it) {
|
|||||||
// on data from an 8-bit Pix, and assume that any input x and/or y are already
|
// on data from an 8-bit Pix, and assume that any input x and/or y are already
|
||||||
// constrained to be legal Pix coordinates.
|
// constrained to be legal Pix coordinates.
|
||||||
|
|
||||||
// Helper computes the local 2-D gradient (dx, dy) from the 2x2 cell centered
|
/**
|
||||||
// on the given (x,y). If the cell would go outside the image, it is padded
|
* Helper computes the local 2-D gradient (dx, dy) from the 2x2 cell centered
|
||||||
// with white.
|
* on the given (x,y). If the cell would go outside the image, it is padded
|
||||||
|
* with white.
|
||||||
|
*/
|
||||||
static void ComputeGradient(const l_uint32* data, int wpl,
|
static void ComputeGradient(const l_uint32* data, int wpl,
|
||||||
int x, int y, int width, int height,
|
int x, int y, int width, int height,
|
||||||
ICOORD* gradient) {
|
ICOORD* gradient) {
|
||||||
@ -671,9 +673,11 @@ static void ComputeGradient(const l_uint32* data, int wpl,
|
|||||||
gradient->set_y(pix_x_prevy + pix_prevx_prevy - (pix_x_y + pix_prevx_y));
|
gradient->set_y(pix_x_prevy + pix_prevx_prevy - (pix_x_y + pix_prevx_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper evaluates a vertical difference, (x,y) - (x,y-1), returning true if
|
/**
|
||||||
// the difference, matches diff_sign and updating the best_diff, best_sum,
|
* Helper evaluates a vertical difference, (x,y) - (x,y-1), returning true if
|
||||||
// best_y if a new max.
|
* the difference, matches diff_sign and updating the best_diff, best_sum,
|
||||||
|
* best_y if a new max.
|
||||||
|
*/
|
||||||
static bool EvaluateVerticalDiff(const l_uint32* data, int wpl, int diff_sign,
|
static bool EvaluateVerticalDiff(const l_uint32* data, int wpl, int diff_sign,
|
||||||
int x, int y, int height,
|
int x, int y, int height,
|
||||||
int* best_diff, int* best_sum, int* best_y) {
|
int* best_diff, int* best_sum, int* best_y) {
|
||||||
@ -691,9 +695,11 @@ static bool EvaluateVerticalDiff(const l_uint32* data, int wpl, int diff_sign,
|
|||||||
return diff > 0;
|
return diff > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper evaluates a horizontal difference, (x,y) - (x-1,y), where y is implied
|
/**
|
||||||
// by the input image line, returning true if the difference matches diff_sign
|
* Helper evaluates a horizontal difference, (x,y) - (x-1,y), where y is implied
|
||||||
// and updating the best_diff, best_sum, best_x if a new max.
|
* by the input image line, returning true if the difference matches diff_sign
|
||||||
|
* and updating the best_diff, best_sum, best_x if a new max.
|
||||||
|
*/
|
||||||
static bool EvaluateHorizontalDiff(const l_uint32* line, int diff_sign,
|
static bool EvaluateHorizontalDiff(const l_uint32* line, int diff_sign,
|
||||||
int x, int width,
|
int x, int width,
|
||||||
int* best_diff, int* best_sum, int* best_x) {
|
int* best_diff, int* best_sum, int* best_x) {
|
||||||
@ -710,17 +716,21 @@ static bool EvaluateHorizontalDiff(const l_uint32* line, int diff_sign,
|
|||||||
return diff > 0;
|
return diff > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds sub-pixel resolution EdgeOffsets for the outline if the supplied
|
/**
|
||||||
// pix is 8-bit. Does nothing otherwise.
|
* Adds sub-pixel resolution EdgeOffsets for the outline if the supplied
|
||||||
// Operation: Consider the following near-horizontal line:
|
* pix is 8-bit. Does nothing otherwise.
|
||||||
// _________
|
* Operation: Consider the following near-horizontal line:
|
||||||
// |________
|
* @verbatim
|
||||||
// |________
|
* _________
|
||||||
// At *every* position along this line, the gradient direction will be close
|
* |________
|
||||||
// to vertical. Extrapoaltion/interpolation of the position of the threshold
|
* |________
|
||||||
// that was used to binarize the image gives a more precise vertical position
|
* @endverbatim
|
||||||
// for each horizontal step, and the conflict in step direction and gradient
|
* At *every* position along this line, the gradient direction will be close
|
||||||
// direction can be used to ignore the vertical steps.
|
* to vertical. Extrapoaltion/interpolation of the position of the threshold
|
||||||
|
* that was used to binarize the image gives a more precise vertical position
|
||||||
|
* for each horizontal step, and the conflict in step direction and gradient
|
||||||
|
* direction can be used to ignore the vertical steps.
|
||||||
|
*/
|
||||||
void C_OUTLINE::ComputeEdgeOffsets(int threshold, Pix* pix) {
|
void C_OUTLINE::ComputeEdgeOffsets(int threshold, Pix* pix) {
|
||||||
if (pixGetDepth(pix) != 8) return;
|
if (pixGetDepth(pix) != 8) return;
|
||||||
const l_uint32* data = pixGetData(pix);
|
const l_uint32* data = pixGetData(pix);
|
||||||
@ -809,30 +819,35 @@ void C_OUTLINE::ComputeEdgeOffsets(int threshold, Pix* pix) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds sub-pixel resolution EdgeOffsets for the outline using only
|
/**
|
||||||
// a binary image source.
|
* Adds sub-pixel resolution EdgeOffsets for the outline using only
|
||||||
// Runs a sliding window of 5 edge steps over the outline, maintaining a count
|
* a binary image source.
|
||||||
// of the number of steps in each of the 4 directions in the window, and a
|
*
|
||||||
// sum of the x or y position of each step (as appropriate to its direction.)
|
* Runs a sliding window of 5 edge steps over the outline, maintaining a count
|
||||||
// Ignores single-count steps EXCEPT the sharp U-turn and smoothes out the
|
* of the number of steps in each of the 4 directions in the window, and a
|
||||||
// perpendicular direction. Eg
|
* sum of the x or y position of each step (as appropriate to its direction.)
|
||||||
// ___ ___ Chain code from the left:
|
* Ignores single-count steps EXCEPT the sharp U-turn and smoothes out the
|
||||||
// |___ ___ ___| 222122212223221232223000
|
* perpendicular direction. Eg
|
||||||
// |___| |_| Corresponding counts of each direction:
|
* @verbatim
|
||||||
// 0 00000000000000000123
|
* ___ ___ Chain code from the left:
|
||||||
// 1 11121111001111100000
|
* |___ ___ ___| 222122212223221232223000
|
||||||
// 2 44434443443333343321
|
* |___| |_| Corresponding counts of each direction:
|
||||||
// 3 00000001111111112111
|
* 0 00000000000000000123
|
||||||
// Count of direction at center 41434143413313143313
|
* 1 11121111001111100000
|
||||||
// Step gets used? YNYYYNYYYNYYNYNYYYyY (y= U-turn exception)
|
* 2 44434443443333343321
|
||||||
// Path redrawn showing only the used points:
|
* 3 00000001111111112111
|
||||||
// ___ ___
|
* Count of direction at center 41434143413313143313
|
||||||
// ___ ___ ___|
|
* Step gets used? YNYYYNYYYNYYNYNYYYyY (y= U-turn exception)
|
||||||
// ___ _
|
* Path redrawn showing only the used points:
|
||||||
// Sub-pixel edge position cannot be shown well with ASCII-art, but each
|
* ___ ___
|
||||||
// horizontal step's y position is the mean of the y positions of the steps
|
* ___ ___ ___|
|
||||||
// in the same direction in the sliding window, which makes a much smoother
|
* ___ _
|
||||||
// outline, without losing important detail.
|
* @endverbatim
|
||||||
|
* Sub-pixel edge position cannot be shown well with ASCII-art, but each
|
||||||
|
* horizontal step's y position is the mean of the y positions of the steps
|
||||||
|
* in the same direction in the sliding window, which makes a much smoother
|
||||||
|
* outline, without losing important detail.
|
||||||
|
*/
|
||||||
void C_OUTLINE::ComputeBinaryOffsets() {
|
void C_OUTLINE::ComputeBinaryOffsets() {
|
||||||
delete [] offsets;
|
delete [] offsets;
|
||||||
offsets = new EdgeOffset[stepcount];
|
offsets = new EdgeOffset[stepcount];
|
||||||
@ -887,8 +902,10 @@ void C_OUTLINE::ComputeBinaryOffsets() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renders the outline to the given pix, with left and top being
|
/**
|
||||||
// the coords of the upper-left corner of the pix.
|
* Renders the outline to the given pix, with left and top being
|
||||||
|
* the coords of the upper-left corner of the pix.
|
||||||
|
*/
|
||||||
void C_OUTLINE::render(int left, int top, Pix* pix) const {
|
void C_OUTLINE::render(int left, int top, Pix* pix) const {
|
||||||
ICOORD pos = start;
|
ICOORD pos = start;
|
||||||
for (int stepindex = 0; stepindex < stepcount; ++stepindex) {
|
for (int stepindex = 0; stepindex < stepcount; ++stepindex) {
|
||||||
@ -965,8 +982,11 @@ void C_OUTLINE::plot(ScrollView* window,
|
|||||||
window->DrawTo(pos.x(), pos.y());
|
window->DrawTo(pos.x(), pos.y());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Draws the outline in the given colour, normalized using the given denorm,
|
|
||||||
// making use of sub-pixel accurate information if available.
|
/**
|
||||||
|
* Draws the outline in the given colour, normalized using the given denorm,
|
||||||
|
* making use of sub-pixel accurate information if available.
|
||||||
|
*/
|
||||||
void C_OUTLINE::plot_normed(const DENORM& denorm, ScrollView::Color colour,
|
void C_OUTLINE::plot_normed(const DENORM& denorm, ScrollView::Color colour,
|
||||||
ScrollView* window) const {
|
ScrollView* window) const {
|
||||||
window->Pen(colour);
|
window->Pen(colour);
|
||||||
@ -1025,10 +1045,12 @@ C_OUTLINE & C_OUTLINE::operator= (const C_OUTLINE & source) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper for ComputeBinaryOffsets. Increments pos, dir_counts, pos_totals
|
/**
|
||||||
// by the step, increment, and vertical step ? x : y position * increment
|
* Helper for ComputeBinaryOffsets. Increments pos, dir_counts, pos_totals
|
||||||
// at step s Mod stepcount respectively. Used to add or subtract the
|
* by the step, increment, and vertical step ? x : y position * increment
|
||||||
// direction and position to/from accumulators of a small neighbourhood.
|
* at step s Mod stepcount respectively. Used to add or subtract the
|
||||||
|
* direction and position to/from accumulators of a small neighbourhood.
|
||||||
|
*/
|
||||||
void C_OUTLINE::increment_step(int s, int increment, ICOORD* pos,
|
void C_OUTLINE::increment_step(int s, int increment, ICOORD* pos,
|
||||||
int* dir_counts, int* pos_totals) const {
|
int* dir_counts, int* pos_totals) const {
|
||||||
int step_index = Modulo(s, stepcount);
|
int step_index = Modulo(s, stepcount);
|
||||||
|
Loading…
Reference in New Issue
Block a user