[Python] Combine png-images to video with alpha channel in python

Discussão em 'Python' iniciado por Stack, Dezembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    My Intention was: - Extract all frames from video - Apply background removal to each frame - Merge all frames together as a video with transparency

    Problem: - The resulting video doesn't have the desired transparency where the background used to be My code for the Merging-Part

    import cv2
    import os

    image_folder = r"C:\Users\youre\Documents\machine_learning\bg-rm\output"
    video_name = r'C:\Users\youre\Documents\machine_learning\bg-rm\test.avi'
    images = # list of all frames
    frame = cv2.imread(os.path.join(image_folder, images[0]))
    height, width, layers = frame.shape
    video = cv2.VideoWriter(video_name, cv2.VideoWriter_fourcc(*"MJPG"), 30, (width, height))
    for image in images:
    video.write(cv2.imread(os.path.join(image_folder, image)))
    cv2.destroyAllWindows()
    video.release()


    My question: - What do I have to do in order to have my transparency over the background in the resulting video, because my code just gives me a black background. More specific: How do I merge the png-frames together with an alpha channel?

    Continue reading...

Compartilhe esta Página