如何从多个视频中提取帧

时间:2019-06-22 00:23:44

标签: python opencv cv2

我定义了一个从单个视频流中提取帧的函数,但我不知道如何使用它从多个视频中提取帧

def frames(path):
    # Read the video from specified path 
    cam = cv2.VideoCapture(path) 
    try: 
        # creating a folder named data 
        if not os.path.exists('datav3'): 
            os.makedirs('datav3') 
    # if not created then raise error 
    except OSError: 
        print ('Error: Creating directory of data') 
    # frame 
    currentframe = 0
    while(True): 
        # reading from frame 
        ret,frame = cam.read() 
        if ret: 
            # if video is still left continue creating images 
            name = './datav3/frame' + str(currentframe) + '.jpg'
            print ('Creating...' + name) 
            # writing the extracted images 
            cv2.imwrite(name, frame) 
            # increasing counter so that it will 
            # show how many frames are created 
            currentframe += 1
        else: 
            break
    # Release all space and windows once done 
    cam.release() 
    cv2.destroyAllWindows()

0 个答案:

没有答案