I am cutting out an image of an animal, aligning it, modifying it, then I want to paste it back into the original image. So the workflow is like this:
I have the code to detect and align the animal:
# get rotation matrix
M = cv2.getRotationMatrix2D(eyesCenter, angle, scale)
# update the translation component of the matrix
tX = w * 0.5
tY = h * LeftEye[1]
M[0, 2] += (tX - eyesCenter[0])
M[1, 2] += (tY - eyesCenter[1])
# apply the affine transformation
output = cv2.warpAffine(image, M, (w, h), flags=cv2.INTER_CUBIC)
I tried to use
Mp = np.linalg.inv(M)
But I get the error:
Last 2 dimensions of the array must be square
How can I place the owl back into original image?