-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathresize.py
More file actions
29 lines (22 loc) · 855 Bytes
/
Copy pathresize.py
File metadata and controls
29 lines (22 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import imutils
import cv2
# Load the image and show it
image = cv2.imread('C:/PythonProjects/PracticalPythonAndOpenCV_Book/images/trex.png')
cv2.imshow("Original", image)
# Calculate the ratio based on the width to keep the aspect ratio
r = 150.0 / image.shape[1]
dim = (150, int(image.shape[0] * r))
# Perform the actual resizing of the image
resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)
cv2.imshow("Resized (Width)", resized)
# Calculate the ratio based on height to keep the aspect ratio
r = 50.0 / image.shape[0]
dim = (int(image.shape[1] * r), 50)
# Perform the resizing
resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)
cv2.imshow("Resized (Height)", resized)
cv2.waitKey(0)
# Resizing using our own function
resized = imutils.resize(image, width=100)
cv2.imshow("Resized via Function", resized)
cv2.waitKey(0)