I am trying to create a play loop option for OpenCV video . My program uses Python multiprocessing and has a button for sending loopswitch calls via queue4 to enable or disable the loop option. My particular problem is that my video freezes in the last frame, and I would like to know if the vidFile.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 1) line of the vidFile.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 1) method is used cv2.VideoCapture.set() , and, indeed, you need to return the video to frame 1 and play it (as I think it should).
EDIT
After reviewing my code, it now launches a C ++ error at runtime, but no other instructions are given. According to this answer, it seems that using cv2.VideoCapture.set() to jump between frames is an error. Could anyone do this?
Thanks,
My code for the capture process ( queue and queue2 are input and output queues):
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
Raoul source share