Skip to content

Commit f86d4b2

Browse files
update
1 parent d4dffcd commit f86d4b2

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

doctr/models/_utils.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def estimate_orientation(
9898
if general_page_orientation and general_page_orientation[1] >= min_confidence:
9999
estimated_angle = estimated_angle + general_page_orientation[0]
100100

101-
return -estimated_angle # return the clockwise angle
101+
return estimated_angle # return the clockwise angle
102102

103103

104104
def rectify_crops(
@@ -107,10 +107,12 @@ def rectify_crops(
107107
) -> List[np.ndarray]:
108108
"""Rotate each crop of the list according to the predicted orientation:
109109
0: already straight, no rotation
110-
1: 90 cw, rotate 3 times ccw
111-
2: 180 cw, rotate 2 times ccw
112-
3: 270 cw, rotate 1 times ccw
110+
1: 90 ccw, rotate 3 times ccw
111+
2: 180, rotate 2 times ccw
112+
3: 270 ccw, rotate 1 time ccw
113113
"""
114+
# Inverse predictions (if angle of +90 is detected, rotate by -90)
115+
orientations = [4 - pred if pred != 0 else 0 for pred in orientations]
114116
return (
115117
[crop if orientation == 0 else np.rot90(crop, orientation) for orientation, crop in zip(orientations, crops)]
116118
if len(orientations) > 0
@@ -128,8 +130,7 @@ def rectify_loc_preds(
128130
return (
129131
np.stack(
130132
[
131-
# shift clockwise
132-
np.roll(page_loc_pred, -orientation, axis=0)
133+
np.roll(page_loc_pred, orientation, axis=0)
133134
for orientation, page_loc_pred in zip(orientations, page_loc_preds)
134135
],
135136
axis=0,

doctr/models/kie_predictor/pytorch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def forward(
9797
general_pages_orientations = None
9898
origin_pages_orientations = None
9999
if self.straighten_pages:
100-
pages = self._get_straightened_pages(pages, seg_maps, general_pages_orientations, origin_pages_orientations) # type: ignore[arg-type]
100+
pages = self._get_straightened_pages(pages, seg_maps, general_pages_orientations, origin_pages_orientations) # type: ignore
101101
# Forward again to get predictions on straight pages
102102
loc_preds = self.det_predictor(pages, **kwargs)
103103

doctr/models/predictor/base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _get_pages_orientations(
7777
) -> Tuple[List[Tuple[int, float]], List[int]]:
7878
general_pages_orientations = self._get_general_pages_orientations(pages)
7979
origin_page_orientations = [
80-
estimate_orientation(seq_map, general_orientation)
80+
-estimate_orientation(seq_map, general_orientation)
8181
for seq_map, general_orientation in zip(seg_maps, general_pages_orientations)
8282
]
8383
return general_pages_orientations, origin_page_orientations
@@ -115,7 +115,6 @@ def _get_straightened_pages(
115115
]
116116
)
117117
# TODO: test the -> expand if page page width is larger than height
118-
# rotate image counter clockwise
119118
return [
120119
rotate_image(page, angle, expand=page.shape[1] > page.shape[0])
121120
for page, angle in zip(pages, origin_pages_orientations)

doctr/models/predictor/pytorch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def forward(
9595
general_pages_orientations = None
9696
origin_pages_orientations = None
9797
if self.straighten_pages:
98-
pages = self._get_straightened_pages(pages, seg_maps, general_pages_orientations, origin_pages_orientations) # type: ignore[assignment]
98+
pages = self._get_straightened_pages(pages, seg_maps, general_pages_orientations, origin_pages_orientations) # type: ignore
9999
# Forward again to get predictions on straight pages
100100
loc_preds = self.det_predictor(pages, **kwargs)
101101

0 commit comments

Comments
 (0)