Skip to content

Commit

Permalink
Adds tests for tilt correction functionality using parameterized angl…
Browse files Browse the repository at this point in the history
…es and image data.
  • Loading branch information
Paethon committed Oct 28, 2024
1 parent 7d06603 commit 2224367
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/test_tilt_correction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import os

import numpy as np
import pytest
from ocr_wrapper.tilt_correction import _closest_90_degree_distance, correct_tilt
from PIL import Image
from pytest import mark
from ocr_wrapper.tilt_correction import _closest_90_degree_distance

filedir = os.path.dirname(__file__)
DATA_DIR = os.path.join(filedir, "data")


@mark.parametrize(
Expand All @@ -25,3 +33,12 @@
)
def test_closest_90_degree_distance(angle, expected):
assert _closest_90_degree_distance(angle) == expected


@pytest.mark.parametrize("angle", np.linspace(0, 9, 15))
def test_correct_tilt(angle):
file = os.path.join(DATA_DIR, "mixed_arabic.jpg")
img = Image.open(file)
rotated_img = img.rotate(angle)
_, detected_angle = correct_tilt(rotated_img)
assert pytest.approx(abs(detected_angle), abs=0.1) == angle

0 comments on commit 2224367

Please sign in to comment.