File size: 1,198 Bytes
de2aa9b
ba4d1a9
 
 
 
ce6434e
ba4d1a9
6ef9294
ce6434e
6ef9294
ce6434e
 
 
6ef9294
ce6434e
 
6ef9294
 
ce6434e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ef9294
ce6434e
 
 
de2aa9b
6ef9294
ce6434e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr
import cv2
import numpy as np
from transparent_background import Remover

remover = Remover(mode='fast')  # Custom setting

def doo(video):
    cap = cv2.VideoCapture(video)  # Video reader for input
    fps = cap.get(cv2.CAP_PROP_FPS)

    processed_frames = []  # List to store processed frames

    while cap.isOpened():
        ret, frame = cap.read()  # Read video

        if ret is False:
            break

        # Assuming frame is a NumPy array (e.g., shape: (height, width, 3))
        # Perform background removal using the model
        # Replace this placeholder code with actual model inference

        # Example: Apply a simple threshold to create a binary mask
        gray_frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
        _, mask = cv2.threshold(gray_frame, 200, 255, cv2.THRESH_BINARY)

        # Create a masked frame
        masked_frame = cv2.bitwise_and(frame, frame, mask=mask)

        # Append the processed frame to the output
        processed_frames.append(masked_frame)

    cap.release()

    # Return the list of processed frames
    return processed_frames

iface = gr.Interface(fn=doo, inputs="video", outputs="video")
iface.launch()