Spaces:
Starting
Starting
Update app.py
Browse files
app.py
CHANGED
@@ -80,7 +80,7 @@ def predict_depth(image, model):
|
|
80 |
# return model(image)["depth"]
|
81 |
|
82 |
def make_video(video_path, outdir='./vis_video_depth', encoder='vits', remove_bg=False):
|
83 |
-
if encoder not in ["vitl","vitb","vits"]:
|
84 |
encoder = "vits"
|
85 |
|
86 |
model_name = encoder2name[encoder]
|
@@ -210,9 +210,21 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', remove_bg
|
|
210 |
#raw_frame = cv2.cvtColor(raw_frame, cv2.COLOR_BGR2BGRA)
|
211 |
#raw_frame[:, :, 3] = 255
|
212 |
|
213 |
-
if remove_bg ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
if count >= 1: #int(cframes/2):
|
215 |
n = 0 #n = count-int(cframes/2)
|
|
|
216 |
depth_color_bg = cv2.imread(f"f{n}_dmap.png").astype(np.uint8)
|
217 |
raw_frame_bg = cv2.imread(f"f{n}.png").astype(np.uint8)
|
218 |
|
@@ -228,15 +240,15 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', remove_bg
|
|
228 |
print('-median')
|
229 |
print(md_d)
|
230 |
print(md_c)
|
231 |
-
print('-most common')
|
232 |
-
c = Counter(diff_d.flatten())
|
233 |
-
value, cc = c.most_common()[0]
|
234 |
-
print(value)
|
235 |
-
print(cc)
|
236 |
-
c = Counter(diff_c.flatten())
|
237 |
-
value, cc = c.most_common()[0]
|
238 |
-
print(value)
|
239 |
-
print(cc)
|
240 |
print('-')
|
241 |
|
242 |
mask_bg = cv2.inRange(diff_d, np.array([0,0,0]), np.array([md_d,md_d,md_d]))
|
@@ -251,16 +263,6 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', remove_bg
|
|
251 |
raw_frame[cv2.bitwise_and(mask_shadow, mask_bg)>0] = (raw_frame[cv2.bitwise_and(mask_shadow, mask_bg)>0] / 17 + 240).astype(np.uint8)
|
252 |
raw_frame[cv2.bitwise_and(mask_no_shadow, mask_bg)>0] = (255,255,255)
|
253 |
|
254 |
-
thumbnail = cv2.cvtColor(cv2.resize(raw_frame, (16,32)), cv2.COLOR_BGR2GRAY).flatten()
|
255 |
-
if len(thumbnail_old) > 0:
|
256 |
-
diff = thumbnail - thumbnail_old
|
257 |
-
#print(diff)
|
258 |
-
c = Counter(diff)
|
259 |
-
value, cc = c.most_common()[0]
|
260 |
-
if value == 0 and cc > int(16*32*0.8):
|
261 |
-
continue
|
262 |
-
thumbnail_old = thumbnail
|
263 |
-
|
264 |
cv2.imwrite(f"f{count}.png", raw_frame)
|
265 |
orig_frames.append(f"f{count}.png")
|
266 |
|
@@ -1024,7 +1026,7 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
1024 |
find_normals.click(fn=findNormals, inputs=[format_normals], outputs=[normals_out])
|
1025 |
|
1026 |
with gr.Column():
|
1027 |
-
model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
|
1028 |
remove_bg = gr.Checkbox(label="Remove background")
|
1029 |
processed_video = gr.Video(label="Output Video", format="mp4", interactive=False)
|
1030 |
processed_zip = gr.File(label="Output Archive", interactive=False)
|
@@ -1404,7 +1406,7 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
1404 |
render.click(None, inputs=[coords, mesh_order, bgcolor, output_frame, output_mask, selected, output_depth], outputs=None, js=load_model)
|
1405 |
render.click(partial(get_mesh), inputs=[output_frame, output_mask, blur_in, load_all], outputs=[result, result_file, mesh_order])
|
1406 |
|
1407 |
-
example_files = [["./examples/streetview.mp4", "vits", False, example_coords], ["./examples/man-in-museum-reverse.mp4", "vits", True, example_coords]]
|
1408 |
examples = gr.Examples(examples=example_files, fn=on_submit, cache_examples=True, inputs=[input_video, model_type, remove_bg, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|
1409 |
|
1410 |
|
|
|
80 |
# return model(image)["depth"]
|
81 |
|
82 |
def make_video(video_path, outdir='./vis_video_depth', encoder='vits', remove_bg=False):
|
83 |
+
if encoder not in ["vitl","vitb","vits","vitg"]:
|
84 |
encoder = "vits"
|
85 |
|
86 |
model_name = encoder2name[encoder]
|
|
|
210 |
#raw_frame = cv2.cvtColor(raw_frame, cv2.COLOR_BGR2BGRA)
|
211 |
#raw_frame[:, :, 3] = 255
|
212 |
|
213 |
+
if remove_bg == False:
|
214 |
+
thumbnail = cv2.cvtColor(cv2.resize(raw_frame, (16,32)), cv2.COLOR_BGR2GRAY).flatten()
|
215 |
+
if len(thumbnail_old) > 0:
|
216 |
+
diff = thumbnail - thumbnail_old
|
217 |
+
#print(diff)
|
218 |
+
c = Counter(diff)
|
219 |
+
value, cc = c.most_common()[0]
|
220 |
+
if value == 0 and cc > int(16*32*0.8):
|
221 |
+
count += 1
|
222 |
+
continue
|
223 |
+
thumbnail_old = thumbnail
|
224 |
+
else:
|
225 |
if count >= 1: #int(cframes/2):
|
226 |
n = 0 #n = count-int(cframes/2)
|
227 |
+
|
228 |
depth_color_bg = cv2.imread(f"f{n}_dmap.png").astype(np.uint8)
|
229 |
raw_frame_bg = cv2.imread(f"f{n}.png").astype(np.uint8)
|
230 |
|
|
|
240 |
print('-median')
|
241 |
print(md_d)
|
242 |
print(md_c)
|
243 |
+
#print('-most common')
|
244 |
+
#c = Counter(diff_d.flatten())
|
245 |
+
#value, cc = c.most_common()[0]
|
246 |
+
#print(value)
|
247 |
+
#print(cc)
|
248 |
+
#c = Counter(diff_c.flatten())
|
249 |
+
#value, cc = c.most_common()[0]
|
250 |
+
#print(value)
|
251 |
+
#print(cc)
|
252 |
print('-')
|
253 |
|
254 |
mask_bg = cv2.inRange(diff_d, np.array([0,0,0]), np.array([md_d,md_d,md_d]))
|
|
|
263 |
raw_frame[cv2.bitwise_and(mask_shadow, mask_bg)>0] = (raw_frame[cv2.bitwise_and(mask_shadow, mask_bg)>0] / 17 + 240).astype(np.uint8)
|
264 |
raw_frame[cv2.bitwise_and(mask_no_shadow, mask_bg)>0] = (255,255,255)
|
265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
cv2.imwrite(f"f{count}.png", raw_frame)
|
267 |
orig_frames.append(f"f{count}.png")
|
268 |
|
|
|
1026 |
find_normals.click(fn=findNormals, inputs=[format_normals], outputs=[normals_out])
|
1027 |
|
1028 |
with gr.Column():
|
1029 |
+
model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl"), ("giant", "vitg")], type="value", value="vits", label='Model Type')
|
1030 |
remove_bg = gr.Checkbox(label="Remove background")
|
1031 |
processed_video = gr.Video(label="Output Video", format="mp4", interactive=False)
|
1032 |
processed_zip = gr.File(label="Output Archive", interactive=False)
|
|
|
1406 |
render.click(None, inputs=[coords, mesh_order, bgcolor, output_frame, output_mask, selected, output_depth], outputs=None, js=load_model)
|
1407 |
render.click(partial(get_mesh), inputs=[output_frame, output_mask, blur_in, load_all], outputs=[result, result_file, mesh_order])
|
1408 |
|
1409 |
+
example_files = [["./examples/streetview.mp4", "vits", False, example_coords], ["./examples/man-in-museum-reverse-cut.mp4", "vits", True, example_coords]]
|
1410 |
examples = gr.Examples(examples=example_files, fn=on_submit, cache_examples=True, inputs=[input_video, model_type, remove_bg, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|
1411 |
|
1412 |
|