Skip to content

Commit

Permalink
Use deskew lib
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed May 21, 2019
1 parent 11287cb commit dd30b55
Show file tree
Hide file tree
Showing 17 changed files with 19 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- run:
name: Init Docker volumes
command: |
docker run --rm --detach --name volumes --volume=tests:/tests --volume=results:/results alpine sleep 9999
docker run --rm --detach --name volumes --volume=tests:/tests --volume=results:/results alpine tail -f /dev/null
docker cp tests/ volumes:/tests/
when: always
- run:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends \
python3-pip python3-setuptools && \
python3 -m pip install PyYaml numpy scipy scikit-image opencv-python-headless && \
python3 -m pip install PyYaml numpy scipy scikit-image opencv-python-headless deskew && \
DEBIAN_FRONTEND=noninteractive apt-get auto-remove --assume-yes python3-pip python3-setuptools && \
apt-get clean && \
rm --recursive --force /var/lib/apt/lists/* /root/.cache /var/cache/*
Expand Down
21 changes: 5 additions & 16 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,12 @@ python_version = 3.6

disallow_untyped_calls = False

disallow_untyped_defs=True
check_untyped_defs=True
disallow_untyped_defs = True
check_untyped_defs = True
strict_optional = True

warn_no_return = True
warn_redundant_casts=True
warn_unused_ignores=True
warn_unused_configs=True

[mypy-numpy.*]
ignore_missing_imports = True

[mypy-scipy.*]
ignore_missing_imports = True

[mypy-skimage.*]
ignore_missing_imports = True

[mypy-cv2.*]
warn_redundant_casts = True
warn_unused_ignores = True
warn_unused_configs = True
ignore_missing_imports = True
22 changes: 9 additions & 13 deletions process
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ import traceback
from typing import cast, List, Dict, Any, Tuple, Union, Optional, Callable
import yaml
from skimage.measure import compare_ssim
from skimage.color import rgb2gray
import numpy as np
# read, write, rotate, crop, sharpen, draw_line, find_line, find_contour
import cv2
from scipy.signal import find_peaks
from deskew import determine_skew


# dither, crop, append, repage
CONVERT = ['gm', 'convert']


Expand Down Expand Up @@ -300,16 +304,8 @@ def level(context: Context, config: Dict[str, Any]) -> np.ndarray:
@Process('deskew')
def deskew(context: Context) -> None:
image = context.get_masked()
contours = find_contours(image, 200)
if contours:
x, y, width, height = get_contour_to_crop(contours)
image = crop_image(image, x, y, width, height, (255, 255, 255))
source = tempfile.NamedTemporaryFile(suffix='.png')
cv2.imwrite(source.name, image)
out = output(['/opt/Deskew/Bin/deskew', source.name]).split('\n')
text = 'Skew angle found [deg]: '
out = [e for e in out if e.startswith(text)]
angle = float(out[0][len(text):])
grayscale = rgb2gray(image)
angle = determine_skew(grayscale)
context.rotate(angle)


Expand Down Expand Up @@ -583,7 +579,7 @@ def transform(
autorotate(context)

# Is empty ?
contours = find_contours(context.get_masked())
contours = find_contours(context.get_masked(), 70)
if not contours:
print("Ignore image with no content: {}".format(img))
continue
Expand Down Expand Up @@ -728,8 +724,8 @@ def split(config: Dict[str, Any], step: Dict[str, Any], root_folder: str) -> Dic
page_pos = 0

save(root_folder, img2, '{}-split'.format(context.get_process_count()))
marging_horizontal = 10
maring_vertical = 7
marging_horizontal = 9
maring_vertical = 6
context.image = cv2.imread(img2)
crop(
context,
Expand Down
Binary file modified tests/all-1.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/all-2.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/assisted-split-contour-1.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/assisted-split-contour-3.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/assisted-split-contour-4.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/assisted-split-contour-5.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/assisted-split-join-1.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/assisted-split-join-2.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/assisted-split-lines-1.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/assisted-split-lines-3.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/assisted-split-lines-4.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/assisted-split-lines-5.expected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ def init_test():
# @pytest.mark.skip(reason='for test')
@pytest.mark.parametrize('type_,limit', [
('lines', {
'name': 'VL0',
'name': 'VL1',
'type': 'line detection',
'value': 1804,
'value': 1812,
'vertical': True,
'margin': 0
}),
('contour', {
'name': 'VC0',
'type': 'contour detection',
'value': 1581,
'value': 1617,
'vertical': True,
'margin': 0
})
Expand Down

0 comments on commit dd30b55

Please sign in to comment.