Ask Your Question

sd70's profile - activity

2020-04-12 03:43:13 -0600 received badge  Popular Question (source)
2018-05-13 13:43:01 -0600 received badge  Enthusiast
2018-05-09 23:39:22 -0600 received badge  Supporter (source)
2018-05-09 08:33:48 -0600 received badge  Scholar (source)
2018-05-09 06:15:01 -0600 marked best answer 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()
2018-05-09 06:10:04 -0600 commented question OpenCV in Fullscreen mode changes video aspect ratio

thank you @StevenPuttemans

2018-05-09 06:09:47 -0600 commented question OpenCV in Fullscreen mode changes video aspect ratio

thank you @Steven

2018-05-08 14:15:32 -0600 commented question OpenCV in Fullscreen mode changes video aspect ratio

Thanks. Can I use PyQt windows instead of imshow? Does it fully support OpenCV?

2018-05-08 04:33:07 -0600 asked a question OpenCV in Fullscreen mode changes video aspect ratio

OpenCV in Fullscreen mode changes video aspect ratio Hello. My video aspect ratio is 16:9 and my monitor is 16:10. I wro