Leptonica
1.54
|
#define DEBUG_SHORT_LINES 0 /* ditto */ |
#define DEBUG_TEXTLINE_CENTERS 0 /* set this to 1 for debuging */ |
l_int32 dewarpaModelStatus | ( | L_DEWARPA * | dewa, |
l_int32 | pageno, | ||
l_int32 * | pvsuccess, | ||
l_int32 * | phsuccess | ||
) |
Input: dewa pageno &vsuccess (<optional return>=""> 1 on success) &hsuccess (<optional return>=""> 1 on success) Return: 0 if OK, 1 on error
Notes: (1) This tests if a model has been built, not if it is valid.
l_int32 dewarpBuildLineModel | ( | L_DEWARP * | dew, |
l_int32 | opensize, | ||
const char * | debugfile | ||
) |
Input: dew opensize (size of opening to remove perpendicular lines) debugfile (use null to skip writing this) Return: 0 if OK, 1 if unable to build the model or on error
Notes: (1) This builds the horizontal and vertical disparity arrays for an input of ruled lines, typically for calibration. In book scanning, you could lay the ruled paper over a page. Then for that page and several below it, you can use the disparity correction of the line model to dewarp the pages. (2) The dew has been initialized with the image of ruled lines. These lines must be continuous, but we do a small amount of pre-processing here to insure that. (3) is typically about 8. It must be larger than the thickness of the lines to be extracted. This is the default value, which is applied if < 3. (4) Sets vsuccess = 1 and hsuccess = 1 if the vertical and/or horizontal disparity arrays build. (5) Similar to dewarpBuildPageModel(), except here the vertical and horizontal disparity arrays are both built from ruled lines. See notes there.
l_int32 dewarpBuildPageModel | ( | L_DEWARP * | dew, |
const char * | debugfile | ||
) |
Input: dew debugfile (use null to skip writing this) Return: 0 if OK, 1 if unable to build the model or on error
Notes: (1) This is the basic function that builds the horizontal and vertical disparity arrays, which allow determination of the src pixel in the input image corresponding to each dest pixel in the dewarped image. (2) Sets vsuccess = 1 if the vertical disparity array builds. Always attempts to build the horizontal disparity array, even if it will not be requested (useboth == 0). Sets hsuccess = 1 if horizontal disparity builds. (3) The method is as follows: (a) Estimate the points along the centers of all the long textlines. If there are too few lines, no disparity models are built. (b) From the vertical deviation of the lines, estimate the vertical disparity. (c) From the ends of the lines, estimate the horizontal disparity, assuming that the text is made of lines that are left and right justified. (d) One can also compute an additional contribution to the horizontal disparity, inferred from slopes of the top and bottom lines. We do not do this. (4) In more detail for the vertical disparity: (a) Fit a LS quadratic to center locations along each line. This smooths the curves. (b) Sample each curve at a regular interval, find the y-value of the mid-point on each curve, and subtract the sampled curve value from this value. This is the vertical disparity at sampled points along each curve. (c) Fit a LS quadratic to each set of vertically aligned disparity samples. This smooths the disparity values in the vertical direction. Then resample at the same regular interval. We now have a regular grid of smoothed vertical disparity valuels. (5) Once the sampled vertical disparity array is found, it can be interpolated to get a full resolution vertical disparity map. This can be applied directly to the src image pixels to dewarp the image in the vertical direction, making all textlines horizontal. Likewise, the horizontal disparity array is used to left- and right-align the longest textlines.
l_int32 dewarpFindHorizDisparity | ( | L_DEWARP * | dew, |
PTAA * | ptaa | ||
) |
Input: dew ptaa (unsmoothed lines, not vertically ordered) Return: 0 if OK, 1 if vertical disparity array is no built or on error
(1) This is not required for a successful model; only the vertical disparity is required. This will not be called if the function to build the vertical disparity fails. (2) Debug output goes to /tmp/lept/dewmod/ for collection into a pdf.
static l_int32 dewarpFindLongLines | ( | PTA * | ptal, |
PTA * | ptar, | ||
l_float32 | minfract, | ||
PTA ** | pptald, | ||
PTA ** | pptard | ||
) | [static] |
Input: ptal (left end points of lines) ptar (right end points of lines) minfract (minimum allowed fraction of longest line) &ptald (<return> left end points of longest lines) &ptard (<return> right end points of longest lines) Return: 0 if OK, 1 on error or if there aren't enough long lines
Notes: (1) We do the following: (a) Sort the lines from top to bottom, and divide equally into Top and Bottom sets. (b) For each set, select the lines that are at least of the length of the longest line in the set. Typically choose around 0.95. (c) Accumulate the left and right end points from both sets into the two returned ptas.
l_int32 dewarpFindVertDisparity | ( | L_DEWARP * | dew, |
PTAA * | ptaa, | ||
l_int32 | rotflag | ||
) |
Input: dew ptaa (unsmoothed lines, not vertically ordered) rotflag (0 if using dew->pixs; 1 if rotated by 90 degrees cw) Return: 0 if OK, 1 on error
Notes: (1) This starts with points along the centers of textlines. It does quadratic fitting (and smoothing), first along the lines and then in the vertical direction, to generate the sampled vertical disparity map. This can then be interpolated to full resolution and used to remove the vertical line warping. (2) Use == 1 if you are dewarping vertical lines, as is done in dewarpBuildLineModel(). The usual case is for == 0. (3) The model fails to build if the vertical disparity fails. This sets the vsuccess flag to 1 on success. (4) Pix debug output goes to /tmp/dewvert/ for collection into a pdf. Non-pix debug output goes to /tmp.
static l_int32 dewarpGetLineEndpoints | ( | l_int32 | h, |
PTAA * | ptaa, | ||
PTA ** | pptal, | ||
PTA ** | pptar | ||
) | [static] |
Input: h (height of pixs) ptaa (lines) &ptal (<return> left end points of each line) &ptar (<return> right end points of each line) Return: 0 if OK, 1 on error.
Notes: (1) We require that the set of end points extends over 45% of the height of the input image, to insure good coverage and avoid extrapolating the curvature too far beyond the actual textlines. Large extrapolations are particularly dangerous if used as a reference model. (2) For fitting the endpoints, x = f(y), we transpose x and y. Thus all these ptas have x and y swapped!
static PTA * dewarpGetMeanVerticals | ( | PIX * | pixs, |
l_int32 | x, | ||
l_int32 | y | ||
) | [static] |
Input: pixs (1 bpp, single c.c.) x,y (location of UL corner of pixs with respect to page image Return: pta (mean y-values in component for each x-value, both translated by (x,y)
PTAA* dewarpGetTextlineCenters | ( | PIX * | pixs, |
l_int32 | debugflag | ||
) |
Input: pixs (1 bpp) debugflag (1 for debug output) Return: ptaa (of center values of textlines)
Notes: (1) This in general does not have a point for each value of x, because there will be gaps between words. It doesn't matter because we will fit a quadratic to the points that we do have.
static l_int32 dewarpIsLineCoverageValid | ( | PTAA * | ptaa, |
l_int32 | h, | ||
l_int32 * | ptopline, | ||
l_int32 * | pbotline | ||
) | [static] |
Input: ptaa (of validated lines) h (height of pix) &topline (<return> location of top line) &botline (<return> location of bottom line) Return: 1 if coverage is valid, 0 if not or on error.
Notes: (1) The criterion for valid coverage is: (a) there must be lines in both halves (top and bottom) of the image. (b) the coverage must be at least 40% of the image height
static l_int32 dewarpQuadraticLSF | ( | PTA * | ptad, |
l_float32 * | pa, | ||
l_float32 * | pb, | ||
l_float32 * | pc, | ||
l_float32 * | pmederr | ||
) | [static] |
Input: ptad (left or right end points of longest lines) &a (<return> coeff a of LSF: y = ax^2 + bx + c) &b (<return> coeff b of LSF: y = ax^2 + bx + c) &c (<return> coeff c of LSF: y = ax^2 + bx + c) &mederr (<optional return>=""> median error) Return: 0 if OK, 1 on error.
Notes: (1) This is used for finding the left or right sides of the text block, computed as a quadratic curve. Only the longest lines are input, so there are no outliers. (2) The ptas for the end points all have x and y swapped.
Input: pixs (1 bpp) ptaas (input lines) fract (minimum fraction of longest line to keep) debugflag Return: ptaad (containing only lines of sufficient length), or null on error
static l_int32 pixRenderHorizEndPoints | ( | PIX * | pixs, |
PTA * | ptal, | ||
PTA * | ptar, | ||
l_uint32 | color | ||
) | [static] |
Input: pixs (32 bpp) ptal (left side line end points) ptar (right side line end points) color (0xrrggbb00) Return: 0 if OK, 1 on error
static l_int32 pixRenderMidYs | ( | PIX * | pixs, |
NUMA * | namidys, | ||
l_int32 | linew | ||
) | [static] |
Input: pixs (32 bpp) namidys (y location of reference lines for vertical disparity) linew (width of rendered line; typ 2) Return: 0 if OK, 1 on error
const l_float32 MIN_RATIO_LINES_TO_HEIGHT = 0.45 [static] |