amirgame197 commited on
Commit
e6399c3
1 Parent(s): ce6434e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import cv2
3
  import numpy as np
 
4
  from transparent_background import Remover
5
 
6
  remover = Remover(mode='fast') # Custom setting
@@ -17,19 +18,17 @@ def doo(video):
17
  if ret is False:
18
  break
19
 
20
- # Assuming frame is a NumPy array (e.g., shape: (height, width, 3))
21
- # Perform background removal using the model
22
- # Replace this placeholder code with actual model inference
23
 
24
- # Example: Apply a simple threshold to create a binary mask
25
- gray_frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
26
- _, mask = cv2.threshold(gray_frame, 200, 255, cv2.THRESH_BINARY)
27
 
28
- # Create a masked frame
29
- masked_frame = cv2.bitwise_and(frame, frame, mask=mask)
30
 
31
- # Append the processed frame to the output
32
- processed_frames.append(masked_frame)
33
 
34
  cap.release()
35
 
 
1
  import gradio as gr
2
  import cv2
3
  import numpy as np
4
+ from PIL import Image
5
  from transparent_background import Remover
6
 
7
  remover = Remover(mode='fast') # Custom setting
 
18
  if ret is False:
19
  break
20
 
21
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
22
+ img = Image.fromarray(frame).convert('RGB')
 
23
 
24
+ # Process the frame using the transparent-background model
25
+ out = remover.process(img, type='map') # Same as image, except for 'rgba'
 
26
 
27
+ # Convert the processed frame back to a NumPy array
28
+ processed_frame = np.array(out)
29
 
30
+ # Append the processed frame to the list
31
+ processed_frames.append(processed_frame)
32
 
33
  cap.release()
34