freealise commited on
Commit
55a1244
1 Parent(s): b166ebd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -344,20 +344,31 @@ def draw_mask(ksize, th, v, d, evt: gr.EventData):
344
  w = int(vv[2])
345
  h = int(vv[3])
346
 
347
- scale = 1
348
- delta = 0
349
- ddepth = cv2.CV_16S
 
 
 
 
 
 
 
 
 
 
 
350
 
351
- gray = cv2.cvtColor(d["background"], cv2.COLOR_BGR2GRAY)
352
- grad_x = cv2.Sobel(gray, ddepth, 1, 0, ksize=ksize, scale=scale, delta=delta, borderType=cv2.BORDER_DEFAULT)
353
  # Gradient-Y
354
  # grad_y = cv2.Scharr(gray,ddepth,0,1)
355
- grad_y = cv2.Sobel(gray, ddepth, 0, 1, ksize=ksize, scale=scale, delta=delta, borderType=cv2.BORDER_DEFAULT)
356
- abs_grad_x = cv2.convertScaleAbs(grad_x)
357
- abs_grad_y = cv2.convertScaleAbs(grad_y)
358
 
359
- grad = cv2.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0)
360
- bw = cv2.threshold(255-grad, th, 255, cv2.THRESH_BINARY)[1]
361
 
362
  d["background"] = cv2.cvtColor(bw, cv2.COLOR_GRAY2RGB)
363
  d["composite"] = cv2.cvtColor(bw, cv2.COLOR_GRAY2RGB)
 
344
  w = int(vv[2])
345
  h = int(vv[3])
346
 
347
+ src = d["background"]
348
+ src_gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
349
+ ratio = 3
350
+ kernel_size = ksize
351
+ low_threshold = th
352
+ img_blur = cv.blur(src_gray, (3,3))
353
+ detected_edges = cv.Canny(img_blur, low_threshold, low_threshold*ratio, kernel_size)
354
+ mask = detected_edges != 0
355
+ dst = src * (mask[:,:,None].astype(src.dtype))
356
+
357
+
358
+ #scale = 1
359
+ #delta = 0
360
+ #ddepth = cv2.CV_16S
361
 
362
+ #gray = cv2.cvtColor(d["background"], cv2.COLOR_BGR2GRAY)
363
+ #grad_x = cv2.Sobel(gray, ddepth, 1, 0, ksize=ksize, scale=scale, delta=delta, borderType=cv2.BORDER_DEFAULT)
364
  # Gradient-Y
365
  # grad_y = cv2.Scharr(gray,ddepth,0,1)
366
+ #grad_y = cv2.Sobel(gray, ddepth, 0, 1, ksize=ksize, scale=scale, delta=delta, borderType=cv2.BORDER_DEFAULT)
367
+ #abs_grad_x = cv2.convertScaleAbs(grad_x)
368
+ #abs_grad_y = cv2.convertScaleAbs(grad_y)
369
 
370
+ #grad = cv2.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0)
371
+ bw = cv2.threshold(255-dst, th, 255, cv2.THRESH_BINARY)[1]
372
 
373
  d["background"] = cv2.cvtColor(bw, cv2.COLOR_GRAY2RGB)
374
  d["composite"] = cv2.cvtColor(bw, cv2.COLOR_GRAY2RGB)