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

Rotate page #488

Merged
merged 66 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
1af0fc1
feat: integrate image rotation before using predictor
Rob192 Jul 19, 2021
811fd6a
Merge branch 'main' into rotate_page
Rob192 Jul 19, 2021
6f5c183
Merge branch 'main' into rotate_page
Rob192 Sep 21, 2021
c2b18d7
feat: add rotate_document functionality
Rob192 Sep 22, 2021
312179f
fix: remove min_angle from rotate_page
Rob192 Sep 22, 2021
b6bc74f
merge
Rob192 Sep 30, 2021
6fe1bc6
fix: correct models.predictor.tensorflow
Rob192 Sep 30, 2021
a6f2ff1
fix: minor corrections
Rob192 Oct 1, 2021
ccda4d0
feat: Rotate back images and boxes after straightening
Rob192 Oct 4, 2021
7d4ed75
fix: correct typo
Rob192 Oct 4, 2021
a303b23
fix: merge two functions rotate_image
Rob192 Oct 5, 2021
7a78263
fix: do not rotate back pages but only boxes
Rob192 Oct 5, 2021
eb341ac
fix: typos
Rob192 Oct 6, 2021
eeff2d6
fix: add more testing for remap_boxes in cases of boxes with an angle…
Rob192 Oct 6, 2021
16f3489
fix: remove the cropping after rotation of the image
Rob192 Oct 14, 2021
eb063f1
Merge branch 'main' of https://github.com/mindee/doctr
Rob192 Oct 25, 2021
b9ec27e
Merge branch 'main' into rotate_page
Rob192 Oct 25, 2021
f7fcf90
fix: correct model/_utils.py
Rob192 Oct 25, 2021
a04ab4f
Merge branch 'main' of https://github.com/mindee/doctr
Rob192 Oct 28, 2021
8ec9eab
Merge branch 'main' into rotate_page
Rob192 Oct 28, 2021
cf9ab0d
fix: do not use resolve_lines and resolve_boxes as it does not work w…
Rob192 Oct 28, 2021
8a31014
fix: remove expand in geometry.rotate_boxes
Rob192 Oct 29, 2021
e457cf0
fix: reformat code
Rob192 Oct 29, 2021
9975c82
fix: reformat expand from function signature
Rob192 Oct 29, 2021
32d53e4
fix: rename keep_original_size to preserve_aspect_ratio
Rob192 Oct 29, 2021
6821442
fix: vectorize box transformation
Rob192 Oct 29, 2021
988e2d0
Merge branch 'main' into rotate_page
Rob192 Nov 16, 2021
573f13f
fix: minor modifications + remove test_bbox_to_rbbox
Rob192 Nov 16, 2021
290e8ed
fix: add the straighten_pages to the latest codebase
Rob192 Nov 19, 2021
1775ebf
feat: add the straighten_pages to the pytorch predictor
Rob192 Nov 19, 2021
816168c
Merge branch 'main' into rotate_page
Rob192 Nov 19, 2021
f199044
feat: add testing for the straighten_pages parameter
Rob192 Nov 19, 2021
887ed25
fix: in case no angle is found in estimate_orientation return 0
Rob192 Nov 19, 2021
789a9c2
Merge branch 'main' into rotate_page
Rob192 Nov 24, 2021
239c508
fix: make sure boxes are outputted from _process_predictions
Rob192 Nov 24, 2021
52461dc
fix: update docstrings in OCRPredictor
Rob192 Nov 24, 2021
b6f8cca
fix: create a copy of boxes inside rotate_boxes
Rob192 Nov 24, 2021
a9f3d6e
fix: update docstring for rotate_image
Rob192 Nov 24, 2021
ea69de6
fix: add comments inside remap_boxes
Rob192 Nov 24, 2021
1a72a8c
fix: change testing in test_estimate_orientation
Rob192 Nov 24, 2021
d658be4
fix: change testing in test_estimate_orientation
Rob192 Nov 24, 2021
4711797
Merge branch 'main' into rotate_page
Rob192 Nov 25, 2021
e5ed562
Merge branch 'main' into rotate_page
Rob192 Nov 26, 2021
9a6c658
fix: delete imports not used
Rob192 Nov 29, 2021
a9cbe04
fix: styling
Rob192 Nov 29, 2021
ebdc320
fix: change assertion in test_utils_geometry.py
Rob192 Nov 30, 2021
d16fba3
fix: keep check with if expand in rotate_image
Rob192 Nov 30, 2021
e344e5c
fix: change rotate_boxes signature
Rob192 Nov 30, 2021
2e11dc8
fix: use loc_preds instead of boxes
Rob192 Nov 30, 2021
bb6bc79
fix: wrong test in remap boxes
Rob192 Nov 30, 2021
258b18b
Merge branch 'main' into rotate_page
Rob192 Nov 30, 2021
b22309d
add unit tests for pytorch
Rob192 Dec 1, 2021
495ad8c
add unit tests for remap_boxes and estimate_orientation
Rob192 Dec 1, 2021
98b44f6
fix: styling
Rob192 Dec 1, 2021
28f1fd8
fix: isort
Rob192 Dec 1, 2021
1d61de7
fix: remove unnecessary fixture
Rob192 Dec 1, 2021
faac0bd
fix: add testing for pytorch predictor
Rob192 Dec 2, 2021
938c9f2
fix: styling
Rob192 Dec 2, 2021
30a70f2
fix: correct testing for ocrpredictor with pytorch
Rob192 Dec 2, 2021
a7c0d55
fix: correct imports for testing
Rob192 Dec 2, 2021
ce23100
fix: isort
Rob192 Dec 2, 2021
8525b14
fix: make sure that expand in rotate_image is keeping the same image …
Rob192 Dec 3, 2021
7bcf639
fix: styling
Rob192 Dec 3, 2021
2205737
fix: use absolute centers for rotate_boxes
Rob192 Dec 5, 2021
484451b
fix: calculation of image_center and documentation
Rob192 Dec 5, 2021
66fad67
fix: remove default value for orig_shape in rotate_boxes
Rob192 Dec 5, 2021
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
Prev Previous commit
Next Next commit
fix: make sure that expand in rotate_image is keeping the same image …
…ratio
  • Loading branch information
Rob192 committed Dec 3, 2021
commit 8525b14471a8f9e426cdc04eb598e304cf50940f
23 changes: 11 additions & 12 deletions doctr/utils/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,8 @@ def rotate_image(
Args:
image: numpy tensor to rotate
angle: rotation angle in degrees, between -90 and +90
expand: whether the image should be padded before the rotation
preserve_origin_shape: whether the image should be resized to the original image size after the rotation.
Only useful if expand is True.
expand: whether the image should be padded before the rotation,
Rob192 marked this conversation as resolved.
Show resolved Hide resolved
preserve_origin_shape: if expand is set to True, resizes the final output to the original image size

Returns:
Rotated array, padded by 0 by default.
Expand All @@ -261,16 +260,16 @@ def rotate_image(
rot_mat = cv2.getRotationMatrix2D((width / 2, height / 2), angle, 1.0)
rot_img = cv2.warpAffine(exp_img, rot_mat, (width, height))
if expand:
# Pad to get the same aspect ratio
if (image.shape[0] / image.shape[1]) != (rot_img.shape[0] / rot_img.shape[1]):
# Pad width
if (rot_img.shape[0] / rot_img.shape[1]) > (image.shape[0] / image.shape[1]):
h_pad, w_pad = 0, int(rot_img.shape[0] * image.shape[1] / image.shape[0] - rot_img.shape[1])
# Pad height
else:
h_pad, w_pad = int(rot_img.shape[1] * image.shape[0] / image.shape[1] - rot_img.shape[0]), 0
rot_img = np.pad(rot_img, ((h_pad // 2, h_pad - h_pad // 2), (w_pad // 2, w_pad - w_pad // 2), (0, 0)))
if preserve_origin_shape:
Rob192 marked this conversation as resolved.
Show resolved Hide resolved
# Pad to get the same aspect ratio
if (image.shape[0] / image.shape[1]) != (rot_img.shape[0] / rot_img.shape[1]):
# Pad width
if (rot_img.shape[0] / rot_img.shape[1]) > (image.shape[0] / image.shape[1]):
h_pad, w_pad = 0, int(rot_img.shape[0] * image.shape[1] / image.shape[0] - rot_img.shape[1])
# Pad height
else:
h_pad, w_pad = int(rot_img.shape[1] * image.shape[0] / image.shape[1] - rot_img.shape[0]), 0
rot_img = np.pad(rot_img, ((h_pad // 2, h_pad - h_pad // 2), (w_pad // 2, w_pad - w_pad // 2), (0, 0)))
# rescale
rot_img = cv2.resize(rot_img, image.shape[:-1][::-1], interpolation=cv2.INTER_LINEAR)

Expand Down
4 changes: 2 additions & 2 deletions tests/common/test_utils_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_rotate_image():

# Expand
rotated = geometry.rotate_image(img, 30., expand=True)
assert rotated.shape[:-1] == (60, 72)
assert rotated.shape[:-1] == (60, 120)
assert rotated[0, :, 0].sum() <= 1

# Expand
Expand All @@ -134,5 +134,5 @@ def test_rotate_image():

# Expand with 90° rotation
rotated = geometry.rotate_image(img, 90., expand=True)
assert rotated.shape[:-1] == (64, 64)
assert rotated.shape[:-1] == (64, 128)
assert rotated[0, :, 0].sum() <= 1