from cv2 import cv
import numpy as np

def subimage(image, centre, theta, width, height):
    output_image = cv.CreateImage((width, height), image.depth, image.nChannels
        )
mapping = np.array([[np.cos(theta), -np.sin(theta), centre[0]], [np.sin(
    theta), np.cos(theta), centre[1]]])
map_matrix_cv = cv.fromarray(mapping)
cv.GetQuadrangleSubPix(image, output_image, map_matrix_cv)
return output_image
How to straighten a rotated rectangle area of an image using opencv in python?