Leptonica 1.54
|
#define DEBUG_SHORT_LINES 0 |
#define DEBUG_TEXTLINE_CENTERS 0 |
Input: dew pixs (image to be modified; can be 1, 8 or 32 bpp) debugflag Return: 0 if OK, 1 on error
Notes: (1) This applies the vertical disparity array to the specified image. For src pixels above the image, we use the pixels in the first raster line. (2) This works with stripped models. If the full resolution disparity array(s) are missing, they are remade.
Input: dew debugflag (1 for debugging output) Return: 0 if OK, 1 on error
Notes: (1) This is the basic function that builds the vertical disparity array, which allows determination of the src pixel in the input image corresponding to each dest pixel in the dewarped image. (2) The method is as follows: * Estimate the centers of all the long textlines and fit a LS quadratic to each one. This smooths the curves. * Sample each curve at a regular interval, find the y-value of the flat point on each curve, and subtract the sampled curve value from this value. This is the vertical disparity. * 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. * Interpolate this grid to get a full resolution disparity map. This can be applied directly to the src image pixels to dewarp the image in the vertical direction, making all textlines horizontal.
L_DEWARP* dewarpCreate | ( | PIX * | pixs, |
l_int32 | pageno, | ||
l_int32 | sampling, | ||
l_int32 | minlines, | ||
l_int32 | applyhoriz | ||
) |
Input: pixs (1 bpp) pageno (page number) sampling (use -1 or 0 for default value; otherwise minimum of 5) minlines (minimum number of lines to accept; e.g., 10) applyhoriz (1 to estimate horiz disparity; 0 to skip) Return: dew (or null on error)
Notes: (1) The page number is typically 0-based. If scanned from a book, the even pages are usually on the left. Disparity arrays built for even pages should only be applied to even pages. (2) The sampling factor is for the disparity array. The number used is not critical; anything between 10 and 60 should be fine. (3) The minimum number of nearly full-length lines required to generate a vertical disparity array. Use a small number if you are willing to accept a questionable array.
void dewarpDestroy | ( | L_DEWARP ** | pdew | ) |
Input: &dew (<will be="" set="" to="" null="" before="" returning>="">) Return: void
Input: dew Return: 0 if OK, 1 on error
Notes: (1) This removes all data that is not needed for serialization. It keeps the subsampled disparity array(s), so the full resolution arrays can be reconstructed.
Input: dew Return: 0 if OK, 1 on error
Notes: (1) If the full resolution vertical (and, optionally horizontal) disparity arrays do not exist, they are built from the subsampled ones.
L_DEWARP* dewarpRead | ( | const char * | filename | ) |
Input: filename Return: dew, or null on error
L_DEWARP* dewarpReadStream | ( | FILE * | fp | ) |
Input: stream Return: dew, or null on error
Notes: (1) The dewarp struct is stored in minimized format, with only subsampled disparity arrays.
Input: filename dew Return: 0 if OK, 1 on error
Input: stream (opened for "wb") dew Return: 0 if OK, 1 on error
fpixBuildHorizontalDisparity()
Input: fpixv (vertical disparity model) factor (conversion factor for vertical disparity slope; use 0 for default) &extraw (<return> extra width to be added to dewarped pix) Return: fpixh, or null on error
Notes: (1) This takes the difference in vertical disparity at top and bottom of the image, and converts it to an assumed horizontal disparity.
Input: fpixs (full resolution disparity model) sampling (sampling factor) Return: fpixd (sampled disparity model), or null on error
Notes: (1) The input array is sampled at the right and top edges, and at every pixels horizontally and vertically. (2) The sampled array is constructed large enough to (a) cover fpixs and (b) have the sampled grid on all boundary pixels in fpixd. Having sampled pixels around the boundary simplifies interpolation. (3) There must be at least 3 sampled points horizontally and vertically.
Input: pixs (1, 8 or 32 bpp) fpix (horizontal disparity array) extraw (extra width added to pixd) Return: pixd (modified by fpix), or null on error
Notes: (1) This applies the horizontal disparity array to the specified image.
Input: pixs (1, 8 or 32 bpp) fpix (vertical disparity array) Return: pixd (modified by fpix), or null on error
Notes: (1) This applies the vertical disparity array to the specified image. For src pixels above the image, we use the pixels in the first raster line.
ptaGetMeanVerticals()
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)
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.
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
const l_float32 DEFAULT_SLOPE_FACTOR = 2000. [static] |
const l_int32 L_DEFAULT_SAMPLING = 30 [static] |