Spaces:
Runtime error
Runtime error
pablo
commited on
Commit
·
aa6e5e4
1
Parent(s):
baf6855
fixes
Browse files- geometry.py +2 -2
- mesh.py +3 -3
geometry.py
CHANGED
@@ -12,7 +12,7 @@ def get_intrinsics(H,W):
|
|
12 |
[0, f, cy],
|
13 |
[0, 0, 1]])
|
14 |
|
15 |
-
def depth_to_points(depth, R=None, t=None):
|
16 |
|
17 |
K = get_intrinsics(depth.shape[1], depth.shape[2])
|
18 |
Kinv = np.linalg.inv(K)
|
@@ -36,7 +36,7 @@ def depth_to_points(depth, R=None, t=None):
|
|
36 |
# coord = torch.as_tensor(coord, dtype=torch.float32, device=device)
|
37 |
coord = coord[None] # bs, h, w, 3
|
38 |
|
39 |
-
D = depth[:, :, :, None, None]
|
40 |
# print(D.shape, Kinv[None, None, None, ...].shape, coord[:, :, :, :, None].shape )
|
41 |
pts3D_1 = D * Kinv[None, None, None, ...] @ coord[:, :, :, :, None]
|
42 |
# pts3D_1 live in your coordinate system. Convert them to Py3D's
|
|
|
12 |
[0, f, cy],
|
13 |
[0, 0, 1]])
|
14 |
|
15 |
+
def depth_to_points(depth, R=None, t=None, skew=0.5):
|
16 |
|
17 |
K = get_intrinsics(depth.shape[1], depth.shape[2])
|
18 |
Kinv = np.linalg.inv(K)
|
|
|
36 |
# coord = torch.as_tensor(coord, dtype=torch.float32, device=device)
|
37 |
coord = coord[None] # bs, h, w, 3
|
38 |
|
39 |
+
D = depth[:, :, :, None, None] * skew
|
40 |
# print(D.shape, Kinv[None, None, None, ...].shape, coord[:, :, :, :, None].shape )
|
41 |
pts3D_1 = D * Kinv[None, None, None, ...] @ coord[:, :, :, :, None]
|
42 |
# pts3D_1 live in your coordinate system. Convert them to Py3D's
|
mesh.py
CHANGED
@@ -18,7 +18,7 @@ def depth_edges_mask(depth):
|
|
18 |
# Compute the gradient magnitude.
|
19 |
depth_grad = np.sqrt(depth_dx ** 2 + depth_dy ** 2)
|
20 |
# Compute the edge mask.
|
21 |
-
mask = depth_grad >
|
22 |
return mask
|
23 |
|
24 |
|
@@ -26,9 +26,9 @@ def predict_depth(model, image):
|
|
26 |
depth = model.infer_pil(image)
|
27 |
return depth
|
28 |
|
29 |
-
def get_mesh(depth, image, keep_edges=False):
|
30 |
# limit the size of the input image
|
31 |
-
pts3d = depth_to_points(depth[None])
|
32 |
pts3d = pts3d.reshape(-1, 3)
|
33 |
|
34 |
# Create a trimesh mesh from the points
|
|
|
18 |
# Compute the gradient magnitude.
|
19 |
depth_grad = np.sqrt(depth_dx ** 2 + depth_dy ** 2)
|
20 |
# Compute the edge mask.
|
21 |
+
mask = depth_grad > 2
|
22 |
return mask
|
23 |
|
24 |
|
|
|
26 |
depth = model.infer_pil(image)
|
27 |
return depth
|
28 |
|
29 |
+
def get_mesh(depth, image, keep_edges=False, skew=0.5):
|
30 |
# limit the size of the input image
|
31 |
+
pts3d = depth_to_points(depth[None], skew=skew)
|
32 |
pts3d = pts3d.reshape(-1, 3)
|
33 |
|
34 |
# Create a trimesh mesh from the points
|