Skip to content
Merged
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
16 changes: 9 additions & 7 deletions wpodnet/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 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 240.
height (int): The height of the output warped image. Defaults to 80.

Returns:
PIL.Image.Image: The warped image.
Expand All @@ -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(
Expand Down
Loading