我正试图建立一个
一个OpenCV视频的循环播放选项
.我的程序使用Python多进程,并有一个按钮通过
loopswitch
发送
queue4
调用,以启用或禁用循环选项。我的具体问题是,我的视频在最后一帧冻结了,并且
我想知道
vidFile.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 1)
这一行是否是对
cv2.VideoCapture.set()
方法的正确使用。
而且确实应该将视频带回第1帧并重放(我认为应该如此)。
在修改了我的代码后,现在触发了一个运行时的C++错误,但没有给出其他的预判。 根据 这个答案 替换代码3】在帧间跳转似乎是个错误。有谁能做到这一点?
我的捕获过程的代码(
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():
else:
queueval = queue4.get()
if queueval=='loop':
if loopswitch==False:
loopswitch = True
elif loopswitch==True:
loopswitch = False
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