freealise commited on
Commit
7efd13c
1 Parent(s): 270bad9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -341,15 +341,20 @@ def draw_mask(v, d, evt: gr.EventData):
341
  w = int(vv[2])
342
  h = int(vv[3])
343
 
344
- mask = np.zeros(d["background"].shape[:2], np.uint8)
345
- bgdModel = np.zeros((1,65), np.float64)
346
- fgdModel = np.zeros((1,65), np.float64)
347
- rect = (x, y, w, h)
348
- mask = cv2.grabCut(d["background"], mask, rect, bgdModel, fgdModel, 5, cv2.GC_INIT_WITH_RECT)
349
- print(mask)
350
- mask0 = mask[0]
351
- newmask = np.where((mask0==2)|(mask0==0),1,0).astype('uint8')
352
- d["composite"] = rgb*newmask[:,:,np.newaxis]
 
 
 
 
 
353
 
354
  return gr.ImageEditor(value=d)
355
 
 
341
  w = int(vv[2])
342
  h = int(vv[3])
343
 
344
+ scale = 1
345
+ delta = 0
346
+ ddepth = cv.CV_16S
347
+
348
+ gray = cv.cvtColor(d["background"], cv.COLOR_BGR2GRAY)
349
+ grad_x = cv.Sobel(gray, ddepth, 1, 0, ksize=5, scale=scale, delta=delta, borderType=cv.BORDER_DEFAULT)
350
+ # Gradient-Y
351
+ # grad_y = cv.Scharr(gray,ddepth,0,1)
352
+ grad_y = cv.Sobel(gray, ddepth, 0, 1, ksize=5, scale=scale, delta=delta, borderType=cv.BORDER_DEFAULT)
353
+ abs_grad_x = cv.convertScaleAbs(grad_x)
354
+ abs_grad_y = cv.convertScaleAbs(grad_y)
355
+
356
+ grad = cv.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0)
357
+ d["composite"] = cv.cvtColor(255-grad, cv.COLOR_GRAY2RGB)
358
 
359
  return gr.ImageEditor(value=d)
360