Recently, we need to use the image processing related operation in the depth study, in the Niang find the picture rotation method is stereotyped, rotate the picture is not the original size, very distressed, so Google to the site of crooked nuts push lightly a method, close to test and use, again to reject the world article a big copy of the phenomenon, Although I also copy crooked nuts. No more nonsense to say, directly affixed to the code.
def rotate_bound (image, Angle):
# Grab the dimensions of the image and then determine the
# Center
(h, w) = IM Age.shape[:2]
(CX, CY) = (w//2, H//2)
# Grab the rotation matrix (applying the negative of the
# angle to Rotate clockwise), then grab the sine and cosine
# (i.e., the rotation components of the matrix)
M = Cv2.getrotati Onmatrix2d (CX, CY),-angle, 1.0)
cos = np.abs (m[0, 0))
sin = Np.abs (m[0, 1])
# Compute the new bounding dime Nsions of the image
NW = Int ((h * sin) + (w * cos))
NH = Int ((h * cos) + (w * sin))
# Adjust the rotation m Atrix to take in account translation
m[0, 2] + = (NW/2)-CX
m[1, 2] + = (NH/2)-CY
# Perform the ACTU Al Rotation and return the image return
cv2.warpaffine (image, M, (NW, NH))
The other is not to say it, the first parameter wears OPENCV read the image, the second parameter passes the angle that needs to rotate, enjoy!