Search code examples
numpyopencvmatrixmatrix-multiplicationimage-segmentation

applying cv2.warpAffine on images and polygon annotations simultaneously


I apply random perspective transformations on images using OpenCV as following:

import cv2

# M: some random transformation operations

wimg = cv2.warpAffine(img, M, dsize=(width, height), borderValue=(114,114,114))

I have instance segmentation polygon annotations for each image, and I need to finetune the coordinates according to the new warped image.

How can I do it in a fast way, without converting polygon points to binary images, warping them, and converting back to polygon points?


Solution

  • You can use: cv2.transform

    As stated in OpenCV's documentation: This function may be used for geometrical transformation of N-dimensional points