bug fixed: type casting
Browse files- handcrafted_solution.py +8 -8
handcrafted_solution.py
CHANGED
|
@@ -164,7 +164,7 @@ def get_smooth_uv_depth(vertices, depth, gest_seg_np, sfm_depth_np):
|
|
| 164 |
vertex_depth = np.array(vertex_depth)
|
| 165 |
return uv, vertex_depth
|
| 166 |
|
| 167 |
-
|
| 168 |
from numba import njit, prange
|
| 169 |
@njit(parallel=True)
|
| 170 |
def fill_range(u, v, z, dilate_r, c, sfm_depth_np, sfm_color_np, H, W):
|
|
@@ -178,7 +178,6 @@ def fill_range(u, v, z, dilate_r, c, sfm_depth_np, sfm_color_np, H, W):
|
|
| 178 |
if DUMP_IMG:
|
| 179 |
sfm_color_np[j, i] = c
|
| 180 |
return sfm_depth_np, sfm_color_np
|
| 181 |
-
'''
|
| 182 |
|
| 183 |
def get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, dilate_r = 5):
|
| 184 |
'''Project 3D sfm pointcloud to the image plane '''
|
|
@@ -207,7 +206,7 @@ def get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, dilate_r = 5):
|
|
| 207 |
#checked = 0
|
| 208 |
#print('dim of us uv zs rgb:', len(us), len(vs), len(zs), len(rgb))
|
| 209 |
for u,v,z,c in zip(us,vs,zs, rgb):
|
| 210 |
-
|
| 211 |
sfm_depth_np, sfm_color_np = fill_range(u, v, z, dilate_r, c, sfm_depth_np, sfm_color_np, H, W)
|
| 212 |
'''
|
| 213 |
i_range = range(max(0, u - dilate_r), min(W, u + dilate_r))
|
|
@@ -221,7 +220,7 @@ def get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, dilate_r = 5):
|
|
| 221 |
sfm_depth_np[j, i] = z
|
| 222 |
if DUMP_IMG:
|
| 223 |
sfm_color_np[j, i] = c
|
| 224 |
-
|
| 225 |
|
| 226 |
#print(f'checked {checked} pts')
|
| 227 |
|
|
@@ -519,6 +518,7 @@ def delete_one_vert(vertices, vertices_3d, connections, vert_to_del):
|
|
| 519 |
|
| 520 |
#print(f'del {len(conn_to_del)} connections')
|
| 521 |
connections = np.delete(connections, (conn_to_del), axis=0)
|
|
|
|
| 522 |
#print(vertices, vertices_3d, connections)
|
| 523 |
if vertices:
|
| 524 |
return vertices, vertices_3d, connections
|
|
@@ -599,7 +599,7 @@ def predict(entry, visualize=False, prune_dist_thr=600, depth_scale=2.5, ) -> Tu
|
|
| 599 |
continue
|
| 600 |
|
| 601 |
#uv, depth_vert = get_uv_depth(vertices, depth_np)
|
| 602 |
-
sfm_depth_np = get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t,
|
| 603 |
uv, depth_vert = get_smooth_uv_depth(vertices, depth_np, gest_seg_np, sfm_depth_np)
|
| 604 |
#uv, depth_vert = get_smooth_uv_depth(vertices, depth_np, gest_seg_np, None)
|
| 605 |
|
|
@@ -616,9 +616,9 @@ def predict(entry, visualize=False, prune_dist_thr=600, depth_scale=2.5, ) -> Tu
|
|
| 616 |
#all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image, 3.0) # TODO: 3cm looks too small
|
| 617 |
all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image, 30)
|
| 618 |
#print(f'after merge, {len(all_3d_vertices)} 3d vertices and {len(connections_3d)} 3d connections')
|
| 619 |
-
#all_3d_vertices_clean, connections_3d_clean = prune_not_connected(all_3d_vertices, connections_3d)
|
| 620 |
-
|
| 621 |
-
all_3d_vertices_clean, connections_3d_clean = all_3d_vertices, connections_3d # don't prune -> cost:2.0
|
| 622 |
#print(f'after pruning, {len(all_3d_vertices_clean)} 3d clean vertices and {len(connections_3d_clean)} 3d clean connections')
|
| 623 |
if (len(all_3d_vertices_clean) < 2) or len(connections_3d_clean) < 1:
|
| 624 |
print (f'Not enough vertices or connections in the 3D vertices')
|
|
|
|
| 164 |
vertex_depth = np.array(vertex_depth)
|
| 165 |
return uv, vertex_depth
|
| 166 |
|
| 167 |
+
|
| 168 |
from numba import njit, prange
|
| 169 |
@njit(parallel=True)
|
| 170 |
def fill_range(u, v, z, dilate_r, c, sfm_depth_np, sfm_color_np, H, W):
|
|
|
|
| 178 |
if DUMP_IMG:
|
| 179 |
sfm_color_np[j, i] = c
|
| 180 |
return sfm_depth_np, sfm_color_np
|
|
|
|
| 181 |
|
| 182 |
def get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, dilate_r = 5):
|
| 183 |
'''Project 3D sfm pointcloud to the image plane '''
|
|
|
|
| 206 |
#checked = 0
|
| 207 |
#print('dim of us uv zs rgb:', len(us), len(vs), len(zs), len(rgb))
|
| 208 |
for u,v,z,c in zip(us,vs,zs, rgb):
|
| 209 |
+
|
| 210 |
sfm_depth_np, sfm_color_np = fill_range(u, v, z, dilate_r, c, sfm_depth_np, sfm_color_np, H, W)
|
| 211 |
'''
|
| 212 |
i_range = range(max(0, u - dilate_r), min(W, u + dilate_r))
|
|
|
|
| 220 |
sfm_depth_np[j, i] = z
|
| 221 |
if DUMP_IMG:
|
| 222 |
sfm_color_np[j, i] = c
|
| 223 |
+
'''
|
| 224 |
|
| 225 |
#print(f'checked {checked} pts')
|
| 226 |
|
|
|
|
| 518 |
|
| 519 |
#print(f'del {len(conn_to_del)} connections')
|
| 520 |
connections = np.delete(connections, (conn_to_del), axis=0)
|
| 521 |
+
connections = connections.tolist()
|
| 522 |
#print(vertices, vertices_3d, connections)
|
| 523 |
if vertices:
|
| 524 |
return vertices, vertices_3d, connections
|
|
|
|
| 599 |
continue
|
| 600 |
|
| 601 |
#uv, depth_vert = get_uv_depth(vertices, depth_np)
|
| 602 |
+
sfm_depth_np = get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, 10)
|
| 603 |
uv, depth_vert = get_smooth_uv_depth(vertices, depth_np, gest_seg_np, sfm_depth_np)
|
| 604 |
#uv, depth_vert = get_smooth_uv_depth(vertices, depth_np, gest_seg_np, None)
|
| 605 |
|
|
|
|
| 616 |
#all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image, 3.0) # TODO: 3cm looks too small
|
| 617 |
all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image, 30)
|
| 618 |
#print(f'after merge, {len(all_3d_vertices)} 3d vertices and {len(connections_3d)} 3d connections')
|
| 619 |
+
#all_3d_vertices_clean, connections_3d_clean = prune_not_connected(all_3d_vertices, connections_3d)
|
| 620 |
+
all_3d_vertices_clean, connections_3d_clean = prune_far(all_3d_vertices, connections_3d, prune_dist_thr=prune_dist_thr)
|
| 621 |
+
#all_3d_vertices_clean, connections_3d_clean = all_3d_vertices, connections_3d # don't prune -> cost:2.0
|
| 622 |
#print(f'after pruning, {len(all_3d_vertices_clean)} 3d clean vertices and {len(connections_3d_clean)} 3d clean connections')
|
| 623 |
if (len(all_3d_vertices_clean) < 2) or len(connections_3d_clean) < 1:
|
| 624 |
print (f'Not enough vertices or connections in the 3D vertices')
|