【发布时间】:2021-10-12 03:38:22
【问题描述】:
我正在尝试从使用 pygame 加载的视频中提取特定帧
在这个question中给出了这个例子
import pygame
import cv2
video = cv2.VideoCapture("video.mp4")
success, video_image = video.read()
fps = video.get(cv2.CAP_PROP_FPS)
window = pygame.display.set_mode(video_image.shape[1::-1])
clock = pygame.time.Clock()
run = success
while run:
clock.tick(fps)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
success, video_image = video.read()
if success:
video_surf = pygame.image.frombuffer(
video_image.tobytes(), video_image.shape[1::-1], "BGR")
else:
run = False
window.blit(video_surf, (0, 0))
pygame.display.flip()
pygame.quit()
exit()
但是,这只会遍历视频中的所有帧。 有没有办法在鼠标点击时获取当前帧?
当我尝试获取例如第 15 帧 video_image[15].tobytes() 我得到 TypeError: argument 2 must be sequence of length 2, not 1
【问题讨论】: