-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
PYTHON := $(shell which python) | ||
POETRY := $(PYTHON) -m poetry | ||
POETRY := poetry | ||
|
||
all : test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ | |
__email__ = "[email protected]" | ||
|
||
from pathlib import Path | ||
import typing as T | ||
import cv2 as cv | ||
import numpy as np | ||
import numpy.typing as npt | ||
|
||
import tempfile | ||
|
||
|
@@ -31,18 +33,21 @@ def heal(orig): | |
|
||
|
||
def remove_grid( | ||
orig, num_iter=3, background_color: int = 255, grid_size: int = 2 | ||
orig: npt.ArrayLike, | ||
num_iter: int = 3, | ||
background_color: T.Sequence[int] = (255, 255, 255), | ||
grid_size: int = 2, | ||
) -> np.ndarray: | ||
img = orig.copy() | ||
img = np.array(orig, copy=True) | ||
thres = cv.threshold(img, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1] | ||
# Remove horizontal lines | ||
horizontal_kernel = cv.getStructuringElement(cv.MORPH_RECT, (40, 1)) | ||
remove_horizontal = cv.morphologyEx( | ||
thres, cv.MORPH_OPEN, horizontal_kernel, iterations=num_iter | ||
) | ||
cnts = cv.findContours(remove_horizontal, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE) | ||
cnts = cnts[0] if len(cnts) == 2 else cnts[1] | ||
for c in cnts: | ||
contours = cnts[0] if len(cnts) == 2 else cnts[1] | ||
for c in contours: | ||
cv.drawContours(img, [c], -1, background_color, grid_size) | ||
|
||
# Remove vertical lines | ||
|
@@ -51,8 +56,8 @@ def remove_grid( | |
thres, cv.MORPH_OPEN, vertical_kernel, iterations=num_iter | ||
) | ||
cnts = cv.findContours(remove_vertical, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE) | ||
cnts = cnts[0] if len(cnts) == 2 else cnts[1] | ||
for c in cnts: | ||
contours = cnts[0] if len(cnts) == 2 else cnts[1] | ||
for c in contours: | ||
cv.drawContours(img, [c], -1, background_color, grid_size) | ||
return img | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.