Ask Your Question
0

OpenCV in Fullscreen mode changes video aspect ratio

asked 2018-05-08 04:00:53 -0600

sd70 gravatar image

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()
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-05-08 07:47:33 -0600

The cv2.WINDOW_KEEPRATIO and the cv2.WINDOW_FULLSCREEN option simply do opposite things. You cannot avoid this. The windows are purely there for debugging purposes, if you want to make a clear gui output, use Qt or another backend specific for this.

edit flag offensive delete link more

Comments

Thanks.

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

sd70 gravatar imagesd70 ( 2018-05-08 14:15:32 -0600 )edit

It does not need OpenCV support. The idea is that you use OpenCV to process your data, then stock it in a PyQt format and use Qt to visualise everything.

StevenPuttemans gravatar imageStevenPuttemans ( 2018-05-09 03:15:00 -0600 )edit
1
sd70 gravatar imagesd70 ( 2018-05-09 06:09:47 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-05-08 04:00:53 -0600

Seen: 4,022 times

Last updated: May 08 '18