Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -194,14 +194,6 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', remove_bg
|
|
194 |
n = 0 #n = count-int(cframes/2)
|
195 |
depth_color_bg = cv2.imread(f"f{n}_dmap.png").astype(np.uint8)
|
196 |
raw_frame_bg = cv2.imread(f"f{n}.png").astype(np.uint8)
|
197 |
-
|
198 |
-
dc = np.float32(depth_color.reshape((-1,3)))
|
199 |
-
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 4, 1.0)
|
200 |
-
K = 16
|
201 |
-
ret,label,center=cv2.kmeans(dc,K,None,criteria,4,cv2.KMEANS_PP_CENTERS)
|
202 |
-
center = np.uint8(center)
|
203 |
-
res = center[label.flatten()]
|
204 |
-
depth_color = res.reshape((depth_color.shape))
|
205 |
|
206 |
diff_d = np.abs(depth_color.astype(np.int16)-depth_color_bg.astype(np.int16))
|
207 |
diff_c = np.abs(raw_frame.astype(np.int16)-raw_frame_bg.astype(np.int16))
|
@@ -581,33 +573,36 @@ def draw_mask(l, t, v, d, evt: gr.EventData):
|
|
581 |
pts = np.array(points, np.int32)
|
582 |
pts = pts.reshape((-1,1,2))
|
583 |
|
584 |
-
scale = 1
|
585 |
-
delta = 0
|
586 |
-
ddepth = cv2.CV_16S
|
587 |
-
|
588 |
if len(edge) == 0 or params["fnum"] != frame_selected or params["l"] != l:
|
589 |
if len(edge) > 0:
|
590 |
d["background"] = cv2.imread(depths[frame_selected]).astype(np.uint8)
|
591 |
|
592 |
bg = cv2.cvtColor(d["background"], cv2.COLOR_RGBA2GRAY)
|
593 |
|
594 |
-
diff = (bg-cv2.cvtColor(gradient, cv2.COLOR_RGBA2GRAY)).astype(np.uint8)
|
595 |
-
mask = cv2.inRange(diff,
|
596 |
#kernel = np.ones((c,c),np.float32)/(c*c)
|
597 |
#mask = cv2.filter2D(mask,-1,kernel)
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
#for i in range(l):
|
609 |
# bg[(bg >= i*255/l) & (bg < (i+1)*255/l)] = i*255/(l-1)
|
610 |
-
bg = cv2.convertScaleAbs(palette[bg]).astype(np.uint8) # Converting image back to uint
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
611 |
bg[mask>0] = 0
|
612 |
bg[bg==255] = 0
|
613 |
|
|
|
194 |
n = 0 #n = count-int(cframes/2)
|
195 |
depth_color_bg = cv2.imread(f"f{n}_dmap.png").astype(np.uint8)
|
196 |
raw_frame_bg = cv2.imread(f"f{n}.png").astype(np.uint8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
diff_d = np.abs(depth_color.astype(np.int16)-depth_color_bg.astype(np.int16))
|
199 |
diff_c = np.abs(raw_frame.astype(np.int16)-raw_frame_bg.astype(np.int16))
|
|
|
573 |
pts = np.array(points, np.int32)
|
574 |
pts = pts.reshape((-1,1,2))
|
575 |
|
|
|
|
|
|
|
|
|
576 |
if len(edge) == 0 or params["fnum"] != frame_selected or params["l"] != l:
|
577 |
if len(edge) > 0:
|
578 |
d["background"] = cv2.imread(depths[frame_selected]).astype(np.uint8)
|
579 |
|
580 |
bg = cv2.cvtColor(d["background"], cv2.COLOR_RGBA2GRAY)
|
581 |
|
582 |
+
diff = np.abs(bg.astype(np.int16)-cv2.cvtColor(gradient, cv2.COLOR_RGBA2GRAY).astype(np.int16)).astype(np.uint8)
|
583 |
+
mask = cv2.inRange(diff, 0, t)
|
584 |
#kernel = np.ones((c,c),np.float32)/(c*c)
|
585 |
#mask = cv2.filter2D(mask,-1,kernel)
|
586 |
+
dilation = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (15-(t*2+1), 15-(t*2+1)), (t, t))
|
587 |
+
mask = cv2.dilate(mask, dilation)
|
588 |
+
|
589 |
+
#indices = np.arange(0,256) # List of all colors
|
590 |
+
#divider = np.linspace(0,255,l+1)[1] # we get a divider
|
591 |
+
#quantiz = np.intp(np.linspace(0,255,l)) # we get quantization colors
|
592 |
+
#color_levels = np.clip(np.intp(indices/divider),0,l-1) # color levels 0,1,2..
|
593 |
+
#palette = quantiz[color_levels]
|
594 |
+
|
|
|
595 |
#for i in range(l):
|
596 |
# bg[(bg >= i*255/l) & (bg < (i+1)*255/l)] = i*255/(l-1)
|
597 |
+
#bg = cv2.convertScaleAbs(palette[bg]).astype(np.uint8) # Converting image back to uint
|
598 |
+
|
599 |
+
bg = np.float32(bg.reshape((-1,3)))
|
600 |
+
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 4, 1.0)
|
601 |
+
ret,label,center=cv2.kmeans(bg,l,None,criteria,4,cv2.KMEANS_PP_CENTERS)
|
602 |
+
center = np.uint8(center)
|
603 |
+
res = center[label.flatten()]
|
604 |
+
bg = res.reshape((bg.shape))
|
605 |
+
|
606 |
bg[mask>0] = 0
|
607 |
bg[bg==255] = 0
|
608 |
|