disable image dump
Browse files- handcrafted_solution.py +19 -13
handcrafted_solution.py
CHANGED
|
@@ -12,6 +12,7 @@ from scipy.spatial.distance import cdist
|
|
| 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 |
|
| 16 |
def empty_solution():
|
| 17 |
'''Return a minimal valid solution, i.e. 2 vertices and 1 edge.'''
|
|
@@ -122,9 +123,10 @@ def get_uv_depth(vertices, depth):
|
|
| 122 |
vertex_depth = depth[(uv_int[:, 1] , uv_int[:, 0])]
|
| 123 |
return uv, vertex_depth
|
| 124 |
|
| 125 |
-
def get_smooth_uv_depth(vertices, depth):
|
| 126 |
'''Get the depth of the vertices from the depth image'''
|
| 127 |
-
#print(f'max depth = {np.max(depth)}')
|
|
|
|
| 128 |
uv = []
|
| 129 |
for v in vertices:
|
| 130 |
uv.append(v['xy'])
|
|
@@ -139,15 +141,17 @@ def get_smooth_uv_depth(vertices, depth):
|
|
| 139 |
for i in range(max(0, x - r), min(W, x + r + 1)):
|
| 140 |
for j in range(max(0, y - r), min(H, y + r + 1)):
|
| 141 |
if np.sqrt((i - x)**2 + (j - y)**2) <= r:
|
| 142 |
-
|
| 143 |
return local_depths
|
| 144 |
|
| 145 |
vertex_depth = []
|
| 146 |
for x,y in zip(a,b):
|
| 147 |
local_depths = get_local_depth(x,y, H, W, depth, 5)
|
|
|
|
| 148 |
local_mean = np.mean(local_depths)
|
| 149 |
vertex_depth.append(local_mean)
|
| 150 |
vertex_depth = np.array(vertex_depth)
|
|
|
|
| 151 |
|
| 152 |
return uv, vertex_depth
|
| 153 |
|
|
@@ -232,12 +236,13 @@ def get_vertices_and_edges_from_two_segmentations(ade_seg_np, gest_seg_np, edge_
|
|
| 232 |
# imsave apex and eave_end
|
| 233 |
import random
|
| 234 |
rid = random.random()
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
|
|
|
| 241 |
|
| 242 |
print(f'{len(vertices)} vertices detected')
|
| 243 |
# Connectivity
|
|
@@ -284,8 +289,9 @@ def get_vertices_and_edges_from_two_segmentations(ade_seg_np, gest_seg_np, edge_
|
|
| 284 |
for a_i, a in enumerate(connected_verts):
|
| 285 |
for b in connected_verts[a_i+1:]:
|
| 286 |
connections.append((a, b))
|
| 287 |
-
|
| 288 |
-
|
|
|
|
| 289 |
return vertices, connections
|
| 290 |
|
| 291 |
def get_uv_dept_category(vertices, depth, ade_seg):
|
|
@@ -424,8 +430,8 @@ def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
|
|
| 424 |
print (f'Not enough vertices or connections in image {i}')
|
| 425 |
vert_edge_per_image[i] = np.empty((0, 2)), [], np.empty((0, 3))
|
| 426 |
continue
|
| 427 |
-
#uv, depth_vert = get_uv_depth(vertices, depth_np)
|
| 428 |
-
uv, depth_vert = get_smooth_uv_depth(vertices, depth_np)
|
| 429 |
|
| 430 |
# Normalize the uv to the camera intrinsics
|
| 431 |
xy_local = np.ones((len(uv), 3))
|
|
|
|
| 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.'''
|
|
|
|
| 123 |
vertex_depth = depth[(uv_int[:, 1] , uv_int[:, 0])]
|
| 124 |
return uv, vertex_depth
|
| 125 |
|
| 126 |
+
def get_smooth_uv_depth(vertices, depth, gest_seg_np):
|
| 127 |
'''Get the depth of the vertices from the depth image'''
|
| 128 |
+
#print(f'max depth = {np.max(depth)}')
|
| 129 |
+
|
| 130 |
uv = []
|
| 131 |
for v in vertices:
|
| 132 |
uv.append(v['xy'])
|
|
|
|
| 141 |
for i in range(max(0, x - r), min(W, x + r + 1)):
|
| 142 |
for j in range(max(0, y - r), min(H, y + r + 1)):
|
| 143 |
if np.sqrt((i - x)**2 + (j - y)**2) <= r:
|
| 144 |
+
local_depths.append(depth[j, i])
|
| 145 |
return local_depths
|
| 146 |
|
| 147 |
vertex_depth = []
|
| 148 |
for x,y in zip(a,b):
|
| 149 |
local_depths = get_local_depth(x,y, H, W, depth, 5)
|
| 150 |
+
#print(f'local_depths={local_depths}')
|
| 151 |
local_mean = np.mean(local_depths)
|
| 152 |
vertex_depth.append(local_mean)
|
| 153 |
vertex_depth = np.array(vertex_depth)
|
| 154 |
+
|
| 155 |
|
| 156 |
return uv, vertex_depth
|
| 157 |
|
|
|
|
| 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'
|
| 243 |
+
cv2.imwrite(filename_apex_gest, apex_map_on_gest)
|
| 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
|
|
|
|
| 289 |
for a_i, a in enumerate(connected_verts):
|
| 290 |
for b in connected_verts[a_i+1:]:
|
| 291 |
connections.append((a, b))
|
| 292 |
+
if DUMP_IMG:
|
| 293 |
+
filename_edges_map = f'edges_map_{rid}.jpg'
|
| 294 |
+
cv2.imwrite(filename_edges_map, line_img)
|
| 295 |
return vertices, connections
|
| 296 |
|
| 297 |
def get_uv_dept_category(vertices, depth, ade_seg):
|
|
|
|
| 430 |
print (f'Not enough vertices or connections in image {i}')
|
| 431 |
vert_edge_per_image[i] = np.empty((0, 2)), [], np.empty((0, 3))
|
| 432 |
continue
|
| 433 |
+
#uv, depth_vert = get_uv_depth(vertices, depth_np)
|
| 434 |
+
uv, depth_vert = get_smooth_uv_depth(vertices, depth_np, gest_seg_np)
|
| 435 |
|
| 436 |
# Normalize the uv to the camera intrinsics
|
| 437 |
xy_local = np.ones((len(uv), 3))
|