Skip to content

Commit 197dbed

Browse files
authored
Fix incorrect warped image size (#23)
* add argument `width` and `height` * default width and height should be `(240, 80)`
1 parent 900b7f2 commit 197dbed

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

wpodnet/backend.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,16 @@ def annotate(
5555
drawer = ImageDraw.Draw(canvas)
5656
drawer.polygon(self.bounds, fill=fill, outline=outline, width=width)
5757

58-
def warp(self, canvas: Image.Image) -> Image.Image: # pragma: no cover
58+
def warp(
59+
self, canvas: Image.Image, width: int = 240, height: int = 80
60+
) -> Image.Image: # pragma: no cover
5961
"""
6062
Warps the image with perspective based on the bounding polygon.
6163
6264
Args:
6365
canvas (PIL.Image.Image): The image to be warped.
66+
width (int): The width of the output warped image. Defaults to 240.
67+
height (int): The height of the output warped image. Defaults to 80.
6468
6569
Returns:
6670
PIL.Image.Image: The warped image.
@@ -69,14 +73,12 @@ def warp(self, canvas: Image.Image) -> Image.Image: # pragma: no cover
6973
startpoints=self.bounds,
7074
endpoints=[
7175
(0, 0),
72-
(canvas.width, 0),
73-
(canvas.width, canvas.height),
74-
(0, canvas.height),
76+
(width, 0),
77+
(width, height),
78+
(0, height),
7579
],
7680
)
77-
return canvas.transform(
78-
(canvas.width, canvas.height), Image.Transform.PERSPECTIVE, coeffs
79-
)
81+
return canvas.transform((width, height), Image.Transform.PERSPECTIVE, coeffs)
8082

8183

8284
Q = np.array(

0 commit comments

Comments
 (0)