在opencv中按指定键时是否可以倒带?我有下面的视频,但它没有回放
def run(self, filepath, fps, width, height, monochrome=False):
video_file = self.read_file(filepath)
previous_frame = None
while (video_file.isOpened()):
ret, frame = video_file.read()
if previous_frame is not None:
pass
previous_frame = frame
if ret:
frame = self.color(frame, monochrome)
final_frame = self.resolution(frame, width, height)
delaytime = self.frame_per_second(fps)
cv2.imshow('frame', final_frame)
key = cv2.waitKey(delaytime)
if key & 0xFF == ord("p"):
cv2.waitKey(234320)
if key & 0xFF == ord("r"):
cv2.set(cv2.CV_CAP_PROP_POS_FRAMES(2, previous_frame))
video_file.release()
cv2.destroyAllWindows()
上面的代码将它带到上一帧,但不播放
理想的解决方案是设置暂停视频时需要播放的帧数,以实现回放效果。这可以通过video capture properties完成:
有用的示例可在“Jumping between frames in video files”中找到
这是一个源代码示例,它暂停视频,并提供一些控制,让您回放到上一帧或跳转到零帧,然后重新启动视频:
按键选项:
q
退出应用程序李>p
暂停李>p
继续播放李>b
回放单个帧。您必须按p
重新开始播放李>r
将回放到第0帧并自动恢复播放李>如果只需要上一帧,可以存储在临时数组中。 例如:
相关问题 更多 >
编程相关推荐