Skip to content

Latest commit

 

History

History
368 lines (229 loc) · 7.12 KB

api-documentation.md

File metadata and controls

368 lines (229 loc) · 7.12 KB

better_imshow

better_imshow.better_imshow

wait_space

wait_space(image, title="Output") -> None

Arguments:

  • image: image to show
  • title: frame title

Returns:

show image until space press

visualextract

visual-data-extractor module

visualextract.ocr

ocr module - extract text from images

visualextract.ocr.extract_text

SPDX-License-Identifier: GPLv3-or-later

Copyright © 2020 Or Toledano

extract_text.py: extract text from preprocessed images

from_roi

from_roi(roi)

Arguments:

  • roi: grayscale rectangular cut with text

Returns:

visualextract.__main__

visualextract.write_data

write_data module - format and write extracted data

visualextract.roi

roi module - detect relevant quads and preprocess them before ocr

visualextract.roi.rectification

SPDX-License-Identifier: GPLv3-or-later

Copyright © 2020 Or Toledano

rectification.py: warp perspective of quads to rectangles

sort_y

sort_y(p0, p1) -> list

Arguments:

  • p0: first point
  • p1: second point

Returns:

[minarg_{p0, p1}(p.y), maxarg_{p0, p1}(p.y)]

sort_quad

sort_quad(quad: ndarray) -> ndarray

Arguments:

  • quad: four points

Returns:

four points, starting from the top left, counter clockwise (positive orientation)

tup

tup(arr: ndarray) -> tuple

Arguments:

  • arr: 1d array

Returns:

tuple version of the ndarray

rect_angle

rect_angle(rotated_rect)

Arguments:

  • rotated_rect: minRectArea output :return the angle that is required to rotate the rotated_rect back

centroid

centroid(contour: ndarray) -> Tuple[int, int]

Arguments:

  • contour: contour

Returns:

centroid of the contour

rectified_roi

rectified_roi(image: ndarray, quad: ndarray) -> ndarray

Arguments:

  • image: base image of the contour
  • quad: contour to rectify

Returns:

a cropped ROI for the rectified quad

rectified_roi_manual_roll

rectified_roi_manual_roll(image: ndarray, quad: ndarray, rect: ndarray, roll: int = 0) -> ndarray

Arguments:

  • image: base image of the contour
  • quad: contour to rectify
  • roll: TODO: figure out why aligned_box needs roll sometimes roll is in range(4), like a 90 degree fix for the box
  • rect: pre computed minAreaRect

Returns:

a cropped ROI for the rectified quad, but u

rectified_roi_worst

rectified_roi_worst(image: ndarray, quad: ndarray, rect: ndarray) -> ndarray

Arguments:

  • image: base image of the contour
  • quad: contour to rectify
  • rect: pre computed minAreaRect

Returns:

a cropped ROI for the rectified quad

rectified_roi_good_no_rotate

rectified_roi_good_no_rotate(image: ndarray, quad: ndarray, rect: ndarray) -> ndarray

Arguments:

  • image: base image of the contour
  • quad: contour to rectify
  • rect: pre computed minAreaRect

Returns:

a cropped ROI for the rectified quad IMPORTANT NOTE: the ROI is warped to a plane, but not rotated yet!

visualextract.roi.quad_detection

SPDX-License-Identifier: GPLv3-or-later

Copyright © 2020 Or Toledano

quad_detection.py: detect quads

get_quads_approx_poly

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 quads
  • gray: grayscale image
  • rect_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
  • epsilon: epsilon*perimeter -> approxPolyDP's epsilon

Returns:

List[(quad, minRectArea around the quad)]

get_quads_hough_lines

get_quads_hough_lines() -> List[Tuple[ndarray, ndarray]]

More robust than approxPolyDP

Returns:

quads

visualextract.roi.edges

SPDX-License-Identifier: GPLv3-or-later

Copyright © 2020 Or Toledano

quad_detection.py: detect quads

resize

resize(image, width, inter=cv.INTER_AREA) -> Tuple[ndarray, float]

Arguments:

  • image: image
  • width: output width
  • inter: interpolation method, INTER_AREA by default

Returns:

(resized image, input/output ratio)

get_quads_approx_poly

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 calculations
  • area_thresh: area threshold for chosen quads
  • gray: grayscale image
  • rect_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

get_quads_hough_lines()

More robust than approxPolyDP

Returns:

visualextract.extract

SPDX-License-Identifier: GPLv3-or-later

Copyright © 2020 Or Toledano

extract.py: user frontend for the module

extract_data

extract_data(image_path, rotate=False) -> List[str]

Arguments:

  • image_path: image_path
  • rotate: try all rotations+rolls

Returns:

all texts extracted (including garbage)

extract_data_once

extract_data_once(image, roll) -> List[str]

Arguments:

  • image: image
  • roll: roll so we can try all rolls

Returns:

all texts extracted (including garbage)