sahar-yaccov commited on
Commit
bbaf394
verified
1 Parent(s): 1d6be01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -33,18 +33,22 @@ def is_ffmpeg_available():
33
  except (subprocess.CalledProcessError, FileNotFoundError):
34
  return False
35
 
36
- def remove_watermark_from_frame(frame, mask_coords=None):
37
- mask = np.zeros(frame.shape[:2], np.uint8)
38
- if mask_coords:
39
- x1, y1 = mask_coords[0]
40
- x2, y2 = mask_coords[1]
41
- x1, x2 = sorted([x1, x2])
42
- y1, y2 = sorted([y1, y2])
43
- mask[y1:y2, x1:x2] = 255
44
  else:
45
- h, w = frame.shape[:2]
46
- mask[0:50, 0:w] = 255
47
- return cv2.inpaint(frame, mask, 10, cv2.INPAINT_NS)
 
 
 
 
48
 
49
  def extract_first_frame(video_file_path):
50
  cap = cv2.VideoCapture(video_file_path)
@@ -61,6 +65,7 @@ def frames_to_video(frames, output_path, fps, frame_size):
61
  out.write(frame)
62
  out.release()
63
  return True
 
64
 
65
  def remove_watermark_process(video_path, coords_input=None):
66
  if not is_ffmpeg_available():
 
33
  except (subprocess.CalledProcessError, FileNotFoundError):
34
  return False
35
 
36
+
37
+ def remove_watermark_from_frame(frame, mask_coords):
38
+ if mask_coords is None:
39
+ return frame
40
+
41
+ # 讘讚讬拽讛 讗诐 谞砖诇讞 tuple 专讙讬诇 (x1, y1, x2, y2)
42
+ if isinstance(mask_coords[0], int):
43
+ x1, y1, x2, y2 = mask_coords
44
  else:
45
+ (x1, y1), (x2, y2) = mask_coords
46
+
47
+ mask = np.zeros(frame.shape[:2], dtype=np.uint8)
48
+ mask[y1:y2, x1:x2] = 255
49
+ frame = cv2.inpaint(frame, mask, 3, cv2.INPAINT_TELEA)
50
+ return frame
51
+
52
 
53
  def extract_first_frame(video_file_path):
54
  cap = cv2.VideoCapture(video_file_path)
 
65
  out.write(frame)
66
  out.release()
67
  return True
68
+
69
 
70
  def remove_watermark_process(video_path, coords_input=None):
71
  if not is_ffmpeg_available():