Skip to content

Mypy fix rotation.py #4319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 6, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions digital_image_processing/rotation/rotation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import cv2
import numpy as np
from matplotlib import pyplot as plt
import os.path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use https://docs.python.org/3/library/pathlib.html instead of os.path for improved readability.

Copy link
Member

@cclauss cclauss Apr 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from pathlib import Path

Path(__file__).resolve().parent / "image_data" / "lena.jpg"



def get_rotation(
img: np.array, pt1: np.float32, pt2: np.float32, rows: int, cols: int
) -> np.array:
img: np.ndarray, pt1: np.ndarray, pt2: np.ndarray, rows: int, cols: int
) -> np.ndarray:
"""
Get image rotation
:param img: np.array
Expand All @@ -21,17 +22,17 @@ def get_rotation(

if __name__ == "__main__":
# read original image
image = cv2.imread("lena.jpg")
image = cv2.imread(os.path.dirname(__file__) + "/../image_data/lena.jpg")
# turn image in gray scale value
gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# get image shape
img_rows, img_cols = gray_img.shape

# set different points to rotate image
pts1 = np.float32([[50, 50], [200, 50], [50, 200]])
pts2 = np.float32([[10, 100], [200, 50], [100, 250]])
pts3 = np.float32([[50, 50], [150, 50], [120, 200]])
pts4 = np.float32([[10, 100], [80, 50], [180, 250]])
pts1 = np.array([[50, 50], [200, 50], [50, 200]], np.float32)
pts2 = np.array([[10, 100], [200, 50], [100, 250]], np.float32)
pts3 = np.array([[50, 50], [150, 50], [120, 200]], np.float32)
pts4 = np.array([[10, 100], [80, 50], [180, 250]], np.float32)

# add all rotated images in a list
images = [
Expand Down