From 15afd5094e7dd42fd5af8c09d464de5a7e356657 Mon Sep 17 00:00:00 2001 From: Pandede Date: Mon, 2 Jun 2025 17:58:57 +0800 Subject: [PATCH 1/2] add argument `width` and `height` --- wpodnet/backend.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/wpodnet/backend.py b/wpodnet/backend.py index 6cea2cd..8d3dc74 100644 --- a/wpodnet/backend.py +++ b/wpodnet/backend.py @@ -55,12 +55,16 @@ def annotate( drawer = ImageDraw.Draw(canvas) drawer.polygon(self.bounds, fill=fill, outline=outline, width=width) - def warp(self, canvas: Image.Image) -> Image.Image: # pragma: no cover + def warp( + self, canvas: Image.Image, width: int = 208, height: int = 60 + ) -> Image.Image: # pragma: no cover """ Warps the image with perspective based on the bounding polygon. Args: canvas (PIL.Image.Image): The image to be warped. + width (int): The width of the output warped image. Defaults to 208. + height (int): The height of the output warped image. Defaults to 60. Returns: PIL.Image.Image: The warped image. @@ -69,14 +73,12 @@ def warp(self, canvas: Image.Image) -> Image.Image: # pragma: no cover startpoints=self.bounds, endpoints=[ (0, 0), - (canvas.width, 0), - (canvas.width, canvas.height), - (0, canvas.height), + (width, 0), + (width, height), + (0, height), ], ) - return canvas.transform( - (canvas.width, canvas.height), Image.Transform.PERSPECTIVE, coeffs - ) + return canvas.transform((width, height), Image.Transform.PERSPECTIVE, coeffs) Q = np.array( From 742d6b4845651766a77b76293d1a7783a66d3502 Mon Sep 17 00:00:00 2001 From: Pandede Date: Mon, 2 Jun 2025 18:01:32 +0800 Subject: [PATCH 2/2] default width and height should be `(240, 80)` --- wpodnet/backend.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wpodnet/backend.py b/wpodnet/backend.py index 8d3dc74..a006673 100644 --- a/wpodnet/backend.py +++ b/wpodnet/backend.py @@ -56,15 +56,15 @@ def annotate( drawer.polygon(self.bounds, fill=fill, outline=outline, width=width) def warp( - self, canvas: Image.Image, width: int = 208, height: int = 60 + self, canvas: Image.Image, width: int = 240, height: int = 80 ) -> Image.Image: # pragma: no cover """ Warps the image with perspective based on the bounding polygon. Args: canvas (PIL.Image.Image): The image to be warped. - width (int): The width of the output warped image. Defaults to 208. - height (int): The height of the output warped image. Defaults to 60. + width (int): The width of the output warped image. Defaults to 240. + height (int): The height of the output warped image. Defaults to 80. Returns: PIL.Image.Image: The warped image.