How to read mp4 video to be processed by scikit-image?

后端 未结 3 1962
名媛妹妹
名媛妹妹 2020-12-23 17:28

I would like to apply a scikit-image function (specifically the template matching function match_template) to the frames of a mp4 vide

3条回答
  •  我在风中等你
    2020-12-23 17:58

    You could use scikit-video, like this:

    from skvideo.io import VideoCapture
    
    cap = VideoCapture(filename)
    cap.open()
    
    while True:
        retval, image = cap.read()
        # image is a numpy array containing the next frame
        # do something with image here
        if not retval:
            break
    

    This uses avconv or ffmpeg under the hood. The performance is quite good, with a small overhead to move the data into python compared to just decoding the video in avconv.

    The advantage of scikit-video is that the API is exactly the same as the video reading/writing API of OpenCV; just replace cv2.VideoCapture with skvideo.io.VideoCapture.

提交回复
热议问题