OpenCV-PYTHON MAGICAL LIBRARY
In this blog, we will study the rescaling of the image and resolution of the video. As discussed in the previous tutorial about reading and display of the image, we'll continue with other features of OpenCV.
RESCALING OF THE IMAGE
In this section, we are going to discuss our second OpenCV example. We will see how to rescale the image.
RESCALE THE IMAGE
import cv2 as cv def rescaleFrame(frame,scale=0.75): 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("D:\Downloads\luisa-azevedo-h8cUkYFZrzI-unsplash (1).jpg") image_resized=rescaleFrame(img,scale=0.40) cv.imshow("image",img) cv.imshow("image resized",image_resized) |
rescaleFrame= This is the function of rescaling.
cv.INTER_AREA=This is used for shrinking.
RESOLUTION OF THE VIDEO
In this section, we are going to discuss our second OpenCV example. We will see the resolution of the video.
RESOLUTION OF VIDEO
import cv2 #this is only for live videos cap = cv2.VideoCapture(0, cv2.CAP_DSHOW) def make_1080p(): cap.set(3, 1920) cap.set(4, 1080) def make_720p(): cap.set(3, 1280) cap.set(4, 720) def make_480p(): cap.set(3, 640) cap.set(4, 480) def change_res(width, height): cap.set(3, width) cap.set(4, height) make_720p() change_res(1280, 720) |
Thank You!
Keep Learning!
Share with your mates.
Follow us for more amazing content.