Skip to content

Commit 531d2d6

Browse files
algobytewisedhruvmanilacclauss
authored
Mypy fix rotation.py (TheAlgorithms#4319)
* fix type-hints arguments * fix matrices & image-path * Update build.yml * Revert "Update build.yml" This reverts commit c2d04ae. * use pathlib * feat: Add mypy configuration file (TheAlgorithms#4315) * feat: Add mypy config file * refactor: Remove mypy options from build workflow * Remove linear_algebra Co-authored-by: Christian Clauss <cclauss@me.com> * rebase & update mypy.ini * fix pre-commit errors Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent c49fa08 commit 531d2d6

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

digital_image_processing/rotation/rotation.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
from pathlib import Path
2+
13
import cv2
24
import numpy as np
35
from matplotlib import pyplot as plt
46

57

68
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:
911
"""
1012
Get image rotation
1113
:param img: np.array
@@ -21,17 +23,19 @@ def get_rotation(
2123

2224
if __name__ == "__main__":
2325
# 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+
)
2529
# turn image in gray scale value
2630
gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
2731
# get image shape
2832
img_rows, img_cols = gray_img.shape
2933

3034
# 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)
3539

3640
# add all rotated images in a list
3741
images = [

mypy.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
ignore_missing_imports = True
33

44
; FIXME: #4052 fix mypy errors in the exclude directories and remove them below
5-
exclude = (data_structures|digital_image_processing|dynamic_programming|graphs|maths|matrix|other|project_euler|scripts|searches|strings*)/$
5+
exclude = (data_structures|dynamic_programming|graphs|maths|matrix|other|project_euler|scripts|searches|strings*)/$

0 commit comments

Comments
 (0)