Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# compute pair-wise distances
cost_matrix = cdist(img_keys, dest_img, metric=metric)
np_ctype = eval("np." + ctype)
cost_matrix = np_ctype(cost_matrix)
print("Computing optimal assignment on a {}x{} matrix...".format(
cost_matrix.shape[0], cost_matrix.shape[1]))
from lapjv import lapjv
if v is not None and (platform.system() == "Linux" or platform.system() == "Darwin") and v.gui:
try:
from wurlitzer import pipes, STDOUT
from wurlitzer import Wurlitzer
Wurlitzer.flush_interval = 0.1
wrapper = JVOutWrapper(v)
with pipes(stdout=wrapper, stderr=STDOUT):
_, cols, cost = lapjv(cost_matrix, verbose=1)
wrapper.finish()
except ImportError:
_, cols, cost = lapjv(cost_matrix)
else:
_, cols, cost = lapjv(cost_matrix)
cost = cost[0]
print("Total assignment cost:", cost)
print("Time taken: {}s".format((np.round(time.time() - t, 2))))
# sometimes the cost matrix may be extremely large