kcml commited on
Commit
b1dfde5
·
1 Parent(s): d42bebb
Files changed (1) hide show
  1. handcrafted_solution.py +7 -5
handcrafted_solution.py CHANGED
@@ -6,13 +6,15 @@ import numpy as np
6
  from collections import defaultdict
7
  import cv2
8
  from typing import Tuple, List
9
- from scipy.sparse import random
10
  from scipy.spatial.distance import cdist
11
 
12
  from hoho.read_write_colmap import read_cameras_binary, read_images_binary, read_points3D_binary
13
  from hoho.color_mappings import gestalt_color_mapping, ade20k_color_mapping
14
 
15
  DUMP_IMG = False
 
 
16
 
17
  def empty_solution():
18
  '''Return a minimal valid solution, i.e. 2 vertices and 1 edge.'''
@@ -234,9 +236,9 @@ def get_vertices_and_edges_from_two_segmentations(ade_seg_np, gest_seg_np, edge_
234
  apex_map_on_gest[uu+ss[0], vv+ss[1]] = (255,0,0)
235
 
236
  # imsave apex and eave_end
237
- import random
238
- rid = random.random()
239
  if DUMP_IMG:
 
 
240
  filename_apex_ade = f'apex_map_on_ade_{rid}.jpg'
241
  cv2.imwrite(filename_apex_ade, apex_map_on_ade)
242
  filename_apex_gest = f'apex_map_on_gest_{rid}.jpg'
@@ -244,7 +246,7 @@ def get_vertices_and_edges_from_two_segmentations(ade_seg_np, gest_seg_np, edge_
244
  filename_apex_map = f'apex_map_{rid}.jpg'
245
  cv2.imwrite(filename_apex_map, apex_map)
246
 
247
- print(f'{len(vertices)} vertices detected')
248
  # Connectivity
249
  apex_pts = []
250
  apex_pts_idxs = []
@@ -447,7 +449,7 @@ def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
447
  vertices_3d = cv2.convertPointsFromHomogeneous(vertices_3d).reshape(-1, 3)
448
  vert_edge_per_image[i] = vertices, connections, vertices_3d
449
  all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image, 3.0)
450
- print(f'after merge, {len(all_3d_vertices)} 3d vertices and {len(connections_3d)} 3d connections')
451
  #all_3d_vertices_clean, connections_3d_clean = prune_not_connected(all_3d_vertices, connections_3d)
452
  all_3d_vertices_clean, connections_3d_clean = all_3d_vertices, connections_3d # don't prune -> cost:2.0
453
  #print(f'after pruning, {len(all_3d_vertices_clean)} 3d clean vertices and {len(connections_3d_clean)} 3d clean connections')
 
6
  from collections import defaultdict
7
  import cv2
8
  from typing import Tuple, List
9
+
10
  from scipy.spatial.distance import cdist
11
 
12
  from hoho.read_write_colmap import read_cameras_binary, read_images_binary, read_points3D_binary
13
  from hoho.color_mappings import gestalt_color_mapping, ade20k_color_mapping
14
 
15
  DUMP_IMG = False
16
+ if DUMP_IMG:
17
+ from scipy.sparse import random
18
 
19
  def empty_solution():
20
  '''Return a minimal valid solution, i.e. 2 vertices and 1 edge.'''
 
236
  apex_map_on_gest[uu+ss[0], vv+ss[1]] = (255,0,0)
237
 
238
  # imsave apex and eave_end
 
 
239
  if DUMP_IMG:
240
+ import random
241
+ rid = random.random()
242
  filename_apex_ade = f'apex_map_on_ade_{rid}.jpg'
243
  cv2.imwrite(filename_apex_ade, apex_map_on_ade)
244
  filename_apex_gest = f'apex_map_on_gest_{rid}.jpg'
 
246
  filename_apex_map = f'apex_map_{rid}.jpg'
247
  cv2.imwrite(filename_apex_map, apex_map)
248
 
249
+ #print(f'{len(vertices)} vertices detected')
250
  # Connectivity
251
  apex_pts = []
252
  apex_pts_idxs = []
 
449
  vertices_3d = cv2.convertPointsFromHomogeneous(vertices_3d).reshape(-1, 3)
450
  vert_edge_per_image[i] = vertices, connections, vertices_3d
451
  all_3d_vertices, connections_3d = merge_vertices_3d(vert_edge_per_image, 3.0)
452
+ #print(f'after merge, {len(all_3d_vertices)} 3d vertices and {len(connections_3d)} 3d connections')
453
  #all_3d_vertices_clean, connections_3d_clean = prune_not_connected(all_3d_vertices, connections_3d)
454
  all_3d_vertices_clean, connections_3d_clean = all_3d_vertices, connections_3d # don't prune -> cost:2.0
455
  #print(f'after pruning, {len(all_3d_vertices_clean)} 3d clean vertices and {len(connections_3d_clean)} 3d clean connections')