kcml commited on
Commit
2d29c49
·
1 Parent(s): bc43a94

dummy conn

Browse files
Files changed (1) hide show
  1. handcrafted_solution.py +16 -19
handcrafted_solution.py CHANGED
@@ -180,23 +180,18 @@ def get_smooth_uv_depth(vertices, depth, gest_seg_np, sfm_depth_np, r=5):
180
  '''Search on sfm depth first. Search on depthmap only if no sfm depth
181
  exists at all in the local region.
182
  '''
183
- r = 5
184
- yslice = slice(max(0, y - r), min(H, y + r))
185
- xslice = slice(max(0, x - r), min(W, x + r))
186
- local_area = sfm_depth_np[yslice, xslice]
187
- reduced_local_area = local_area[local_area!=0]
188
  PRINT = False
189
- #if np.isclose(x, 2574.81093605, atol=10) and np.isclose(y, 1063.7265987, atol=10):
190
- # PRINT = True
191
-
192
- while (reduced_local_area.size == 0) and r<200:
193
- #print('r=', r)
194
- r*=2
195
  yslice = slice(max(0, y - r), min(H, y + r))
196
  xslice = slice(max(0, x - r), min(W, x + r))
197
  local_area = sfm_depth_np[yslice, xslice]
198
- reduced_local_area = local_area[local_area!=0]
199
-
 
 
 
 
200
  if reduced_local_area.size > 0:
201
  #print('use sfm')
202
  if PRINT: print(reduced_local_area)
@@ -256,7 +251,7 @@ def get_smooth_uv_depth(vertices, depth, gest_seg_np, sfm_depth_np, r=5):
256
  vertex_depth = np.array(vertex_depth)
257
  return uv, vertex_depth
258
 
259
- '''
260
  from numba import njit, prange
261
  @njit(parallel=True)
262
  def fill_range(u, v, z, dilate_r, c, sfm_depth_np, sfm_color_np, H, W):
@@ -270,7 +265,7 @@ def fill_range(u, v, z, dilate_r, c, sfm_depth_np, sfm_color_np, H, W):
270
  if DUMP_IMG:
271
  sfm_color_np[j, i] = c
272
  return sfm_depth_np, sfm_color_np
273
- '''
274
 
275
  def get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, dilate_r = 5):
276
  '''Project 3D sfm pointcloud to the image plane '''
@@ -299,7 +294,7 @@ def get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, dilate_r = 5):
299
  #checked = 0
300
  #print('dim of us uv zs rgb:', len(us), len(vs), len(zs), len(rgb))
301
  for u,v,z,c in zip(us,vs,zs, rgb):
302
- '''
303
  sfm_depth_np, sfm_color_np = fill_range(u, v, z, dilate_r, c, sfm_depth_np, sfm_color_np, H, W)
304
  '''
305
  i_range = range(max(0, u - dilate_r), min(W, u + dilate_r))
@@ -313,7 +308,7 @@ def get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, dilate_r = 5):
313
  sfm_depth_np[j, i] = z
314
  if DUMP_IMG:
315
  sfm_color_np[j, i] = c
316
-
317
 
318
 
319
  #print(f'checked {checked} pts')
@@ -424,7 +419,7 @@ def get_vertices_and_edges_from_two_segmentations(ade_seg_np, gest_seg_np, edge_
424
  apex_pts.append(v['xy'])
425
  apex_pts_idxs.append(j)
426
  apex_pts = np.array(apex_pts)
427
-
428
  # Ridge connects two apex points
429
  def Ridge_connects_two_apex_points(gest_seg_np, color_th, apex_pts, edge_th):
430
  conn = []
@@ -511,7 +506,7 @@ def get_vertices_and_edges_from_two_segmentations(ade_seg_np, gest_seg_np, edge_
511
 
512
  return conn, mask
513
  connections, line_img = classifyPairs(apex_pts, apex_pts_idxs, gest_seg_np, apex_mask, eave_end_mask)
514
- '''
515
  #print(f'{len(vertices)} vertices: {vertices}')
516
  #print(len(connections), ' connections: ', connections)
517
  if DUMP_IMG:
@@ -808,6 +803,8 @@ def predict(entry, visualize=False, prune_dist_thr=600, depth_scale=2.5, ) -> Tu
808
  all_3d_vertices_clean, connections_3d_clean = prune_far(all_3d_vertices, connections_3d, prune_dist_thr=prune_dist_thr)
809
  else:
810
  all_3d_vertices_clean, connections_3d_clean = all_3d_vertices, connections_3d
 
 
811
  #all_3d_vertices_clean, connections_3d_clean = all_3d_vertices, connections_3d # don't prune -> cost:2.0
812
  #print(f'after pruning, {len(all_3d_vertices_clean)} 3d clean vertices and {len(connections_3d_clean)} 3d clean connections')
813
  if (len(all_3d_vertices_clean) < 2) or len(connections_3d_clean) < 1:
 
180
  '''Search on sfm depth first. Search on depthmap only if no sfm depth
181
  exists at all in the local region.
182
  '''
 
 
 
 
 
183
  PRINT = False
184
+ r_choices = [75]
185
+ for r in r_choices:
 
 
 
 
186
  yslice = slice(max(0, y - r), min(H, y + r))
187
  xslice = slice(max(0, x - r), min(W, x + r))
188
  local_area = sfm_depth_np[yslice, xslice]
189
+ reduced_local_area = local_area[local_area!=0]
190
+ #if np.isclose(x, 2574.81093605, atol=10) and np.isclose(y, 1063.7265987, atol=10):
191
+ # PRINT = True
192
+ if reduced_local_area.size > 0:
193
+ break
194
+ #print('r=', r)
195
  if reduced_local_area.size > 0:
196
  #print('use sfm')
197
  if PRINT: print(reduced_local_area)
 
251
  vertex_depth = np.array(vertex_depth)
252
  return uv, vertex_depth
253
 
254
+
255
  from numba import njit, prange
256
  @njit(parallel=True)
257
  def fill_range(u, v, z, dilate_r, c, sfm_depth_np, sfm_color_np, H, W):
 
265
  if DUMP_IMG:
266
  sfm_color_np[j, i] = c
267
  return sfm_depth_np, sfm_color_np
268
+ ''''''
269
 
270
  def get_SfM_depth(points3D, depth_np, gest_seg_np, K, R, t, dilate_r = 5):
271
  '''Project 3D sfm pointcloud to the image plane '''
 
294
  #checked = 0
295
  #print('dim of us uv zs rgb:', len(us), len(vs), len(zs), len(rgb))
296
  for u,v,z,c in zip(us,vs,zs, rgb):
297
+
298
  sfm_depth_np, sfm_color_np = fill_range(u, v, z, dilate_r, c, sfm_depth_np, sfm_color_np, H, W)
299
  '''
300
  i_range = range(max(0, u - dilate_r), min(W, u + dilate_r))
 
308
  sfm_depth_np[j, i] = z
309
  if DUMP_IMG:
310
  sfm_color_np[j, i] = c
311
+ '''
312
 
313
 
314
  #print(f'checked {checked} pts')
 
419
  apex_pts.append(v['xy'])
420
  apex_pts_idxs.append(j)
421
  apex_pts = np.array(apex_pts)
422
+ '''
423
  # Ridge connects two apex points
424
  def Ridge_connects_two_apex_points(gest_seg_np, color_th, apex_pts, edge_th):
425
  conn = []
 
506
 
507
  return conn, mask
508
  connections, line_img = classifyPairs(apex_pts, apex_pts_idxs, gest_seg_np, apex_mask, eave_end_mask)
509
+
510
  #print(f'{len(vertices)} vertices: {vertices}')
511
  #print(len(connections), ' connections: ', connections)
512
  if DUMP_IMG:
 
803
  all_3d_vertices_clean, connections_3d_clean = prune_far(all_3d_vertices, connections_3d, prune_dist_thr=prune_dist_thr)
804
  else:
805
  all_3d_vertices_clean, connections_3d_clean = all_3d_vertices, connections_3d
806
+
807
+ connections_3d_clean = [(0, 1)]
808
  #all_3d_vertices_clean, connections_3d_clean = all_3d_vertices, connections_3d # don't prune -> cost:2.0
809
  #print(f'after pruning, {len(all_3d_vertices_clean)} 3d clean vertices and {len(connections_3d_clean)} 3d clean connections')
810
  if (len(all_3d_vertices_clean) < 2) or len(connections_3d_clean) < 1: