【发布时间】:2013-06-14 01:27:58
【问题描述】:
我正在尝试为 OpenCV 视频构建一个播放循环选项。我的程序使用 Python 多处理,并有一个按钮通过 queue4 发送 loopswitch 调用以启用或禁用循环选项。我的具体问题是我的视频在最后一帧冻结,我想知道vidFile.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 1) 行是否正确使用cv2.VideoCapture.set() 方法,并且确实应该将视频取回帧 1 并重播(我认为应该如此)。
编辑
修改我的代码后,它现在触发运行时 C++ 错误,但没有给出其他精度。
根据this answer 的说法,使用cv2.VideoCapture.set() 在帧之间跳转似乎是错误的。有人管理过吗?
谢谢,
我的捕获过程代码(queue和queue2在队列中):
def image_capture(queue, con, queue2, queue4):
videopath = con.recv()
vidFile = cv2.VideoCapture(videopath)
fps = vidFile.get(cv2.cv.CV_CAP_PROP_FPS)
waitframe = 1/fps
con.send(waitframe)#sending waitkey duration through pipe to update_image()
loopswitch = False #init for playing video in a loop
while True:
if queue4.empty():
pass
else:
queueval = queue4.get()
if queueval=='loop':
if loopswitch==False:
loopswitch = True
elif loopswitch==True:
loopswitch = False
try:
flag, frame=vidFile.read()
if flag==0:
if loopswitch==False:
queue2.put(None)
break
elif loopswitch==True:
vidFile.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 1)
continue
else:
queue2.put(frame)
cv2.waitKey(waitframe)
except:
continue
【问题讨论】:
标签: python opencv video-capture