In this tutorial, I will show how to change the resolution of the video using OpenCV-Python. This blog is based on interpolation methods (Chapter-5) which we have discussed earlier.
Here, I will convert a 640×480 video to 1280×720. Let’s see how to do this
- Load a video using cv2.VideoCapture()
- Create a VideoWriter object using cv2.VideoWriter()
- Extract frame by frame
- Resize the frames using cv2.resize()
- Save the frames to a video file using cv2.VideoWriter()
- Release the VideoWriter and destroy all windows
import numpy as np
cap = cv2.VideoCapture('C:/New folder/video.avi')
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 5, (1280,720))
ret, frame = cap.read()
if ret == True:
b = cv2.resize(frame,(1280,720),fx=0,fy=0, interpolation = cv2.INTER_CUBIC)
Here, I have used Bicubic as the interpolation method, you can use any. Hope you enjoy reading.
If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time.