There is plenty of answers how to rotate around center of image but how to rotate around an arbitrary point in original image and cropping the new rotated image to its new four corners after rotation (corners of the original image not the black background added).
I tried this based on an answer of someone here, but the result is that image cropped wrong.
import cv2import imutils#https://stackoverflow.com/a/32929315/8384006def rotate(image, angle, center = None, scale = 1.0): (h, w) = image.shape[:2] if center is None: center = (w / 2, h / 2) # Perform the rotation M = cv2.getRotationMatrix2D(center, angle, scale) rotated = cv2.warpAffine(image, M, (w, h)) return rotatedimage = cv2.imread('DJI_0433.jpg', 1)point = (10, 10) # Example point to rotate aroundrotated_image = rotate(image, 35, point) #35 degreescv2.imshow("Rotated Image", cv2.resize(rotated_image, (800, 600)))cv2.waitKey(0) cv2.destroyAllWindows()
That is what is shown, not all its four corners are shown and clipped to.
EDITBecause my english is not so good, that is some additional illustraion: