Home > Blockchain >  VideoCapture removes alpha channel
VideoCapture removes alpha channel

Time:10-19

I want to get alpha channel from mov file using opencv-python. And, I read these information: https://github.com/opencv/opencv/pull/13395. I tried to write simple code, but failed:

import cv2
import numpy as np

print("OpenCV:", cv2.__version__)

file_name = "../assets/piku01.mov"

# Capture
cap = cv2.VideoCapture(file_name)
cap.set(cv2.CAP_PROP_CONVERT_RGB, 0)# No means...!?

while cap.isOpened():
    ret, frame = cap.read()# Read
    print("frame:", frame.shape)# Can't get alpha channel
    print(frame[0][0])# Removed alpha channel...?
    break

cap.release()

Output:

OpenCV: 4.5.4-dev
frame: (1080, 1920, 3)
[0 0 0]

Any idea?

CodePudding user response:

Thank you all!!
I could get alpha channel from video!!
Awsome!!

import av
import numpy as np

print("PyAV:", av.__version__)

container = av.open("./piku01.mov")
for frame in container.decode(video=0):
    frame = frame.to_ndarray(format="bgra") # BGRA
    print("frame:", frame.shape) # Well done!!

Output:

frame: (1080, 1920, 4)

CodePudding user response:

print("OpenCV:", cv2.__version__)
file_name = "../assets/piku01.mov"

cap = cv2.VideoCapture(file_name)
ret, frame = cap.read()
alpha = frame[:, :, 3]
cap.release()
  • Related