|
import gradio as gr |
|
import cv2 |
|
import numpy as np |
|
from PIL import Image |
|
from transparent_background import Remover |
|
|
|
remover = Remover(mode='fast') |
|
|
|
def doo(video): |
|
cap = cv2.VideoCapture(video) |
|
fps = cap.get(cv2.CAP_PROP_FPS) |
|
|
|
processed_frames = [] |
|
|
|
while cap.isOpened(): |
|
ret, frame = cap.read() |
|
|
|
if ret is False: |
|
break |
|
|
|
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) |
|
img = Image.fromarray(frame).convert('RGB') |
|
|
|
|
|
out = remover.process(img, type='map') |
|
|
|
|
|
processed_frame = np.array(out) |
|
|
|
|
|
processed_frames.append(processed_frame) |
|
|
|
cap.release() |
|
|
|
|
|
return processed_frames |
|
|
|
iface = gr.Interface(fn=doo, inputs="video", outputs="video") |
|
iface.launch() |
|
|