Given 4 points, how to crop a quadrilateral from an image in pytorch/torchvision?
Problem is pretty straightforward -  

I want to crop a quadrilateral from an image in pytorch/torchvision. Given, I have four coordinates of the corners of this quadrilateral.

Please note that these four points confine a quadrilateral within themselves which may or may not be a rectangle. So please refrain from suggesting answers involving slicing of the image.

Please comment if I have missed any relevant detail.

Quoting https://stackoverflow.com/a/30902423/4982729 I could extract the patch using opencv as -

import numpy as np
import cv2

pts = np.array([[542, 107], [562, 102], [582, 110], [598, 142], [600, 192], [601, 225], [592, 261], [572, 263], [551, 245], [526, 220], [520, 188], [518, 152], [525, 127], [524, 107]], dtype=np.int32)

mask = np.zeros((img.shape[0], img.shape[1]))

cv2.fillConvexPoly(mask, pts, 1)
mask = mask.astype(np.bool)

out = np.zeros_like(img)
out[mask] = img[mask]




and then I could convert the numpy array to torch's Variable manually. This seems to raise no errors even when I am forming torch's graph for neural networks.

    outputs = model(images)
    o = outputs.data.cpu().numpy()
    #
    # do your opencv stuff here to o
    #
    o = torch.Tensor(o).to(device)
    outputs = Variable(o, requires_grad=True)

