wait_space(image, title="Output") -> None
Arguments:
image
: image to showtitle
: frame title
Returns:
show image until space press
visual-data-extractor module
ocr module - extract text from images
SPDX-License-Identifier: GPLv3-or-later
Copyright © 2020 Or Toledano
extract_text.py: extract text from preprocessed images
from_roi(roi)
Arguments:
roi
: grayscale rectangular cut with text
Returns:
write_data module - format and write extracted data
roi module - detect relevant quads and preprocess them before ocr
SPDX-License-Identifier: GPLv3-or-later
Copyright © 2020 Or Toledano
rectification.py: warp perspective of quads to rectangles
sort_y(p0, p1) -> list
Arguments:
p0
: first pointp1
: second point
Returns:
[minarg_{p0, p1}(p.y), maxarg_{p0, p1}(p.y)]
sort_quad(quad: ndarray) -> ndarray
Arguments:
quad
: four points
Returns:
four points, starting from the top left, counter clockwise (positive orientation)
tup(arr: ndarray) -> tuple
Arguments:
arr
: 1d array
Returns:
tuple version of the ndarray
rect_angle(rotated_rect)
Arguments:
rotated_rect
: minRectArea output :return the angle that is required to rotate the rotated_rect back
centroid(contour: ndarray) -> Tuple[int, int]
Arguments:
contour
: contour
Returns:
centroid of the contour
rectified_roi(image: ndarray, quad: ndarray) -> ndarray
Arguments:
image
: base image of the contourquad
: contour to rectify
Returns:
a cropped ROI for the rectified quad
rectified_roi_manual_roll(image: ndarray, quad: ndarray, rect: ndarray, roll: int = 0) -> ndarray
Arguments:
image
: base image of the contourquad
: contour to rectifyroll
: TODO: figure out why aligned_box needs roll sometimes roll is in range(4), like a 90 degree fix for the boxrect
: pre computed minAreaRect
Returns:
a cropped ROI for the rectified quad, but u
rectified_roi_worst(image: ndarray, quad: ndarray, rect: ndarray) -> ndarray
Arguments:
image
: base image of the contourquad
: contour to rectifyrect
: pre computed minAreaRect
Returns:
a cropped ROI for the rectified quad
rectified_roi_good_no_rotate(image: ndarray, quad: ndarray, rect: ndarray) -> ndarray
Arguments:
image
: base image of the contourquad
: contour to rectifyrect
: pre computed minAreaRect
Returns:
a cropped ROI for the rectified quad IMPORTANT NOTE: the ROI is warped to a plane, but not rotated yet!
SPDX-License-Identifier: GPLv3-or-later
Copyright © 2020 Or Toledano
quad_detection.py: detect quads
get_quads_approx_poly(gray, area_thresh=999, rect_thresh=.6, epsilon=.025) -> List[Tuple[ndarray, ndarray]]
not so robust, approxPolyDP implementation - see get_quads_hough_lines
Arguments:
area_thresh
: area threshold for chosen quadsgray
: grayscale imagerect_thresh
: threshold for bounding-rect-like-area score e.i. quads with area/bounding rect area ratio greater than the threshold will be considered "good" for further processingepsilon
: epsilon*perimeter -> approxPolyDP's epsilon
Returns:
List[(quad, minRectArea around the quad)]
get_quads_hough_lines() -> List[Tuple[ndarray, ndarray]]
More robust than approxPolyDP
Returns:
quads
SPDX-License-Identifier: GPLv3-or-later
Copyright © 2020 Or Toledano
quad_detection.py: detect quads
resize(image, width, inter=cv.INTER_AREA) -> Tuple[ndarray, float]
Arguments:
image
: imagewidth
: output widthinter
: interpolation method, INTER_AREA by default
Returns:
(resized image, input/output ratio)
get_quads_approx_poly(gray, resize_width=250, area_thresh=999, rect_thresh=.5) -> List[Tuple[ndarray, ndarray]]
not so robust, approxPolyDP implementation - see get_quads_hough_lines
Arguments:
resize_width
: smaller width for intermediate calculationsarea_thresh
: area threshold for chosen quadsgray
: grayscale imagerect_thresh
: threshold for bounding-rect-like-area score e.i. quads with area/bounding rect area ratio greater than the threshold will be considered "good" for further processing
Returns:
quads
get_quads_hough_lines()
More robust than approxPolyDP
Returns:
SPDX-License-Identifier: GPLv3-or-later
Copyright © 2020 Or Toledano
extract.py: user frontend for the module
extract_data(image_path, rotate=False) -> List[str]
Arguments:
image_path
: image_pathrotate
: try all rotations+rolls
Returns:
all texts extracted (including garbage)
extract_data_once(image, roll) -> List[str]
Arguments:
image
: imageroll
: roll so we can try all rolls
Returns:
all texts extracted (including garbage)