Resizing an image
import cv2 as cv
# Scale the image in a particular size
def rescaleFrame(frame, scale=0.5):
width = int(frame.shape[1]*scale)
height = int(frame.shape[0]*scale)
dimensions = (width, height)
return cv.resize(frame, dimensions, interpolation=cv.INTER_AREA)
img = cv.imread('Photos/cat.jpg')
cv.imshow('Cat', img)
cv.imshow('Resize Cat', rescaleFrame(img))
cv.waitKey(0)
Resizing a video
import cv2 as cv
# Scale the image in a particular size
def rescaleFrame(frame, scale=0.5):
width = int(frame.shape[1]*scale)
height = int(frame.shape[0]*scale)
dimensions = (width, height)
return cv.resize(frame, dimensions, interpolation=cv.INTER_AREA)
# Reading videos
capture = cv.VideoCapture('Videos/dog.mp4')
while True:
isTrue, frame = capture.read()
# Resizing
frame_resized = rescaleFrame(frame)
cv.imshow('Video', frame)
cv.imshow('Video Resized', frame_resized)
if cv.waitKey(20) & 0xFF==ord('d'):
break
capture.release()
cv.destroyAllWindows()
Change the resolution
import cv2 as cv
# Scale the image in a particular size
def rescaleFrame(frame, scale=0.5):
# Images, Videos and Live Video
width = int(frame.shape[1]*scale)
height = int(frame.shape[0]*scale)
dimensions = (width, height)
return cv.resize(frame, dimensions, interpolation=cv.INTER_AREA)
# Change the resolution
def changeRes(width, height):
# Live video
capture.set(3,width)
capture.set(4,height)
# Reading videos
capture = cv.VideoCapture('Videos/dog.mp4')
while True:
isTrue, frame = capture.read()
# Resizing
frame_resized = rescaleFrame(frame)
cv.imshow('Video', frame)
cv.imshow('Video Resized', frame_resized)
if cv.waitKey(20) & 0xFF==ord('d'):
break
capture.release()
cv.destroyAllWindows()
'OpenCV' 카테고리의 다른 글
[OpenCV] contours.py (0) | 2024.04.10 |
---|---|
[OpenCV] transformations.py (0) | 2024.04.10 |
[OpenCV] basic.py (0) | 2024.04.10 |
[OpenCV] draw.py (0) | 2024.04.10 |
[OpenCV] read.py (0) | 2024.04.10 |