1 回答

TA贡献1804条经验 获得超8个赞
我想要实现的是将正在播放的视频窗口移动到屏幕上的另一个位置
如果上述陈述是您主要关心的问题,那么请使用FileVideoStream
.
VideoCapture 管道将大部分时间花在读取和解码下一帧上。当读取、解码并返回下一帧时,OpenCV 应用程序被完全阻止。
这意味着当您移动视频时,应用程序会被阻止,因为管道无法解码下一帧。
例如:下面是显示框架,同时手动拖动窗口。
import cv2
import time
from imutils.video import FileVideoStream
vs = FileVideoStream('result.mp4').start()
time.sleep(0.2)
while True:
frame = vs.read()
cv2.imshow("out", frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
vs.stop()
cv2.destroyAllWindows()
现在,如果我们将代码与一些变量合并:
import cv2
import time
from imutils.video import FileVideoStream
vs = FileVideoStream('result.mp4').start()
time.sleep(0.2)
count = 0
x_pos = 0
y_pos = 0
a_x = 180
a_y = 180
frames = 60
while True:
frame = vs.read()
scale_percent = 200
width = int(frame.shape[1] * scale_percent / 100)
height = int(frame.shape[0] * scale_percent / 100)
dim = (width, height)
if count in range(0, 55):
resized = cv2.resize(frame, dim, interpolation=cv2.INTER_AREA)
cv2.imshow('Frame', resized)
x_pos = x_pos + int((a_x / frames) * (count - 50))
y_pos = y_pos + int((a_y / frames) * (count - 50))
cv2.moveWindow('Frame', x_pos, y_pos)
cv2.imshow("out", frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
vs.stop()
cv2.destroyAllWindows()
您将看到两个窗口,一个正在显示,第二个窗口正在从窗口的右侧位置移动到左侧位置。
添加回答
举报