MCPcopy Create free account
hub / github.com/PyImageSearch/imutils / rotate_bound

Function rotate_bound

imutils/convenience.py:41–63  ·  view source on GitHub ↗
(image, angle)

Source from the content-addressed store, hash-verified

39 return rotated
40
41def rotate_bound(image, angle):
42 # grab the dimensions of the image and then determine the
43 # center
44 (h, w) = image.shape[:2]
45 (cX, cY) = (w / 2, h / 2)
46
47 # grab the rotation matrix (applying the negative of the
48 # angle to rotate clockwise), then grab the sine and cosine
49 # (i.e., the rotation components of the matrix)
50 M = cv2.getRotationMatrix2D((cX, cY), -angle, 1.0)
51 cos = np.abs(M[0, 0])
52 sin = np.abs(M[0, 1])
53
54 # compute the new bounding dimensions of the image
55 nW = int((h * sin) + (w * cos))
56 nH = int((h * cos) + (w * sin))
57
58 # adjust the rotation matrix to take into account translation
59 M[0, 2] += (nW / 2) - cX
60 M[1, 2] += (nH / 2) - cY
61
62 # perform the actual rotation and return the image
63 return cv2.warpAffine(image, M, (nW, nH))
64
65def resize(image, width=None, height=None, inter=cv2.INTER_AREA):
66 # initialize the dimensions of the image to be resized and

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…