clean up
Browse files- handcrafted_solution.py +19 -20
handcrafted_solution.py
CHANGED
@@ -457,8 +457,22 @@ def prune_not_connected(all_3d_vertices, connections_3d):
|
|
457 |
|
458 |
return np.array(new_verts), connected_out
|
459 |
|
460 |
-
|
461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
462 |
good_entry = convert_entry_to_human_readable(entry)
|
463 |
points3D = good_entry['points3d']
|
464 |
vert_edge_per_image = {}
|
@@ -477,10 +491,7 @@ def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
|
|
477 |
elif i==2: # only visualize view 0,1
|
478 |
continue
|
479 |
'''
|
480 |
-
|
481 |
-
depth_scale = 2.5
|
482 |
|
483 |
-
|
484 |
ade_seg = ade.resize(depth.size)
|
485 |
ade_seg_np = np.array(ade_seg).astype(np.uint8)
|
486 |
gest_seg = gest.resize(depth.size)
|
@@ -495,26 +506,14 @@ def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
|
|
495 |
print (f'Not enough vertices ({len(vertices)}) or connections ({len(connections)}) in image {i}')
|
496 |
vert_edge_per_image[i] = np.empty((0, 2)), [], np.empty((0, 3))
|
497 |
continue
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
#uv, depth_vert = get_uv_depth(vertices, depth_np)
|
502 |
sfm_depth_np = get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, 10)
|
503 |
uv, depth_vert = get_smooth_uv_depth(vertices, depth_np, gest_seg_np, sfm_depth_np)
|
504 |
#uv, depth_vert = get_smooth_uv_depth(vertices, depth_np, gest_seg_np, None)
|
505 |
|
506 |
-
|
507 |
-
|
508 |
-
xy_local[:, 0] = (uv[:, 0] - K[0,2]) / K[0,0]
|
509 |
-
xy_local[:, 1] = (uv[:, 1] - K[1,2]) / K[1,1]
|
510 |
-
# Get the 3D vertices
|
511 |
-
vertices_3d_local = depth_vert[...,None] * (xy_local/np.linalg.norm(xy_local, axis=1)[...,None])
|
512 |
-
world_to_cam = np.eye(4)
|
513 |
-
world_to_cam[:3, :3] = R
|
514 |
-
world_to_cam[:3, 3] = t.reshape(-1)
|
515 |
-
cam_to_world = np.linalg.inv(world_to_cam)
|
516 |
-
vertices_3d = cv2.transform(cv2.convertPointsToHomogeneous(vertices_3d_local), cam_to_world)
|
517 |
-
vertices_3d = cv2.convertPointsFromHomogeneous(vertices_3d).reshape(-1, 3)
|
518 |
vert_edge_per_image[i] = vertices, connections, vertices_3d
|
519 |
all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image, 3.0) # TODO: 3cm looks too small
|
520 |
#print(f'after merge, {len(all_3d_vertices)} 3d vertices and {len(connections_3d)} 3d connections')
|
|
|
457 |
|
458 |
return np.array(new_verts), connected_out
|
459 |
|
460 |
+
def uv_to_v3d(uv, depth_vert, K, R, t):
|
461 |
+
# Normalize the uv to the camera intrinsics
|
462 |
+
xy_local = np.ones((len(uv), 3))
|
463 |
+
xy_local[:, 0] = (uv[:, 0] - K[0,2]) / K[0,0]
|
464 |
+
xy_local[:, 1] = (uv[:, 1] - K[1,2]) / K[1,1]
|
465 |
+
# Get the 3D vertices
|
466 |
+
vertices_3d_local = depth_vert[...,None] * (xy_local/np.linalg.norm(xy_local, axis=1)[...,None])
|
467 |
+
world_to_cam = np.eye(4)
|
468 |
+
world_to_cam[:3, :3] = R
|
469 |
+
world_to_cam[:3, 3] = t.reshape(-1)
|
470 |
+
cam_to_world = np.linalg.inv(world_to_cam)
|
471 |
+
vertices_3d = cv2.transform(cv2.convertPointsToHomogeneous(vertices_3d_local), cam_to_world)
|
472 |
+
vertices_3d = cv2.convertPointsFromHomogeneous(vertices_3d).reshape(-1, 3)
|
473 |
+
return vertices_3d
|
474 |
+
|
475 |
+
def predict(entry, visualize=False, depth_scale=2.5, ) -> Tuple[np.ndarray, List[int]]:
|
476 |
good_entry = convert_entry_to_human_readable(entry)
|
477 |
points3D = good_entry['points3d']
|
478 |
vert_edge_per_image = {}
|
|
|
491 |
elif i==2: # only visualize view 0,1
|
492 |
continue
|
493 |
'''
|
|
|
|
|
494 |
|
|
|
495 |
ade_seg = ade.resize(depth.size)
|
496 |
ade_seg_np = np.array(ade_seg).astype(np.uint8)
|
497 |
gest_seg = gest.resize(depth.size)
|
|
|
506 |
print (f'Not enough vertices ({len(vertices)}) or connections ({len(connections)}) in image {i}')
|
507 |
vert_edge_per_image[i] = np.empty((0, 2)), [], np.empty((0, 3))
|
508 |
continue
|
509 |
+
|
|
|
|
|
510 |
#uv, depth_vert = get_uv_depth(vertices, depth_np)
|
511 |
sfm_depth_np = get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, 10)
|
512 |
uv, depth_vert = get_smooth_uv_depth(vertices, depth_np, gest_seg_np, sfm_depth_np)
|
513 |
#uv, depth_vert = get_smooth_uv_depth(vertices, depth_np, gest_seg_np, None)
|
514 |
|
515 |
+
vertices_3d = uv_to_v3d(uv, depth_vert, K, R, t)
|
516 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
517 |
vert_edge_per_image[i] = vertices, connections, vertices_3d
|
518 |
all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image, 3.0) # TODO: 3cm looks too small
|
519 |
#print(f'after merge, {len(all_3d_vertices)} 3d vertices and {len(connections_3d)} 3d connections')
|