1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| def rotate_bound(image, angle): (h, w) = image.shape[:2] (cx, cy) = (w / 2, h / 2) M = cv2.getRotationMatrix2D((cx, cy), -angle, 1.0) cos = np.abs(M[0, 0]) sin = np.abs(M[0, 1]) nW = int((h * sin) + (w * cos)) nH = int((h * cos) + (w * sin)) M[0, 2] += (nW / 2) - cx M[1, 2] += (nH / 2) - cy return cv2.warpAffine(image, M, (nW, nH))
|