1
+ from pathlib import Path
2
+
1
3
import cv2
2
4
import numpy as np
3
5
from matplotlib import pyplot as plt
4
6
5
7
6
8
def get_rotation (
7
- img : np .array , pt1 : np .float32 , pt2 : np .float32 , rows : int , cols : int
8
- ) -> np .array :
9
+ img : np .ndarray , pt1 : np .ndarray , pt2 : np .ndarray , rows : int , cols : int
10
+ ) -> np .ndarray :
9
11
"""
10
12
Get image rotation
11
13
:param img: np.array
@@ -21,17 +23,19 @@ def get_rotation(
21
23
22
24
if __name__ == "__main__" :
23
25
# read original image
24
- image = cv2 .imread ("lena.jpg" )
26
+ image = cv2 .imread (
27
+ str (Path (__file__ ).resolve ().parent .parent / "image_data" / "lena.jpg" )
28
+ )
25
29
# turn image in gray scale value
26
30
gray_img = cv2 .cvtColor (image , cv2 .COLOR_BGR2GRAY )
27
31
# get image shape
28
32
img_rows , img_cols = gray_img .shape
29
33
30
34
# set different points to rotate image
31
- pts1 = np .float32 ([[50 , 50 ], [200 , 50 ], [50 , 200 ]])
32
- pts2 = np .float32 ([[10 , 100 ], [200 , 50 ], [100 , 250 ]])
33
- pts3 = np .float32 ([[50 , 50 ], [150 , 50 ], [120 , 200 ]])
34
- pts4 = np .float32 ([[10 , 100 ], [80 , 50 ], [180 , 250 ]])
35
+ pts1 = np .array ([[50 , 50 ], [200 , 50 ], [50 , 200 ]], np . float32 )
36
+ pts2 = np .array ([[10 , 100 ], [200 , 50 ], [100 , 250 ]], np . float32 )
37
+ pts3 = np .array ([[50 , 50 ], [150 , 50 ], [120 , 200 ]], np . float32 )
38
+ pts4 = np .array ([[10 , 100 ], [80 , 50 ], [180 , 250 ]], np . float32 )
35
39
36
40
# add all rotated images in a list
37
41
images = [
0 commit comments