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