-
Notifications
You must be signed in to change notification settings - Fork 0
/
rescale.py
37 lines (28 loc) · 914 Bytes
/
rescale.py
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
30
31
32
33
34
35
36
37
import cv2 as cv
# Reading Images
img = cv.imread('Photos/cat_large.jpg')
# Rescale Function
def rescaleFrame(frame, scale=0.2): #this works for images, videos and live videos
width = int(frame.shape[1] * scale)
height = int(frame.shape[0] * scale)
dimensions = (width, height)
return cv.resize(frame, dimensions, interpolation=cv.INTER_AREA)
#resizing image
# resized_image = rescaleFrame(img)
# cv.imshow('Image', resized_image)
# cv.waitKey(0)
#resizing videos
def changeRes(width, height): #this works for only videos
capture.set(3, width)
capture.set(4, height)
# Reading Videos
capture = cv.VideoCapture(0)
while True:
isTrue, frame = capture.read()
frame_resized = rescaleFrame(frame, scale=0.2)
cv.imshow('Video', frame)
cv.imshow('Video Resized', frame_resized)
if cv.waitKey(20) & 0xFF==ord('d'):
break
capture.release()
cv.destroyAllWindows()