Update app.py
Browse files
app.py
CHANGED
|
@@ -46,9 +46,6 @@ backups = []
|
|
| 46 |
depths = []
|
| 47 |
masks = []
|
| 48 |
locations = []
|
| 49 |
-
mesh = []
|
| 50 |
-
mesh_n = []
|
| 51 |
-
scene = None
|
| 52 |
|
| 53 |
def zip_files(files_in, files_out):
|
| 54 |
with ZipFile("depth_result.zip", "w") as zipObj:
|
|
@@ -285,118 +282,9 @@ def depth_edges_mask(depth):
|
|
| 285 |
mask = depth_grad > 0.05
|
| 286 |
return mask
|
| 287 |
|
| 288 |
-
def pano_depth_to_world_points(depth):
|
| 289 |
-
"""
|
| 290 |
-
360 depth to world points
|
| 291 |
-
given 2D depth is an equirectangular projection of a spherical image
|
| 292 |
-
Treat depth as radius
|
| 293 |
-
longitude : -pi to pi
|
| 294 |
-
latitude : -pi/2 to pi/2
|
| 295 |
-
"""
|
| 296 |
-
|
| 297 |
-
# Convert depth to radius
|
| 298 |
-
radius = (255 - depth.flatten())
|
| 299 |
-
|
| 300 |
-
lon = np.linspace(0, np.pi*2, depth.shape[1])
|
| 301 |
-
lat = np.linspace(0, np.pi, depth.shape[0])
|
| 302 |
-
lon, lat = np.meshgrid(lon, lat)
|
| 303 |
-
lon = lon.flatten()
|
| 304 |
-
lat = lat.flatten()
|
| 305 |
-
|
| 306 |
-
pts3d = [[0,0,0]]
|
| 307 |
-
uv = [[0,0]]
|
| 308 |
-
nl = [[0,0,0]]
|
| 309 |
-
for i in range(0, 1): #(0,2)
|
| 310 |
-
for j in range(0, 1): #(0,2)
|
| 311 |
-
#rnd_lon = (np.random.rand(depth.shape[0]*depth.shape[1]) - 0.5) / 8
|
| 312 |
-
#rnd_lat = (np.random.rand(depth.shape[0]*depth.shape[1]) - 0.5) / 8
|
| 313 |
-
d_lon = lon + i/2 * np.pi*2 / depth.shape[1]
|
| 314 |
-
d_lat = lat + j/2 * np.pi / depth.shape[0]
|
| 315 |
-
|
| 316 |
-
nx = np.cos(d_lon) * np.sin(d_lat)
|
| 317 |
-
ny = np.cos(d_lat)
|
| 318 |
-
nz = np.sin(d_lon) * np.sin(d_lat)
|
| 319 |
-
|
| 320 |
-
# Convert to cartesian coordinates
|
| 321 |
-
x = radius * nx
|
| 322 |
-
y = radius * ny
|
| 323 |
-
z = radius * nz
|
| 324 |
-
|
| 325 |
-
pts = np.stack([x, y, z], axis=1)
|
| 326 |
-
uvs = np.stack([lon/np.pi/2, lat/np.pi], axis=1)
|
| 327 |
-
nls = np.stack([-nx, -ny, -nz], axis=1)
|
| 328 |
-
|
| 329 |
-
pts3d = np.concatenate((pts3d, pts), axis=0)
|
| 330 |
-
uv = np.concatenate((uv, uvs), axis=0)
|
| 331 |
-
nl = np.concatenate((nl, nls), axis=0)
|
| 332 |
-
#print(f'i: {i}, j: {j}')
|
| 333 |
-
j = j+1
|
| 334 |
-
i = i+1
|
| 335 |
-
|
| 336 |
-
return [pts3d, uv, nl]
|
| 337 |
-
|
| 338 |
def rgb2gray(rgb):
|
| 339 |
return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
|
| 340 |
|
| 341 |
-
def get_mesh(image, depth, blur_data, loadall):
|
| 342 |
-
global depths
|
| 343 |
-
global pcolors
|
| 344 |
-
global frame_selected
|
| 345 |
-
global mesh
|
| 346 |
-
global mesh_n
|
| 347 |
-
global scene
|
| 348 |
-
if loadall == False:
|
| 349 |
-
mesh = []
|
| 350 |
-
mesh_n = []
|
| 351 |
-
fnum = frame_selected
|
| 352 |
-
|
| 353 |
-
#print(image[fnum][0])
|
| 354 |
-
#print(depth["composite"])
|
| 355 |
-
|
| 356 |
-
depthc = cv2.imread(depths[frame_selected], cv2.IMREAD_UNCHANGED).astype(np.uint8)
|
| 357 |
-
blur_img = blur_image(cv2.imread(image[fnum][0], cv2.IMREAD_UNCHANGED).astype(np.uint8), depthc, blur_data)
|
| 358 |
-
gdepth = cv2.cvtColor(depthc, cv2.COLOR_RGB2GRAY) #rgb2gray(depthc)
|
| 359 |
-
|
| 360 |
-
print('depth to gray - ok')
|
| 361 |
-
points = pano_depth_to_world_points(gdepth)
|
| 362 |
-
pts3d = points[0]
|
| 363 |
-
uv = points[1]
|
| 364 |
-
nl = points[2]
|
| 365 |
-
print('radius from depth - ok')
|
| 366 |
-
|
| 367 |
-
# Create a trimesh mesh from the points
|
| 368 |
-
# Each pixel is connected to its 4 neighbors
|
| 369 |
-
# colors are the RGB values of the image
|
| 370 |
-
uvs = uv.reshape(-1, 2)
|
| 371 |
-
#print(uvs)
|
| 372 |
-
#verts = pts3d.reshape(-1, 3)
|
| 373 |
-
verts = [[0,0,0]]
|
| 374 |
-
normals = nl.reshape(-1, 3)
|
| 375 |
-
rgba = cv2.cvtColor(blur_img, cv2.COLOR_RGB2RGBA)
|
| 376 |
-
colors = rgba.reshape(-1, 4)
|
| 377 |
-
clrs = [[128,128,128,0]]
|
| 378 |
-
|
| 379 |
-
#for i in range(0,1): #(0,4)
|
| 380 |
-
#clrs = np.concatenate((clrs, colors), axis=0)
|
| 381 |
-
#i = i+1
|
| 382 |
-
#verts, clrs
|
| 383 |
-
|
| 384 |
-
#pcd = o3d.geometry.TriangleMesh.create_tetrahedron()
|
| 385 |
-
#pcd.compute_vertex_normals()
|
| 386 |
-
#pcd.paint_uniform_color((1.0, 1.0, 1.0))
|
| 387 |
-
#mesh.append(pcd)
|
| 388 |
-
#print(mesh[len(mesh)-1])
|
| 389 |
-
if not str(fnum) in mesh_n:
|
| 390 |
-
mesh_n.append(str(fnum))
|
| 391 |
-
print('mesh - ok')
|
| 392 |
-
|
| 393 |
-
# Save as glb
|
| 394 |
-
#glb_file = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)
|
| 395 |
-
#o3d.io.write_triangle_mesh(glb_file.name, pcd)
|
| 396 |
-
#print('file - ok')
|
| 397 |
-
return "./TriangleWithoutIndices.gltf", ",".join(mesh_n)
|
| 398 |
-
|
| 399 |
-
|
| 400 |
def blur_image(image, depth, blur_data):
|
| 401 |
blur_a = blur_data.split()
|
| 402 |
#print(f'blur data {blur_data}')
|
|
@@ -565,254 +453,11 @@ def draw_mask(o, b, v, d, evt: gr.EventData):
|
|
| 565 |
|
| 566 |
|
| 567 |
load_model="""
|
| 568 |
-
async(
|
| 569 |
var intv = setInterval(function(){
|
| 570 |
-
if (document.getElementById("
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
BABYLON.Engine.LastCreatedScene.onAfterRenderObservable.add(function() { //onDataLoadedObservable
|
| 574 |
-
|
| 575 |
-
var then = new Date().getTime();
|
| 576 |
-
var now, delta;
|
| 577 |
-
const interval = 1000 / 25;
|
| 578 |
-
const tolerance = 0.1;
|
| 579 |
-
|
| 580 |
-
BABYLON.Engine.LastCreatedScene.getEngine().stopRenderLoop();
|
| 581 |
-
BABYLON.Engine.LastCreatedScene.getEngine().runRenderLoop(function () {
|
| 582 |
-
now = new Date().getTime();
|
| 583 |
-
delta = now - then;
|
| 584 |
-
then = now - (delta % interval);
|
| 585 |
-
if (delta >= interval - tolerance) {
|
| 586 |
-
BABYLON.Engine.LastCreatedScene.render();
|
| 587 |
-
}
|
| 588 |
-
});
|
| 589 |
-
|
| 590 |
-
BABYLON.Engine.LastCreatedScene.getEngine().setHardwareScalingLevel(1.0);
|
| 591 |
-
BABYLON.Engine.LastCreatedScene.clearColor = new BABYLON.Color4(255,255,255,255);
|
| 592 |
-
BABYLON.Engine.LastCreatedScene.ambientColor = new BABYLON.Color4(255,255,255,255);
|
| 593 |
-
//BABYLON.Engine.LastCreatedScene.autoClear = false;
|
| 594 |
-
//BABYLON.Engine.LastCreatedScene.autoClearDepthAndStencil = false;
|
| 595 |
-
/*for (var i=0; i<BABYLON.Engine.LastCreatedScene.getNodes().length; i++) {
|
| 596 |
-
if (BABYLON.Engine.LastCreatedScene.getNodes()[i].material) {
|
| 597 |
-
BABYLON.Engine.LastCreatedScene.getNodes()[i].material.pointSize = Math.ceil(Math.log2(Math.PI/document.getElementById("zoom").value));
|
| 598 |
-
}
|
| 599 |
-
}*/
|
| 600 |
-
BABYLON.Engine.LastCreatedScene.getAnimationRatio();
|
| 601 |
-
});
|
| 602 |
-
|
| 603 |
-
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
| 604 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata = {
|
| 605 |
-
pipeline: new BABYLON.DefaultRenderingPipeline("default", true, BABYLON.Engine.LastCreatedScene, [BABYLON.Engine.LastCreatedScene.activeCamera])
|
| 606 |
-
}
|
| 607 |
-
}
|
| 608 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.samples = 4;
|
| 609 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.contrast = 1.0;
|
| 610 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure = 1.0;
|
| 611 |
-
|
| 612 |
-
//BABYLON.Engine.LastCreatedScene.activeCamera.detachControl(document.getElementById("model3D").getElementsByTagName("canvas")[0]);
|
| 613 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.inertia = 0.0;
|
| 614 |
-
//pan
|
| 615 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.panningInertia = 0.0;
|
| 616 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.panningDistanceLimit = 16;
|
| 617 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.panningSensibility = 16;
|
| 618 |
-
//zoom
|
| 619 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.pinchDeltaPercentage = 1/256;
|
| 620 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.wheelDeltaPercentage = 1/256;
|
| 621 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.upperRadiusLimit = (1.57-0.157)*16;
|
| 622 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.lowerRadiusLimit = 0.0;
|
| 623 |
-
//BABYLON.Engine.LastCreatedScene.activeCamera.attachControl(document.getElementById("model3D").getElementsByTagName("canvas")[0], false);
|
| 624 |
-
|
| 625 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.fov = document.getElementById("zoom").value;
|
| 626 |
-
|
| 627 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].style.filter = "blur(" + Math.ceil(Math.log2(Math.PI/document.getElementById("zoom").value))/2.0*Math.sqrt(2.0) + "px)";
|
| 628 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].oncontextmenu = function(e){e.preventDefault();}
|
| 629 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].ondrag = function(e){e.preventDefault();}
|
| 630 |
-
|
| 631 |
-
document.getElementById("model3D").appendChild(document.getElementById("compass_box"));
|
| 632 |
-
window.coords = JSON.parse(document.getElementById("coords").getElementsByTagName("textarea")[0].value);
|
| 633 |
-
window.counter = 0;
|
| 634 |
-
|
| 635 |
-
if (o.indexOf(""+n) < 0) {
|
| 636 |
-
if (o != "") { o += ","; }
|
| 637 |
-
o += n;
|
| 638 |
-
}
|
| 639 |
-
//alert(o);
|
| 640 |
-
var o_ = o.split(",");
|
| 641 |
-
var q = BABYLON.Engine.LastCreatedScene.meshes;
|
| 642 |
-
for(i = 0; i < q.length; i++) {
|
| 643 |
-
let mesh = q[i];
|
| 644 |
-
mesh.dispose(false, true);
|
| 645 |
-
}
|
| 646 |
-
var dome = [];
|
| 647 |
-
/*for (var j=0; j<o_.length; j++) {
|
| 648 |
-
o_[j] = parseInt(o_[j]);
|
| 649 |
-
dome[j] = new BABYLON.PhotoDome("dome"+j, p[o_[j]].image.url,
|
| 650 |
-
{
|
| 651 |
-
resolution: 16,
|
| 652 |
-
size: 512
|
| 653 |
-
}, BABYLON.Engine.LastCreatedScene);
|
| 654 |
-
var q = BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-2]._children;
|
| 655 |
-
for(i = 0; i < q.length; i++) {
|
| 656 |
-
let mesh = q[i];
|
| 657 |
-
mesh.dispose(false, true);
|
| 658 |
-
}
|
| 659 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].name = "dome"+j;
|
| 660 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].scaling.z = -1;
|
| 661 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].alphaIndex = o_.length-j;
|
| 662 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].visibility = 0.9999;
|
| 663 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.diffuseTexture.hasAlpha = true;
|
| 664 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.useAlphaFromDiffuseTexture = true;
|
| 665 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].applyDisplacementMap(m[o_[j]].url, 0, 255, function(m){try{alert(BABYLON.Engine.Version);}catch(e){alert(e);}}, null, null, true, function(e){alert(e);});
|
| 666 |
-
|
| 667 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].rotationQuaternion = null;
|
| 668 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].position.z = coords[o_[j]].lat;
|
| 669 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].position.x = coords[o_[j]].lng;
|
| 670 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].rotation.y = coords[o_[j]].heading / 180 * Math.PI;
|
| 671 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].rotation.z = -coords[o_[j]].pitch / 180 * Math.PI;
|
| 672 |
-
}*/
|
| 673 |
-
|
| 674 |
-
if (s == false) {
|
| 675 |
-
v_url = document.getElementById("output_video").getElementsByTagName("video")[0].src;
|
| 676 |
-
} else {
|
| 677 |
-
v_url = document.getElementById("depth_video").getElementsByTagName("video")[0].src;
|
| 678 |
-
}
|
| 679 |
-
window.videoDome = new BABYLON.VideoDome(
|
| 680 |
-
"videoDome", [v_url],
|
| 681 |
-
{
|
| 682 |
-
resolution: 16,
|
| 683 |
-
size: 512,
|
| 684 |
-
clickToPlay: false,
|
| 685 |
-
}, BABYLON.Engine.LastCreatedScene
|
| 686 |
-
);
|
| 687 |
-
var q = BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-2]._children;
|
| 688 |
-
for (i = 0; i < q.length; i++) {
|
| 689 |
-
let mesh = q[i];
|
| 690 |
-
mesh.dispose(false, true);
|
| 691 |
-
}
|
| 692 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].rotationQuaternion = null;
|
| 693 |
-
//BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].position.z = coords[counter].lat;
|
| 694 |
-
//BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].position.x = coords[counter].lng;
|
| 695 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].rotation.y = coords[counter].heading / 180 * Math.PI;
|
| 696 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].rotation.z = -coords[counter].pitch / 180 * Math.PI;
|
| 697 |
-
|
| 698 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].scaling.z = -1;
|
| 699 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.diffuseTexture.hasAlpha = true;
|
| 700 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.useAlphaFromDiffuseTexture = true;
|
| 701 |
-
//BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.emissiveTexture = videoDome.videoTexture;
|
| 702 |
-
//BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.emissiveTexture.hasAlpha = true;
|
| 703 |
-
//BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.useAlphaFromEmissiveTexture = true;
|
| 704 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].alphaIndex = 1;
|
| 705 |
-
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].visibility = 0.9999;
|
| 706 |
-
|
| 707 |
-
window.md = false;
|
| 708 |
-
window.rd = false;
|
| 709 |
-
window.compass = document.getElementById("compass");
|
| 710 |
-
window.x = 0;
|
| 711 |
-
window.y = 0;
|
| 712 |
-
window.xold = 0;
|
| 713 |
-
window.yold = 0;
|
| 714 |
-
window.buffer = null;
|
| 715 |
-
window.bufferCanvas = document.createElement("canvas");
|
| 716 |
-
window.ctx = bufferCanvas.getContext("2d", { willReadFrequently: true });
|
| 717 |
-
window.video = document.getElementById("depth_video").getElementsByTagName("video")[0];
|
| 718 |
-
window.parallax = 0;
|
| 719 |
-
window.xdir = new BABYLON.Vector3(1, 0, 0);
|
| 720 |
-
window.rdir = new BABYLON.Vector3(0, 0, 0);
|
| 721 |
-
window.videoDomeMesh = BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1];
|
| 722 |
-
|
| 723 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].addEventListener('pointermove', function(evt) {
|
| 724 |
-
if (md === true) {
|
| 725 |
-
rdir = BABYLON.Engine.LastCreatedScene.activeCamera.getDirection(xdir);
|
| 726 |
-
videoDomeMesh.position.x = parallax * rdir.x;
|
| 727 |
-
videoDomeMesh.position.z = parallax * rdir.z;
|
| 728 |
-
|
| 729 |
-
try {
|
| 730 |
-
compass.style.transform = "rotateX(" + (BABYLON.Engine.LastCreatedScene.activeCamera.beta-Math.PI/2) + "rad) rotateZ(" + BABYLON.Engine.LastCreatedScene.activeCamera.alpha + "rad)";
|
| 731 |
-
} catch(e) {alert(e);}
|
| 732 |
-
}
|
| 733 |
-
if (rd === true) {
|
| 734 |
-
x = parseInt(evt.clientX - evt.target.getBoundingClientRect().x);
|
| 735 |
-
y = parseInt(evt.clientY - evt.target.getBoundingClientRect().y);
|
| 736 |
-
|
| 737 |
-
if (Math.abs(BABYLON.Engine.LastCreatedScene.activeCamera.radius) > (1.57-0.157)*16) {
|
| 738 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.radius = (1.57-0.157)*16;
|
| 739 |
-
} else {
|
| 740 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.fov = BABYLON.Engine.LastCreatedScene.activeCamera.radius/16 + 0.157;
|
| 741 |
-
}
|
| 742 |
-
document.getElementById('zoom').value = BABYLON.Engine.LastCreatedScene.activeCamera.fov;
|
| 743 |
-
document.getElementById('zoom').parentNode.childNodes[2].innerText = document.getElementById('zoom').value;
|
| 744 |
-
|
| 745 |
-
xold=x;
|
| 746 |
-
yold=y;
|
| 747 |
-
}
|
| 748 |
-
});
|
| 749 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].addEventListener('pointerdown', function() {
|
| 750 |
-
md = true;
|
| 751 |
-
});
|
| 752 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].addEventListener('pointerup', function() {
|
| 753 |
-
md = false;
|
| 754 |
-
rd = false;
|
| 755 |
-
});
|
| 756 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].addEventListener('pointercancel', function() {
|
| 757 |
-
md = false;
|
| 758 |
-
rd = false;
|
| 759 |
-
});
|
| 760 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].addEventListener('pointerleave', function() {
|
| 761 |
-
md = false;
|
| 762 |
-
rd = false;
|
| 763 |
-
});
|
| 764 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].addEventListener('pointerout', function() {
|
| 765 |
-
md = false;
|
| 766 |
-
rd = false;
|
| 767 |
-
});
|
| 768 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].addEventListener('contextmenu', function() {
|
| 769 |
-
rd = true;
|
| 770 |
-
});
|
| 771 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].addEventListener('gesturestart', function() {
|
| 772 |
-
rd = true;
|
| 773 |
-
});
|
| 774 |
-
document.getElementById("model3D").getElementsByTagName("canvas")[0].addEventListener('gestureend', function() {
|
| 775 |
-
rd = false;
|
| 776 |
-
});
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
function requestMap() {
|
| 780 |
-
try {
|
| 781 |
-
ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
|
| 782 |
-
videoDome.videoTexture.video.pause();
|
| 783 |
-
video.pause();
|
| 784 |
-
if (buffer) {
|
| 785 |
-
counter = parseInt(video.currentTime);
|
| 786 |
-
if (!coords[counter]) {counter = coords.length-1;}
|
| 787 |
-
applyDisplacementMapFromBuffer(videoDomeMesh, buffer, video.videoWidth, video.videoHeight, 0, -1, null, null, true);
|
| 788 |
-
}
|
| 789 |
-
buffer = ctx.getImageData(0, 0, video.videoWidth, video.videoHeight).data;
|
| 790 |
-
applyDisplacementMapFromBuffer(videoDomeMesh, buffer, video.videoWidth, video.videoHeight, 0, 1, null, null, true);
|
| 791 |
-
} catch(e) {alert(e)}
|
| 792 |
-
}
|
| 793 |
-
window.requestMap = requestMap;
|
| 794 |
-
|
| 795 |
-
videoDome.videoTexture.video.oncanplaythrough = function () {
|
| 796 |
-
document.getElementById('seek').innerHTML = '';
|
| 797 |
-
for (var i=0; i<videoDome.videoTexture.video.duration; i++) {
|
| 798 |
-
document.getElementById('seek').innerHTML += '<a href="#" style="position:absolute;left:'+(56+coords[i].lng/2)+'px;top:'+(56-coords[i].lat/2)+'px;" onclick="seek('+i+');">-'+i+'-</a> ';
|
| 799 |
-
}
|
| 800 |
-
bufferCanvas.width = video.videoWidth;
|
| 801 |
-
bufferCanvas.height = video.videoHeight;
|
| 802 |
-
|
| 803 |
-
videoPlay();
|
| 804 |
-
};
|
| 805 |
-
|
| 806 |
-
//var debugLayer = BABYLON.Engine.LastCreatedScene.debugLayer.show();
|
| 807 |
-
|
| 808 |
-
if (document.getElementById("model")) {
|
| 809 |
-
document.getElementById("model").appendChild(document.getElementById("model3D"));
|
| 810 |
-
toggleDisplay("model");
|
| 811 |
-
}
|
| 812 |
-
|
| 813 |
-
clearInterval(intv);
|
| 814 |
-
}
|
| 815 |
-
} catch(e) {alert(e);}
|
| 816 |
}
|
| 817 |
}, 40);
|
| 818 |
}
|
|
@@ -914,152 +559,6 @@ function drawLine(x, y) {
|
|
| 914 |
}
|
| 915 |
window.drawLine = drawLine;
|
| 916 |
|
| 917 |
-
|
| 918 |
-
window.screenshot = false;
|
| 919 |
-
|
| 920 |
-
function snapshot() {
|
| 921 |
-
if (BABYLON) {
|
| 922 |
-
screenshot = true;
|
| 923 |
-
BABYLON.Engine.LastCreatedScene.getEngine().onEndFrameObservable.add(function() {
|
| 924 |
-
if (screenshot === true) {
|
| 925 |
-
screenshot = false;
|
| 926 |
-
try {
|
| 927 |
-
BABYLON.Tools.CreateScreenshotUsingRenderTarget(BABYLON.Engine.LastCreatedScene.getEngine(), BABYLON.Engine.LastCreatedScene.activeCamera,
|
| 928 |
-
{ precision: 1.0 }, (durl) => {
|
| 929 |
-
var cnvs = document.getElementById("model3D").getElementsByTagName("canvas")[0]; //.getContext("webgl2");
|
| 930 |
-
var svgd = `<svg id="svg_out" viewBox="0 0 ` + cnvs.width + ` ` + cnvs.height + `" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
| 931 |
-
<defs>
|
| 932 |
-
<filter id="blur" x="0" y="0" xmlns="http://www.w3.org/2000/svg">
|
| 933 |
-
<feGaussianBlur in="SourceGraphic" stdDeviation="1" />
|
| 934 |
-
</filter>
|
| 935 |
-
</defs>
|
| 936 |
-
<image filter="url(#blur)" id="svg_img" x="0" y="0" width="` + cnvs.width + `" height="` + cnvs.height + `" xlink:href=\"` + durl + `\"/>
|
| 937 |
-
</svg>`;
|
| 938 |
-
document.getElementById("cnv_out").width = cnvs.width;
|
| 939 |
-
document.getElementById("cnv_out").height = cnvs.height;
|
| 940 |
-
document.getElementById("img_out").src = "data:image/svg+xml;base64," + btoa(svgd);
|
| 941 |
-
}
|
| 942 |
-
);
|
| 943 |
-
} catch(e) { alert(e); }
|
| 944 |
-
// https://forum.babylonjs.com/t/best-way-to-save-to-jpeg-snapshots-of-scene/17663/11
|
| 945 |
-
}
|
| 946 |
-
});
|
| 947 |
-
}
|
| 948 |
-
}
|
| 949 |
-
window.snapshot = snapshot;
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
window.recorder = null;
|
| 953 |
-
|
| 954 |
-
function record_video() {
|
| 955 |
-
try {
|
| 956 |
-
if (BABYLON.VideoRecorder.IsSupported(BABYLON.Engine.LastCreatedScene.getEngine()) && (recorder == null || !recorder.isRecording) ) {
|
| 957 |
-
if (recorder == null) {
|
| 958 |
-
recorder = new BABYLON.VideoRecorder(BABYLON.Engine.LastCreatedScene.getEngine(), { mimeType:'video/mp4', fps:25, /*audioTracks: mediaStreamDestination.stream.getAudioTracks()*/ });
|
| 959 |
-
}
|
| 960 |
-
recorder.startRecording('video.mp4', 60*60);
|
| 961 |
-
}
|
| 962 |
-
} catch(e) {alert(e);}
|
| 963 |
-
}
|
| 964 |
-
window.record_video = record_video;
|
| 965 |
-
|
| 966 |
-
function stop_recording() {
|
| 967 |
-
if (recorder.isRecording) {
|
| 968 |
-
recorder.stopRecording();
|
| 969 |
-
}
|
| 970 |
-
}
|
| 971 |
-
window.stop_recording = stop_recording;
|
| 972 |
-
|
| 973 |
-
function seek(t) {
|
| 974 |
-
videoDome.videoTexture.video.currentTime = t;
|
| 975 |
-
if (videoDome.videoTexture.video.currentTime > videoDome.videoTexture.video.duration) {
|
| 976 |
-
videoDome.videoTexture.video.currentTime = videoDome.videoTexture.video.duration;
|
| 977 |
-
} else if (videoDome.videoTexture.video.currentTime < 0) {
|
| 978 |
-
videoDome.videoTexture.video.currentTime = 0;
|
| 979 |
-
}
|
| 980 |
-
video.currentTime = t;
|
| 981 |
-
if (video.currentTime > video.duration) {
|
| 982 |
-
video.currentTime = video.duration;
|
| 983 |
-
} else if (video.currentTime < 0) {
|
| 984 |
-
video.currentTime = 0;
|
| 985 |
-
}
|
| 986 |
-
requestMap();
|
| 987 |
-
}
|
| 988 |
-
window.seek = seek;
|
| 989 |
-
|
| 990 |
-
function videoPlay() {
|
| 991 |
-
videoDome.videoTexture.video.oncanplaythrough = null;
|
| 992 |
-
video.oncanplaythrough = null;
|
| 993 |
-
|
| 994 |
-
videoDome.videoTexture.video.loop = true;
|
| 995 |
-
video.loop = true;
|
| 996 |
-
videoDome.videoTexture.video.play();
|
| 997 |
-
video.play();
|
| 998 |
-
}
|
| 999 |
-
window.videoPlay = videoPlay;
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
function applyDisplacementMapFromBuffer(
|
| 1003 |
-
mesh,
|
| 1004 |
-
buffer,
|
| 1005 |
-
heightMapWidth,
|
| 1006 |
-
heightMapHeight,
|
| 1007 |
-
minHeight,
|
| 1008 |
-
maxHeight,
|
| 1009 |
-
uvOffset,
|
| 1010 |
-
uvScale,
|
| 1011 |
-
forceUpdate
|
| 1012 |
-
) {
|
| 1013 |
-
try {
|
| 1014 |
-
if (!mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
|
| 1015 |
-
let positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
|
| 1016 |
-
let normals = [];
|
| 1017 |
-
BABYLON.VertexData.ComputeNormals(positions, mesh.getIndices(), normals, {useRightHandedSystem: true});
|
| 1018 |
-
mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals);
|
| 1019 |
-
}
|
| 1020 |
-
const positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind, true, true);
|
| 1021 |
-
const normals = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
|
| 1022 |
-
const uvs = mesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
|
| 1023 |
-
|
| 1024 |
-
let position = BABYLON.Vector3.Zero();
|
| 1025 |
-
const normal = BABYLON.Vector3.Zero();
|
| 1026 |
-
const uv = BABYLON.Vector2.Zero();
|
| 1027 |
-
|
| 1028 |
-
uvOffset = uvOffset || BABYLON.Vector2.Zero();
|
| 1029 |
-
uvScale = uvScale || new BABYLON.Vector2(1, 1);
|
| 1030 |
-
|
| 1031 |
-
for (let index = 0; index < positions.length; index += 3) {
|
| 1032 |
-
BABYLON.Vector3.FromArrayToRef(positions, index, position);
|
| 1033 |
-
BABYLON.Vector3.FromArrayToRef(normals, index, normal);
|
| 1034 |
-
BABYLON.Vector2.FromArrayToRef(uvs, (index / 3) * 2, uv);
|
| 1035 |
-
|
| 1036 |
-
// Compute height
|
| 1037 |
-
const u = (Math.abs(uv.x * uvScale.x + (uvOffset.x % 1)) * (heightMapWidth - 1)) % heightMapWidth | 0;
|
| 1038 |
-
const v = (Math.abs(uv.y * uvScale.y + (uvOffset.y % 1)) * (heightMapHeight - 1)) % heightMapHeight | 0;
|
| 1039 |
-
|
| 1040 |
-
const pos = (u + v * heightMapWidth) * 4;
|
| 1041 |
-
const r = buffer[pos] / 255.0;
|
| 1042 |
-
const g = buffer[pos + 1] / 255.0;
|
| 1043 |
-
const b = buffer[pos + 2] / 255.0;
|
| 1044 |
-
const a = buffer[pos + 3] / 255.0;
|
| 1045 |
-
|
| 1046 |
-
const gradient = r * 0.33 + g * 0.33 + b * 0.33;
|
| 1047 |
-
//const gradient = a;
|
| 1048 |
-
|
| 1049 |
-
normal.normalize();
|
| 1050 |
-
normal.scaleInPlace(minHeight + (maxHeight - minHeight) * gradient);
|
| 1051 |
-
position = position.add(normal);
|
| 1052 |
-
|
| 1053 |
-
position.toArray(positions, index);
|
| 1054 |
-
}
|
| 1055 |
-
mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions);
|
| 1056 |
-
|
| 1057 |
-
return mesh;
|
| 1058 |
-
} catch(e) {alert(e)}
|
| 1059 |
-
}
|
| 1060 |
-
window.applyDisplacementMapFromBuffer = applyDisplacementMapFromBuffer;
|
| 1061 |
-
|
| 1062 |
-
|
| 1063 |
var intv_ = setInterval(function(){
|
| 1064 |
if (document.getElementById("image_edit") && document.getElementById("image_edit").getElementsByTagName("canvas")) {
|
| 1065 |
document.getElementById("image_edit").getElementsByTagName("canvas")[0].oncontextmenu = function(e){e.preventDefault();}
|
|
@@ -1164,11 +663,6 @@ with gr.Blocks(css=css, js=js, head=head) as demo:
|
|
| 1164 |
processed_video = gr.Video(label="Output Video", format="mp4", elem_id="output_video", interactive=False)
|
| 1165 |
processed_zip = gr.File(label="Output Archive", interactive=False)
|
| 1166 |
depth_video = gr.Video(label="Depth Video", format="mp4", elem_id="depth_video", interactive=False, visible=True)
|
| 1167 |
-
result = gr.Model3D(label="3D Mesh", clear_color=[0.5, 0.5, 0.5, 0.0], camera_position=[0, 90, 512], zoom_speed=2.0, pan_speed=2.0, interactive=True, elem_id="model3D")
|
| 1168 |
-
with gr.Accordion(label="Embed in website", open=False):
|
| 1169 |
-
embed_model = gr.Textbox(elem_id="embed_model", label="Include this wherever the model is to appear on the page", interactive=False, value="""
|
| 1170 |
-
|
| 1171 |
-
""")
|
| 1172 |
|
| 1173 |
with gr.Tab("Blur"):
|
| 1174 |
chart_c = gr.HTML(elem_id="chart_c", value="""<div id='chart' onpointermove='window.drawLine(event.clientX, event.clientY);' onpointerdown='window.pointerDown(event.clientX, event.clientY);' onpointerup='window.pointerUp();' onpointerleave='window.pointerUp();' onpointercancel='window.pointerUp();' onclick='window.resetLine();'></div>
|
|
@@ -1179,9 +673,6 @@ with gr.Blocks(css=css, js=js, head=head) as demo:
|
|
| 1179 |
html, body {
|
| 1180 |
user-select: none;
|
| 1181 |
}
|
| 1182 |
-
#model3D canvas {
|
| 1183 |
-
user-select: none;
|
| 1184 |
-
}
|
| 1185 |
#chart hr {
|
| 1186 |
width: 1px;
|
| 1187 |
height: 1px;
|
|
@@ -1201,32 +692,6 @@ with gr.Blocks(css=css, js=js, head=head) as demo:
|
|
| 1201 |
background-color:#808080;
|
| 1202 |
touch-action: none;
|
| 1203 |
}
|
| 1204 |
-
#compass_box {
|
| 1205 |
-
position:absolute;
|
| 1206 |
-
top:2em;
|
| 1207 |
-
right:3px;
|
| 1208 |
-
border:1px dashed gray;
|
| 1209 |
-
border-radius: 50%;
|
| 1210 |
-
width:1.5em;
|
| 1211 |
-
height:1.5em;
|
| 1212 |
-
padding:0;
|
| 1213 |
-
margin:0;
|
| 1214 |
-
}
|
| 1215 |
-
#compass {
|
| 1216 |
-
position:absolute;
|
| 1217 |
-
transform:rotate(0deg);
|
| 1218 |
-
border:1px solid black;
|
| 1219 |
-
border-radius: 50%;
|
| 1220 |
-
width:100%;
|
| 1221 |
-
height:100%;
|
| 1222 |
-
padding:0;
|
| 1223 |
-
margin:0;
|
| 1224 |
-
line-height:1em;
|
| 1225 |
-
letter-spacing:0;
|
| 1226 |
-
}
|
| 1227 |
-
#compass b {
|
| 1228 |
-
margin-top:-1px;
|
| 1229 |
-
}
|
| 1230 |
</style>
|
| 1231 |
""")
|
| 1232 |
average = gr.HTML(value="""<label for='average'>Average</label><input id='average' type='range' style='width:256px;height:1em;' value='1' min='1' max='15' step='2' onclick='
|
|
@@ -1267,100 +732,6 @@ with gr.Blocks(css=css, js=js, head=head) as demo:
|
|
| 1267 |
{"lat": 50.073823157821664, "lng": 14.437124189538856, "heading": 152.95769, "pitch": 4.233024999999998}
|
| 1268 |
]"""
|
| 1269 |
coords = gr.Textbox(elem_id="coords", value=example_coords, label="Coordinates", interactive=False)
|
| 1270 |
-
mesh_order = gr.Textbox(elem_id="order", value="", label="Order", interactive=False)
|
| 1271 |
-
load_all = gr.Checkbox(label="Load all")
|
| 1272 |
-
|
| 1273 |
-
with gr.Group():
|
| 1274 |
-
camera = gr.HTML(value="""<div style='width:128px;height:128px;border:1px dotted gray;padding:0;margin:0;float:left;clear:none;' id='seek'></div>
|
| 1275 |
-
<span style='max-width:50%;float:right;clear:none;text-align:right;'>
|
| 1276 |
-
<a href='#' id='reset_cam' style='float:right;clear:none;color:white' onclick='
|
| 1277 |
-
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
| 1278 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata = {
|
| 1279 |
-
screenshot: true,
|
| 1280 |
-
pipeline: new BABYLON.DefaultRenderingPipeline(\"default\", true, BABYLON.Engine.LastCreatedScene, [BABYLON.Engine.LastCreatedScene.activeCamera])
|
| 1281 |
-
}
|
| 1282 |
-
}
|
| 1283 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.radius = 0;
|
| 1284 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.alpha = 0;
|
| 1285 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.beta = Math.PI / 2;
|
| 1286 |
-
|
| 1287 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.samples = 4;
|
| 1288 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.fov = document.getElementById(\"zoom\").value;
|
| 1289 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.contrast = document.getElementById(\"contrast\").value;
|
| 1290 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure = document.getElementById(\"exposure\").value;
|
| 1291 |
-
|
| 1292 |
-
document.getElementById(\"model3D\").getElementsByTagName(\"canvas\")[0].style.filter = \"blur(\" + Math.ceil(Math.log2(Math.PI/document.getElementById(\"zoom\").value))/2.0*Math.sqrt(2.0) + \"px)\";
|
| 1293 |
-
document.getElementById(\"model3D\").getElementsByTagName(\"canvas\")[0].oncontextmenu = function(e){e.preventDefault();}
|
| 1294 |
-
document.getElementById(\"model3D\").getElementsByTagName(\"canvas\")[0].ondrag = function(e){e.preventDefault();}
|
| 1295 |
-
'>Reset camera</a><br/>
|
| 1296 |
-
<span><label for='zoom' style='width:8em'>Zoom</label><input id='zoom' type='range' style='width:128px;height:1em;' value='0.8' min='0.157' max='1.57' step='0.001' oninput='
|
| 1297 |
-
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
| 1298 |
-
var evt = document.createEvent(\"Event\");
|
| 1299 |
-
evt.initEvent(\"click\", true, false);
|
| 1300 |
-
document.getElementById(\"reset_cam\").dispatchEvent(evt);
|
| 1301 |
-
}
|
| 1302 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.fov = this.value;
|
| 1303 |
-
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.fov;
|
| 1304 |
-
|
| 1305 |
-
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)\";
|
| 1306 |
-
'/><span>0.8</span></span><br/>
|
| 1307 |
-
<span><label for='pan' style='width:8em'>Pan</label><input id='pan' type='range' style='width:128px;height:1em;' value='0' min='-16' max='16' step='0.001' oninput='
|
| 1308 |
-
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
| 1309 |
-
var evt = document.createEvent(\"Event\");
|
| 1310 |
-
evt.initEvent(\"click\", true, false);
|
| 1311 |
-
document.getElementById(\"reset_cam\").dispatchEvent(evt);
|
| 1312 |
-
}
|
| 1313 |
-
parallax = this.value;
|
| 1314 |
-
rdir = BABYLON.Engine.LastCreatedScene.activeCamera.getDirection(xdir);
|
| 1315 |
-
videoDomeMesh.position.x = parallax * rdir.x;
|
| 1316 |
-
videoDomeMesh.position.z = parallax * rdir.z;
|
| 1317 |
-
this.parentNode.childNodes[2].innerText = parallax;
|
| 1318 |
-
'/><span>0.0</span></span><br/>
|
| 1319 |
-
<span><label for='contrast' style='width:8em'>Contrast</label><input id='contrast' type='range' style='width:128px;height:1em;' value='1.0' min='0' max='2' step='0.001' oninput='
|
| 1320 |
-
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
| 1321 |
-
var evt = document.createEvent(\"Event\");
|
| 1322 |
-
evt.initEvent(\"click\", true, false);
|
| 1323 |
-
document.getElementById(\"reset_cam\").dispatchEvent(evt);
|
| 1324 |
-
}
|
| 1325 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.contrast = this.value;
|
| 1326 |
-
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.contrast;
|
| 1327 |
-
'/><span>1.0</span></span><br/>
|
| 1328 |
-
<span><label for='exposure' style='width:8em'>Exposure</label><input id='exposure' type='range' style='width:128px;height:1em;' value='1.0' min='0' max='2' step='0.001' oninput='
|
| 1329 |
-
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
| 1330 |
-
var evt = document.createEvent(\"Event\");
|
| 1331 |
-
evt.initEvent(\"click\", true, false);
|
| 1332 |
-
document.getElementById(\"reset_cam\").dispatchEvent(evt);
|
| 1333 |
-
}
|
| 1334 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure = this.value;
|
| 1335 |
-
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure;
|
| 1336 |
-
'/><span>1.0</span></span><br/>
|
| 1337 |
-
<a href='#' onclick='snapshot();'>Screenshot</a>
|
| 1338 |
-
<a href='#' onclick='record_video();'>Record</a>
|
| 1339 |
-
<a href='#' onclick='stop_recording();'>Stop rec.</a>
|
| 1340 |
-
<a href='#' onclick='videoPlay();'>Play</a></span>""")
|
| 1341 |
-
snapshot = gr.HTML(value="""<img src='' id='img_out' onload='var ctxt = document.getElementById(\"cnv_out\").getContext(\"2d\");ctxt.drawImage(this, 0, 0);'/><br/>
|
| 1342 |
-
<canvas id='cnv_out'></canvas>
|
| 1343 |
-
<div id='compass_box'><div id='compass'><a id='fullscreen' onclick='
|
| 1344 |
-
const model3D = document.getElementById(\"model3D\");
|
| 1345 |
-
if (model3D.parentNode.tagName != \"BODY\") {
|
| 1346 |
-
window.modelContainer = model3D.parentNode.id;
|
| 1347 |
-
document.body.appendChild(model3D);
|
| 1348 |
-
model3D.style.position = \"fixed\";
|
| 1349 |
-
model3D.style.left = \"0\";
|
| 1350 |
-
model3D.style.top = \"0\";
|
| 1351 |
-
model3D.style.zIndex = \"100\";
|
| 1352 |
-
document.getElementById(\"compass_box\").style.zIndex = \"101\";
|
| 1353 |
-
} else {
|
| 1354 |
-
document.getElementById(window.modelContainer).appendChild(model3D);
|
| 1355 |
-
model3D.style.position = \"relative\";
|
| 1356 |
-
model3D.style.left = \"0\";
|
| 1357 |
-
model3D.style.top = \"0\";
|
| 1358 |
-
model3D.style.zIndex = \"initial\";
|
| 1359 |
-
document.getElementById(\"compass_box\").style.zIndex = \"initial\";
|
| 1360 |
-
}'><b style='color:blue;'>◅</b>𝍠<b style='color:red;'>▻</b></a></div>
|
| 1361 |
-
</div>
|
| 1362 |
-
""")
|
| 1363 |
-
render = gr.Button("Render")
|
| 1364 |
input_json.input(show_json, inputs=[input_json], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|
| 1365 |
|
| 1366 |
|
|
@@ -1405,9 +776,7 @@ with gr.Blocks(css=css, js=js, head=head) as demo:
|
|
| 1405 |
|
| 1406 |
return output_video_path + (json.dumps(locations),)
|
| 1407 |
|
| 1408 |
-
submit.click(on_submit, inputs=[input_video, model_type, blur_in, boffset, bsize, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, depth_video, coords])
|
| 1409 |
-
render.click(None, inputs=[coords, mesh_order, output_frame, output_mask, selected, output_depth, output_switch], outputs=None, js=load_model)
|
| 1410 |
-
render.click(partial(get_mesh), inputs=[output_frame, output_mask, blur_in, load_all], outputs=[result, mesh_order])
|
| 1411 |
|
| 1412 |
example_files = [["./examples/streetview.mp4", "vits", blurin, 1, 32, example_coords]]
|
| 1413 |
examples = gr.Examples(examples=example_files, fn=on_submit, cache_examples=True, inputs=[input_video, model_type, blur_in, boffset, bsize, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, depth_video, coords])
|
|
|
|
| 46 |
depths = []
|
| 47 |
masks = []
|
| 48 |
locations = []
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
def zip_files(files_in, files_out):
|
| 51 |
with ZipFile("depth_result.zip", "w") as zipObj:
|
|
|
|
| 282 |
mask = depth_grad > 0.05
|
| 283 |
return mask
|
| 284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
def rgb2gray(rgb):
|
| 286 |
return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
|
| 287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
def blur_image(image, depth, blur_data):
|
| 289 |
blur_a = blur_data.split()
|
| 290 |
#print(f'blur data {blur_data}')
|
|
|
|
| 453 |
|
| 454 |
|
| 455 |
load_model="""
|
| 456 |
+
async()=>{
|
| 457 |
var intv = setInterval(function(){
|
| 458 |
+
if (document.getElementById("output_video").getElementsByTagName("video")) {
|
| 459 |
+
alert(document.getElementById("output_video").getElementsByTagName("video")[0].src);
|
| 460 |
+
clearInterval(intv);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
}
|
| 462 |
}, 40);
|
| 463 |
}
|
|
|
|
| 559 |
}
|
| 560 |
window.drawLine = drawLine;
|
| 561 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
var intv_ = setInterval(function(){
|
| 563 |
if (document.getElementById("image_edit") && document.getElementById("image_edit").getElementsByTagName("canvas")) {
|
| 564 |
document.getElementById("image_edit").getElementsByTagName("canvas")[0].oncontextmenu = function(e){e.preventDefault();}
|
|
|
|
| 663 |
processed_video = gr.Video(label="Output Video", format="mp4", elem_id="output_video", interactive=False)
|
| 664 |
processed_zip = gr.File(label="Output Archive", interactive=False)
|
| 665 |
depth_video = gr.Video(label="Depth Video", format="mp4", elem_id="depth_video", interactive=False, visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 666 |
|
| 667 |
with gr.Tab("Blur"):
|
| 668 |
chart_c = gr.HTML(elem_id="chart_c", value="""<div id='chart' onpointermove='window.drawLine(event.clientX, event.clientY);' onpointerdown='window.pointerDown(event.clientX, event.clientY);' onpointerup='window.pointerUp();' onpointerleave='window.pointerUp();' onpointercancel='window.pointerUp();' onclick='window.resetLine();'></div>
|
|
|
|
| 673 |
html, body {
|
| 674 |
user-select: none;
|
| 675 |
}
|
|
|
|
|
|
|
|
|
|
| 676 |
#chart hr {
|
| 677 |
width: 1px;
|
| 678 |
height: 1px;
|
|
|
|
| 692 |
background-color:#808080;
|
| 693 |
touch-action: none;
|
| 694 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 695 |
</style>
|
| 696 |
""")
|
| 697 |
average = gr.HTML(value="""<label for='average'>Average</label><input id='average' type='range' style='width:256px;height:1em;' value='1' min='1' max='15' step='2' onclick='
|
|
|
|
| 732 |
{"lat": 50.073823157821664, "lng": 14.437124189538856, "heading": 152.95769, "pitch": 4.233024999999998}
|
| 733 |
]"""
|
| 734 |
coords = gr.Textbox(elem_id="coords", value=example_coords, label="Coordinates", interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 735 |
input_json.input(show_json, inputs=[input_json], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|
| 736 |
|
| 737 |
|
|
|
|
| 776 |
|
| 777 |
return output_video_path + (json.dumps(locations),)
|
| 778 |
|
| 779 |
+
submit.click(on_submit, inputs=[input_video, model_type, blur_in, boffset, bsize, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, depth_video, coords], js=load_model)
|
|
|
|
|
|
|
| 780 |
|
| 781 |
example_files = [["./examples/streetview.mp4", "vits", blurin, 1, 32, example_coords]]
|
| 782 |
examples = gr.Examples(examples=example_files, fn=on_submit, cache_examples=True, inputs=[input_video, model_type, blur_in, boffset, bsize, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, depth_video, coords])
|