(matrix: np.ndarray, angle: float)
| 64 | |
| 65 | |
| 66 | def rotate(matrix: np.ndarray, angle: float) -> np.ndarray: |
| 67 | h, w = matrix.shape[:2] |
| 68 | center = (w / 2, h / 2) |
| 69 | |
| 70 | rotation_matrix = cv.getRotationMatrix2D(center, angle, 1.0) |
| 71 | corners = cv.transform( |
| 72 | np.array([[[0, 0], [w, 0], [w, h], [0, h]]]), rotation_matrix |
| 73 | )[0] |
| 74 | |
| 75 | _, _, w, h = cv.boundingRect(corners) |
| 76 | |
| 77 | rotation_matrix[0, 2] += w / 2 - center[0] |
| 78 | rotation_matrix[1, 2] += h / 2 - center[1] |
| 79 | result = cv.warpAffine(matrix, rotation_matrix, (w, h), flags=cv.INTER_LINEAR) |
| 80 | |
| 81 | return result |
| 82 | |
| 83 | |
| 84 | def rotate_vector_field_normals(normals: np.ndarray, angle: float) -> np.ndarray: |
no outgoing calls
no test coverage detected