Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,7 @@ from vincenty import vincenty
|
|
15 |
import json
|
16 |
from collections import Counter
|
17 |
import mediapy
|
|
|
18 |
|
19 |
#from depth_anything.dpt import DepthAnything
|
20 |
#from depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
|
@@ -128,6 +129,7 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data
|
|
128 |
filenames.sort()
|
129 |
|
130 |
# os.makedirs(outdir, exist_ok=True)
|
|
|
131 |
|
132 |
for k, filename in enumerate(filenames):
|
133 |
file_size = os.path.getsize(filename)/1024/1024
|
@@ -152,7 +154,7 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data
|
|
152 |
#out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"avc1"), frame_rate, (output_width, frame_height))
|
153 |
#fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
154 |
#out = cv2.VideoWriter(output_path, fourcc, frame_rate, (output_width, frame_height))
|
155 |
-
|
156 |
count = 0
|
157 |
n = 0
|
158 |
depth_frames = []
|
@@ -236,6 +238,22 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data
|
|
236 |
|
237 |
cv2.imwrite(f"f{count}_mask.png", depth_gray)
|
238 |
masks.append(f"f{count}_mask.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
count += 1
|
240 |
|
241 |
final_vid = create_video(orig_frames, frame_rate, "orig")
|
@@ -942,18 +960,7 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
942 |
load_all = gr.Checkbox(label="Load all")
|
943 |
|
944 |
with gr.Group():
|
945 |
-
|
946 |
-
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
947 |
-
var evt = document.createEvent(\"Event\");
|
948 |
-
evt.initEvent(\"click\", true, false);
|
949 |
-
document.getElementById(\"reset_cam\").dispatchEvent(evt);
|
950 |
-
}
|
951 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.fov = this.value;
|
952 |
-
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.fov;
|
953 |
-
|
954 |
-
document.getElementById(\"model3D\").getElementsByTagName(\"canvas\")[0].style.filter = \"blur(\" + BABYLON.Engine.LastCreatedScene.getNodes()[parseInt(document.getElementById(\"fnum\").getElementsByTagName(\"input\")[0].value)+1].material.pointSize/2.0*Math.sqrt(2.0) + \"px)\";
|
955 |
-
'/><span>0.8</span>""")
|
956 |
-
camera = gr.HTML(value="""<a href='#' id='reset_cam' style='color:white' onclick='
|
957 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
958 |
BABYLON.Engine.LastCreatedScene.activeCamera.metadata = {
|
959 |
screenshot: true,
|
@@ -970,7 +977,18 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
970 |
document.getElementById(\"model3D\").getElementsByTagName(\"canvas\")[0].oncontextmenu = function(e){e.preventDefault();}
|
971 |
document.getElementById(\"model3D\").getElementsByTagName(\"canvas\")[0].ondrag = function(e){e.preventDefault();}
|
972 |
'>Reset camera</a>""")
|
973 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
974 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
975 |
var evt = document.createEvent(\"Event\");
|
976 |
evt.initEvent(\"click\", true, false);
|
@@ -979,7 +997,7 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
979 |
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.contrast = this.value;
|
980 |
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.contrast;
|
981 |
'/><span>1.0</span>""")
|
982 |
-
exposure = gr.HTML(value="""<label for='exposure'>Exposure</label><input id='exposure' type='range' style='width:256px;height:1em;' value='1.0' min='0' max='2' step='0.001' oninput='
|
983 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
984 |
var evt = document.createEvent(\"Event\");
|
985 |
evt.initEvent(\"click\", true, false);
|
|
|
15 |
import json
|
16 |
from collections import Counter
|
17 |
import mediapy
|
18 |
+
from pymatting import cutout
|
19 |
|
20 |
#from depth_anything.dpt import DepthAnything
|
21 |
#from depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
|
|
|
129 |
filenames.sort()
|
130 |
|
131 |
# os.makedirs(outdir, exist_ok=True)
|
132 |
+
global masks
|
133 |
|
134 |
for k, filename in enumerate(filenames):
|
135 |
file_size = os.path.getsize(filename)/1024/1024
|
|
|
154 |
#out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"avc1"), frame_rate, (output_width, frame_height))
|
155 |
#fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
156 |
#out = cv2.VideoWriter(output_path, fourcc, frame_rate, (output_width, frame_height))
|
157 |
+
|
158 |
count = 0
|
159 |
n = 0
|
160 |
depth_frames = []
|
|
|
238 |
|
239 |
cv2.imwrite(f"f{count}_mask.png", depth_gray)
|
240 |
masks.append(f"f{count}_mask.png")
|
241 |
+
|
242 |
+
depth_gray_trimap = np.zeros(depth_gray.shape[:2], np.uint8)
|
243 |
+
depth_gray_trimap[depth_gray==128] = 0
|
244 |
+
depth_gray_trimap[depth_gray==129] = 255
|
245 |
+
depth_gray_trimap[depth_gray==131] = 127
|
246 |
+
|
247 |
+
cv2.imwrite(f"f{count}_trimap.png", depth_gray_trimap)
|
248 |
+
|
249 |
+
cutout(
|
250 |
+
# input image path
|
251 |
+
f"f{count}.png",
|
252 |
+
# input trimap path
|
253 |
+
f"f{count}_trimap.png",
|
254 |
+
# output cutout path
|
255 |
+
f"f{count}.png")
|
256 |
+
|
257 |
count += 1
|
258 |
|
259 |
final_vid = create_video(orig_frames, frame_rate, "orig")
|
|
|
960 |
load_all = gr.Checkbox(label="Load all")
|
961 |
|
962 |
with gr.Group():
|
963 |
+
camera = gr.HTML(value="""<a href='#' id='reset_cam' style='float:right;color:white' onclick='
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
964 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
965 |
BABYLON.Engine.LastCreatedScene.activeCamera.metadata = {
|
966 |
screenshot: true,
|
|
|
977 |
document.getElementById(\"model3D\").getElementsByTagName(\"canvas\")[0].oncontextmenu = function(e){e.preventDefault();}
|
978 |
document.getElementById(\"model3D\").getElementsByTagName(\"canvas\")[0].ondrag = function(e){e.preventDefault();}
|
979 |
'>Reset camera</a>""")
|
980 |
+
html = gr.HTML(value="""<label for='zoom' style='width:5em'>Zoom</label><input id='zoom' type='range' style='width:256px;height:1em;' value='0.8' min='0.157' max='1.57' step='0.001' oninput='
|
981 |
+
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
982 |
+
var evt = document.createEvent(\"Event\");
|
983 |
+
evt.initEvent(\"click\", true, false);
|
984 |
+
document.getElementById(\"reset_cam\").dispatchEvent(evt);
|
985 |
+
}
|
986 |
+
BABYLON.Engine.LastCreatedScene.activeCamera.fov = this.value;
|
987 |
+
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.fov;
|
988 |
+
|
989 |
+
document.getElementById(\"model3D\").getElementsByTagName(\"canvas\")[0].style.filter = \"blur(\" + BABYLON.Engine.LastCreatedScene.getNodes()[parseInt(document.getElementById(\"fnum\").getElementsByTagName(\"input\")[0].value)+1].material.pointSize/2.0*Math.sqrt(2.0) + \"px)\";
|
990 |
+
'/><span>0.8</span>""")
|
991 |
+
contrast = gr.HTML(value="""<label for='contrast' style='width:5em'>Contrast</label><input id='contrast' type='range' style='width:256px;height:1em;' value='1.0' min='0' max='2' step='0.001' oninput='
|
992 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
993 |
var evt = document.createEvent(\"Event\");
|
994 |
evt.initEvent(\"click\", true, false);
|
|
|
997 |
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.contrast = this.value;
|
998 |
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.contrast;
|
999 |
'/><span>1.0</span>""")
|
1000 |
+
exposure = gr.HTML(value="""<label for='exposure' style='width:5em'>Exposure</label><input id='exposure' type='range' style='width:256px;height:1em;' value='1.0' min='0' max='2' step='0.001' oninput='
|
1001 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
1002 |
var evt = document.createEvent(\"Event\");
|
1003 |
evt.initEvent(\"click\", true, false);
|