def subimage(self, image, center, theta, width, height):
    theta *= 3.14159 / 180
v_x = cos(theta), sin(theta)
v_y = -sin(theta), cos(theta)
s_x = center[0] - v_x[0] * (width / 2) - v_y[0] * (height / 2)
s_y = center[1] - v_x[1] * (width / 2) - v_y[1] * (height / 2)
mapping = np.array([[v_x[0], v_y[0], s_x], [v_x[1], v_y[1], s_y]])
return cv2.warpAffine(image, mapping, (width, height), flags=cv2.
    WARP_INVERSE_MAP, borderMode=cv2.BORDER_REPLICATE)
How to straighten a rotated rectangle area of an image using opencv in python?