Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes torch from ocr_wrapper #24

Merged
merged 11 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The version numbers are according to [Semantic Versioning](http://semver.org/).

## Release v0.0.x ()
### Added

- Added possibility to deactivate using torch by setting the environment variable `OCR_WRAPPER_NO_TORCH`. By default, torch is used. The main use case for this to decreate import times of the library. If torch is not used, numpy and SciPy are used instead. Be aware that tilt correction is around 5x slower without torch.
### Fixed

### Changed
Expand Down
191 changes: 131 additions & 60 deletions ocr_wrapper/bbox_order.py

Large diffs are not rendered by default.

332 changes: 13 additions & 319 deletions ocr_wrapper/tilt_correction.py

Large diffs are not rendered by default.

316 changes: 316 additions & 0 deletions ocr_wrapper/tilt_correction_numpy.py

Large diffs are not rendered by default.

328 changes: 328 additions & 0 deletions ocr_wrapper/tilt_correction_torch.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies = [
"torch",
"torchvision",
"numpy",
"scipy",
"opentelemetry-api",
"opentelemetry-sdk"
]
Expand Down
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
Loading