OpenCV in Fullscreen mode changes video aspect ratio
Hello. My video aspect ratio is 16:9 and my monitor is 16:10. I wrote this code for playing video in full screen mode but the problem is it causes my video to stretch. I want to keep its aspect ratio and have black bars on top and bottom (just like playing videos in KMPlayer)
Is there any solution? Thanks
import cv2
import numpy as np
vid = cv2.VideoCapture('video.mp4')
cv2.namedWindow('My Window',cv2.WINDOW_KEEPRATIO)
cv2.setWindowProperty('My Window',cv2.WND_PROP_ASPECT_RATIO,cv2.WINDOW_KEEPRATIO)
cv2.setWindowProperty('My Window',cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
while vid.isOpened():
ret,frame = vid.read()
cv2.imshow('My Window',frame)
if cv2.waitKey(1) == ord('q'): break
vid.release()
cv2.destroyAllWindows()