Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
# manually delete it to free memory
del cost_matrix
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]
del cost_matrix
paired = np.array(imgs)[cols]
white = np.ones(imgs[0].shape, np.uint8)
white[:, :, :] = [background[2], background[1], background[0]]