|
5 | 5 | import os
|
6 | 6 | from tkinter import *
|
7 | 7 | import shutil
|
| 8 | + |
8 | 9 | import blur_detection
|
9 | 10 |
|
10 | 11 |
|
@@ -275,10 +276,27 @@ def file_naming(_img, process_initial, _folder, _set_counter):
|
275 | 276 | if rotationAngle is not None:
|
276 | 277 | # Rotation Code
|
277 | 278 | for angle in range(0, 360, rotationAngle):
|
278 |
| - dim = _img.shape |
279 | 279 | _scaleFactor = 1
|
280 |
| - _rotationMatrix = cv2.getRotationMatrix2D((dim[1] / 2, dim[0] / 2), angle, _scaleFactor) |
281 |
| - _imgRotated = cv2.warpAffine(_img, _rotationMatrix, (dim[1], dim[0]), flags=cv2.INTER_LINEAR, |
| 280 | + (h, w) = _img.shape[:2] |
| 281 | + (cX, cY) = (w // 2, h // 2) |
| 282 | + |
| 283 | + # grab the rotation matrix (applying the negative of the |
| 284 | + # angle to rotate clockwise), then grab the sine and cosine |
| 285 | + # (i.e., the rotation components of the matrix) |
| 286 | + M = cv2.getRotationMatrix2D((cX, cY), angle, _scaleFactor) |
| 287 | + |
| 288 | + cos = np.abs(M[0, 0]) |
| 289 | + sin = np.abs(M[0, 1]) |
| 290 | + |
| 291 | + # compute the new bounding dimensions of the image |
| 292 | + nW = int((h * sin) + (w * cos)) |
| 293 | + nH = int((h * cos) + (w * sin)) |
| 294 | + |
| 295 | + # adjust the rotation matrix to take into account translation |
| 296 | + M[0, 2] += (nW / 2) - cX |
| 297 | + M[1, 2] += (nH / 2) - cY |
| 298 | + |
| 299 | + _imgRotated = cv2.warpAffine(_img, M, (nW, nH), flags=cv2.INTER_LINEAR, |
282 | 300 | borderMode=cv2.BORDER_REFLECT_101)
|
283 | 301 | _savingName = dst_root + _folder + "/" + _folder + "_" + str(name_counter) + "_" \
|
284 | 302 | + process_initial + "_Rot_" + str(angle) + ".jpg"
|
|
0 commit comments