AaronWu901225 commited on
Commit
868c22c
·
verified ·
1 Parent(s): 7842fd9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -31,16 +31,22 @@ def inpaint_image(image, mask_threshold):
31
  _, mask = cv2.threshold(gray_image, mask_threshold, 255, cv2.THRESH_BINARY)
32
  mask = mask.astype(bool)
33
 
34
- # 如果遮罩無效,拋出錯誤
35
  if not mask.any():
36
- return "遮罩生成失敗,請調整遮罩閾值參數。"
 
 
 
37
 
38
  # 使用 biharmonic 方法修復圖像
39
  inpainted = inpaint.inpaint_biharmonic(image, mask, multichannel=True)
40
  return inpainted
41
  except Exception as e:
42
- # 如果發生錯誤,返回錯誤訊息
43
- return f"發生錯誤:{str(e)}"
 
 
 
44
 
45
  # 主應用程式
46
  def app():
 
31
  _, mask = cv2.threshold(gray_image, mask_threshold, 255, cv2.THRESH_BINARY)
32
  mask = mask.astype(bool)
33
 
34
+ # 如果遮罩無效,返回遮罩檢查圖片
35
  if not mask.any():
36
+ error_image = np.zeros_like(image)
37
+ cv2.putText(error_image, "Invalid Mask! Adjust Threshold", (10, 50),
38
+ cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
39
+ return error_image
40
 
41
  # 使用 biharmonic 方法修復圖像
42
  inpainted = inpaint.inpaint_biharmonic(image, mask, multichannel=True)
43
  return inpainted
44
  except Exception as e:
45
+ # 如果發生錯誤,返回錯誤圖片
46
+ error_image = np.zeros((image.shape[0], image.shape[1], 3), dtype=np.uint8)
47
+ cv2.putText(error_image, f"Error: {str(e)}", (10, 50),
48
+ cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
49
+ return error_image
50
 
51
  # 主應用程式
52
  def app():