Skip to content

Commit

Permalink
Correct mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BryceStevenWilley committed Aug 15, 2023
1 parent eb58ec2 commit 4ebf930
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ dist/**
dev-testing/.DS_Store
.DS_Store
.env
.venv
venv
28 changes: 16 additions & 12 deletions formfyxer/pdf_wrangling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,14 +1103,16 @@ def get_possible_radios(img: Union[str, BinaryIO, cv2.Mat]):
doing any semantic analysis yet."""
if isinstance(img, str):
# 0 is for the flags: means nothing special is being used
img = cv2.imread(img, 0)
if isinstance(img, BinaryIO):
img = cv2.imdecode(np.frombuffer(img.read(), np.uint8), 0)
img_mat = cv2.imread(img, 0)
elif isinstance(img, BinaryIO):
img_mat = cv2.imdecode(np.frombuffer(img.read(), np.uint8), 0)
else:
img_mat = img

rows = img.shape[0]
rows = img_mat.shape[0]
# TODO(brycew): https://docs.opencv.org/3.4/d4/d70/tutorial_hough_circle.html
circles = cv2.HoughCircles(
img,
img_mat,
cv2.HOUGH_GRADIENT,
1,
rows / 8,
Expand All @@ -1124,10 +1126,10 @@ def get_possible_radios(img: Union[str, BinaryIO, cv2.Mat]):
for i in circles[0, :]:
center = (i[0], i[1])
# circle center
cv2.circle(img, center, 1, (0, 100, 100), 3)
cv2.circle(img_mat, center, 1, (0, 100, 100), 3)
# circle outline
radius = i[2]
cv2.circle(img, center, radius, (255, 0, 255), 3)
cv2.circle(img_mat, center, radius, (255, 0, 255), 3)

return []
# cv2.imshow("detected circles", img)
Expand All @@ -1151,17 +1153,19 @@ def get_possible_text_fields(
"""
if isinstance(img, str):
# 0 is for the flags: means nothing special is being used
img = cv2.imread(img, 0)
if isinstance(img, BinaryIO):
img = cv2.imdecode(np.frombuffer(img.read(), np.uint8), 0)
img_mat = cv2.imread(img, 0)
elif isinstance(img, BinaryIO):
img_mat = cv2.imdecode(np.frombuffer(img.read(), np.uint8), 0)
else:
img_mat = img

height, width = img.shape
height, width = img_mat.shape
# fixed level thresholding, turning a gray scale / multichannel img to a black and white one.
# OTSU = optimum global thresholding: minimizes the variance of each Thresh "class"
# for each possible thresh value between 128 and 255, split up pixels, get the within-class variance,
# and minimize that
(thresh, img_bin) = cv2.threshold(
img, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU
img_mat, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU
)

img_bin = 255 - img_bin
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ ignore_missing_imports=true

[[tool.mypy.overrides]]
module="transformers.*"
ignore_missing_imports=true

[[tool.mypy.overrides]]
module="eyecite.*"
ignore_missing_imports=true

0 comments on commit 4ebf930

Please sign in to comment.