amirgame197 commited on
Commit
e7b81e8
·
verified ·
1 Parent(s): fae67bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -14,9 +14,11 @@ def doo(video):
14
  fps = cap.get(cv2.CAP_PROP_FPS)
15
  frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
16
  frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
 
17
 
18
- writer = None
19
- batch_size = 30
 
20
 
21
  while cap.isOpened():
22
  frames = []
@@ -26,21 +28,17 @@ def doo(video):
26
  break
27
  frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
28
  img = Image.fromarray(frame).convert('RGB')
29
- frames.append(img)
 
30
 
31
  if not frames:
32
  break
33
 
34
- if writer is None:
35
- writer = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'mp4v'), fps, (frame_width, frame_height))
36
-
37
- for img in frames:
38
- out = remover.process(img, type='green')
39
- writer.write(cv2.cvtColor(np.array(out), cv2.COLOR_BGR2RGB))
40
 
41
  cap.release()
42
- if writer:
43
- writer.release()
44
  return 'output.mp4'
45
 
46
  iface = gr.Interface(fn=doo, inputs="video", outputs="video")
 
14
  fps = cap.get(cv2.CAP_PROP_FPS)
15
  frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
16
  frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
17
+ total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
18
 
19
+ writer = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'mp4v'), fps, (frame_width, frame_height))
20
+
21
+ batch_size = 30 # Process 30 frames at a time
22
 
23
  while cap.isOpened():
24
  frames = []
 
28
  break
29
  frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
30
  img = Image.fromarray(frame).convert('RGB')
31
+ out = remover.process(img, type='green')
32
+ frames.append(cv2.cvtColor(np.array(out), cv2.COLOR_BGR2RGB))
33
 
34
  if not frames:
35
  break
36
 
37
+ for frame in frames:
38
+ writer.write(frame)
 
 
 
 
39
 
40
  cap.release()
41
+ writer.release()
 
42
  return 'output.mp4'
43
 
44
  iface = gr.Interface(fn=doo, inputs="video", outputs="video")