Last active
August 22, 2021 11:22
-
-
Save NicholasBallard/b454eb6cd2e6f66a0346154a435b420b to your computer and use it in GitHub Desktop.
opencv_resize.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
def resize(fp: str, scale: Union[float, int]) -> np.ndarray: | |
""" Resize an image maintaining its proportions | |
Args: | |
fp (str): Path argument to image file | |
scale (Union[float, int]): Percent as whole number of original image. eg. 53 | |
Returns: | |
image (np.ndarray): Scaled image | |
""" | |
_scale = lambda dim, s: int(dim * s / 100) | |
im: np.ndarray = cv2.imread(fp) | |
height, width, channels = im.shape | |
new_width: int = _scale(width, scale) | |
new_height: int = _scale(height, scale) | |
new_dim: tuple = (new_width, new_height) | |
return cv2.resize(src=im, dsize=new_dim, interpolation=cv2.INTER_LINEAR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're welcome. I realized that my screenshot didn't upload last time. I updated the comment.
Happy Coding :)