opencv中播放视频窗口大小与原视频不一致怎么办
时间: 2023-05-26 11:06:41 浏览: 267
可以使用cv2.resize()函数改变窗口大小,如下:
```
import cv2
cap = cv2.VideoCapture("video.mkv")
# 获取原视频大小
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# 改变目标窗口大小
new_width = 800
new_height = 600
# 创建视频窗口
cv2.namedWindow("Video", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Video", new_width, new_height)
while True:
ret, frame = cap.read()
if ret:
# 将帧大小调整为目标窗口大小
frame = cv2.resize(frame, (new_width, new_height))
# 显示帧
cv2.imshow("Video", frame)
# 按下q键退出循环
if cv2.waitKey(25) & 0xFF == ord("q"):
break
else:
break
cap.release()
cv2.destroyAllWindows()
```
阅读全文
相关推荐
















