coarse to fine search on sfm depth
Browse files- handcrafted_solution.py +23 -6
handcrafted_solution.py
CHANGED
@@ -156,9 +156,9 @@ def get_smooth_uv_depth(vertices, depth, gest_seg_np, sfm_depth_np, r=5):
|
|
156 |
def get_local_min(x,y, H, W, depth, sfm_depth_np, r=r, PRINT=False):
|
157 |
'''return a smooth version of detph in radius r'''
|
158 |
local_min = 9999999
|
159 |
-
PRINT = False
|
160 |
-
if np.isclose(x, 90.13846154, atol=10) and np.isclose(y, 1175.46495726, atol=10):
|
161 |
-
|
162 |
i_range = range(max(0, x - r), min(W, x + r))
|
163 |
j_range = range(max(0, y - r), min(H, y + r))
|
164 |
for i in i_range:
|
@@ -170,25 +170,41 @@ def get_smooth_uv_depth(vertices, depth, gest_seg_np, sfm_depth_np, r=5):
|
|
170 |
if PRINT: print(f'({j},{i})sfm:', sfm_depth_np[j, i])
|
171 |
else:
|
172 |
local_min = min(depth[j, i], local_min)
|
173 |
-
if PRINT: print(f'({j},{i})dm:', depth[j, i])
|
174 |
else:
|
175 |
local_min = min(depth[j, i], local_min)
|
176 |
-
if PRINT: print(f'({j},{i})dm:', depth[j, i])
|
177 |
return local_min
|
178 |
|
179 |
def get_priotity_local_min(x,y, H, W, depth, sfm_depth_np, r=r):
|
180 |
'''Search on sfm depth first. Search on depthmap only if no sfm depth
|
181 |
exists at all in the local region.
|
182 |
'''
|
|
|
183 |
yslice = slice(max(0, y - r), min(H, y + r))
|
184 |
xslice = slice(max(0, x - r), min(W, x + r))
|
185 |
local_area = sfm_depth_np[yslice, xslice]
|
186 |
reduced_local_area = local_area[local_area!=0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
if reduced_local_area.size > 0:
|
|
|
|
|
188 |
local_min = np.min(reduced_local_area)
|
189 |
return local_min
|
190 |
else:
|
191 |
-
|
|
|
192 |
|
193 |
def get_local_min_progressive(x,y, H, W, depth, sfm_depth_np, r=r):
|
194 |
'''If sfm is available in small local region, use it.
|
@@ -740,6 +756,7 @@ def predict(entry, visualize=False, prune_dist_thr=600, depth_scale=2.5, ) -> Tu
|
|
740 |
depth_scale = 2.5
|
741 |
elif i==2: # only visualize view 0,1
|
742 |
continue
|
|
|
743 |
if i!=0:
|
744 |
continue
|
745 |
'''
|
|
|
156 |
def get_local_min(x,y, H, W, depth, sfm_depth_np, r=r, PRINT=False):
|
157 |
'''return a smooth version of detph in radius r'''
|
158 |
local_min = 9999999
|
159 |
+
#PRINT = False
|
160 |
+
#if np.isclose(x, 90.13846154, atol=10) and np.isclose(y, 1175.46495726, atol=10):
|
161 |
+
# PRINT = True
|
162 |
i_range = range(max(0, x - r), min(W, x + r))
|
163 |
j_range = range(max(0, y - r), min(H, y + r))
|
164 |
for i in i_range:
|
|
|
170 |
if PRINT: print(f'({j},{i})sfm:', sfm_depth_np[j, i])
|
171 |
else:
|
172 |
local_min = min(depth[j, i], local_min)
|
173 |
+
#if PRINT: print(f'({j},{i})dm:', depth[j, i])
|
174 |
else:
|
175 |
local_min = min(depth[j, i], local_min)
|
176 |
+
#if PRINT: print(f'({j},{i})dm:', depth[j, i])
|
177 |
return local_min
|
178 |
|
179 |
def get_priotity_local_min(x,y, H, W, depth, sfm_depth_np, r=r):
|
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)
|
203 |
local_min = np.min(reduced_local_area)
|
204 |
return local_min
|
205 |
else:
|
206 |
+
#print('use both sfm and monocular')
|
207 |
+
return get_local_min(x,y, H, W, depth, sfm_depth_np, r, PRINT)
|
208 |
|
209 |
def get_local_min_progressive(x,y, H, W, depth, sfm_depth_np, r=r):
|
210 |
'''If sfm is available in small local region, use it.
|
|
|
756 |
depth_scale = 2.5
|
757 |
elif i==2: # only visualize view 0,1
|
758 |
continue
|
759 |
+
|
760 |
if i!=0:
|
761 |
continue
|
762 |
'''
|