avoid zero detection
Browse files- handcrafted_solution.py +8 -5
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,7 @@ 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 +207,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 +221,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 |
|
@@ -602,6 +602,9 @@ def predict(entry, visualize=False, prune_dist_thr=600, depth_scale=2.5, ) -> Tu
|
|
602 |
vert_edge_per_image[i] = np.empty((0, 2)), [], np.empty((0, 3))
|
603 |
continue
|
604 |
'''
|
|
|
|
|
|
|
605 |
|
606 |
#uv, depth_vert = get_uv_depth(vertices, depth_np)
|
607 |
sfm_depth_np = get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, 5) # Sensitive. 10 is worse than 0 in testset
|
@@ -619,7 +622,7 @@ def predict(entry, visualize=False, prune_dist_thr=600, depth_scale=2.5, ) -> Tu
|
|
619 |
|
620 |
vert_edge_per_image[i] = vertices, connections, vertices_3d
|
621 |
#all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image, 3.0) # TODO: 3cm looks too small
|
622 |
-
all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image,
|
623 |
#print(f'after merge, {len(all_3d_vertices)} 3d vertices and {len(connections_3d)} 3d connections')
|
624 |
#all_3d_vertices_clean, connections_3d_clean = prune_not_connected(all_3d_vertices, connections_3d)
|
625 |
all_3d_vertices_clean, connections_3d_clean = prune_far(all_3d_vertices, connections_3d, prune_dist_thr=prune_dist_thr)
|
|
|
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 |
|
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 |
#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 |
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 |
|
|
|
602 |
vert_edge_per_image[i] = np.empty((0, 2)), [], np.empty((0, 3))
|
603 |
continue
|
604 |
'''
|
605 |
+
if (len(vertices) < 1):
|
606 |
+
vert_edge_per_image[i] = np.empty((0, 2)), [], np.empty((0, 3))
|
607 |
+
continue
|
608 |
|
609 |
#uv, depth_vert = get_uv_depth(vertices, depth_np)
|
610 |
sfm_depth_np = get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, 5) # Sensitive. 10 is worse than 0 in testset
|
|
|
622 |
|
623 |
vert_edge_per_image[i] = vertices, connections, vertices_3d
|
624 |
#all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image, 3.0) # TODO: 3cm looks too small
|
625 |
+
all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image, 150)
|
626 |
#print(f'after merge, {len(all_3d_vertices)} 3d vertices and {len(connections_3d)} 3d connections')
|
627 |
#all_3d_vertices_clean, connections_3d_clean = prune_not_connected(all_3d_vertices, connections_3d)
|
628 |
all_3d_vertices_clean, connections_3d_clean = prune_far(all_3d_vertices, connections_3d, prune_dist_thr=prune_dist_thr)
|