in opensfm/dense.py [0:0]
def compute_depthmap(arguments):
"""Compute depthmap for a single shot."""
log.setup()
data: UndistortedDataSet = arguments[0]
neighbors = arguments[1]
min_depth = arguments[2]
max_depth = arguments[3]
shot = arguments[4]
method = data.config["depthmap_method"]
if data.raw_depthmap_exists(shot.id):
logger.info("Using precomputed raw depthmap {}".format(shot.id))
return
logger.info("Computing depthmap for image {0} with {1}".format(shot.id, method))
de = pydense.DepthmapEstimator()
de.set_depth_range(min_depth, max_depth, 100)
de.set_patchmatch_iterations(data.config["depthmap_patchmatch_iterations"])
de.set_patch_size(data.config["depthmap_patch_size"])
de.set_min_patch_sd(data.config["depthmap_min_patch_sd"])
add_views_to_depth_estimator(data, neighbors, de)
if method == "BRUTE_FORCE":
depth, plane, score, nghbr = de.compute_brute_force()
elif method == "PATCH_MATCH":
depth, plane, score, nghbr = de.compute_patch_match()
elif method == "PATCH_MATCH_SAMPLE":
depth, plane, score, nghbr = de.compute_patch_match_sample()
else:
raise ValueError(
"Unknown depthmap method type "
"(must be BRUTE_FORCE, PATCH_MATCH or PATCH_MATCH_SAMPLE)"
)
good_score = score > data.config["depthmap_min_correlation_score"]
depth = depth * (depth < max_depth) * good_score
# Save and display results
neighbor_ids = [i.id for i in neighbors[1:]]
data.save_raw_depthmap(shot.id, depth, plane, score, nghbr, neighbor_ids)
if data.config["depthmap_save_debug_files"]:
image = data.load_undistorted_image(shot.id)
image = scale_down_image(image, depth.shape[1], depth.shape[0])
ply = depthmap_to_ply(shot, depth, image)
with io.open_wt(data.depthmap_file(shot.id, "raw.npz.ply")) as fout:
fout.write(ply)
if data.config.get("interactive"):
import matplotlib.pyplot as plt
plt.figure()
plt.suptitle("Shot: " + shot.id + ", neighbors: " + ", ".join(neighbor_ids))
plt.subplot(2, 3, 1)
plt.imshow(image)
plt.subplot(2, 3, 2)
plt.imshow(color_plane_normals(plane))
plt.subplot(2, 3, 3)
plt.imshow(depth)
plt.colorbar()
plt.subplot(2, 3, 4)
plt.imshow(score)
plt.colorbar()
plt.subplot(2, 3, 5)
plt.imshow(nghbr)
plt.colorbar()
plt.show()