imwarp_quadrangle
-
Description: Applies a 4-point perspective transform to the input image.
-
Parameters
- img (
np.ndarray): The input image to be transformed. - polygon (
Polygon | np.ndarray): A polygon with four points. Ifnp.ndarrayis provided, it is converted toPolygonfirst. - dst_size (
tuple[int, int] | None): Output image size(width, height). IfNone, it is inferred frompolygon.min_box_wh. - do_order_points (
bool): Whether to order the 4 points clockwise (TL, TR, BR, BL). Default isTrue.
- img (
-
Returns
- np.ndarray: The transformed image.
-
Example
import capybara as cb
img = cb.imread('./resource/test_warp.jpg')
polygon = cb.Polygon([[602, 404], [1832, 530], [1588, 985], [356, 860]])
warp_img = cb.imwarp_quadrangle(img, polygon)
The green box in the image above represents the original polygon area.