[Python] OpenCv_Python - Convert Frame Sequence To a Video

Discussão em 'Python' iniciado por Stack, Agosto 11, 2025.

  1. Stack

    Stack Membro Participativo

    I am a newbie in OpenCV using Python. I am currently working with a project related opencv using python language. I have a video data set named "VideoDataSet/dynamicBackground/canoe/input" that stores the sequence of image frames and I would like to convert the sequence of frames from the file path to a video. However, I am getting an error when I execute the program. I have tried various codecs but it still gives me the same errors, can any of you please shed some light on what might be wrong? Thank you. This is my sample code:

    import cv2
    import numpy as np
    import os
    import glob as gb

    filename = "VideoDataSet/dynamicBackground/canoe/input"

    img_path = gb.glob(filename)

    videoWriter = cv2.VideoWriter('test.avi', cv2.VideoWriter_fourcc(*'MJPG'),
    25, (640,480))

    for path in img_path:
    img = cv2.imread(path)
    img = cv2.resize(img,(640,480))
    videoWriter.write(img)
    print ("you are success create.")


    This is the error:

    Error prompt out:cv2.error: OpenCV(3.4.1) D:\Build\OpenCV\opencv-3.4.1\modules\imgproc\src\resize.cpp:4044: error: (-215) ssize.width > 0 && ssize.height > 0 in function cv::resize


    (Note: the problem occur with the img = cv2.resize(img,(640,480)))

    Continue reading...

Compartilhe esta Página