本文整理汇总了Python中mesh.Mesh.evolve方法的典型用法代码示例。如果您正苦于以下问题:Python Mesh.evolve方法的具体用法?Python Mesh.evolve怎么用?Python Mesh.evolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mesh.Mesh
的用法示例。
在下文中一共展示了Mesh.evolve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from mesh import Mesh [as 别名]
# 或者: from mesh.Mesh import evolve [as 别名]
def main(C):
global mesh
img = cv2.imread(C.IMAGE_URI)
cv2.cvtColor(img, cv2.COLOR_BGR2RGB, img)
# img = np.flipud(img)
if C.FOCUS_MAP is not None:
focus = cv2.imread(C.FOCUS_MAP)
focus = img2heur.grayscale(focus)
# focus = img2heur.linear(focus)
focus = img2heur.exponential(focus)
else:
focus = img2heur.default_focus_image(img)
trimath.set_image(img)
trimath.set_heuristic(focus)
mesh = Mesh(img, C.STARTING_POINTS, parallel=C.PARALLEL)
plotter.start(plotErrors=C.PRINT_ERROR_COUNTER > 0)
plotter.plot_original(img, 1 - C.TRIANGLE_ALPHA)
past = time.time()
pixtemp = C.TEMPERATURE # pixels radius
min_error = 10**16
for cnt in range(10 ** 6):
if pixtemp < 0.1:
break
mesh.evolve(pixtemp, absolute_error=C.ABSOLUTE_ERROR, parallel=C.PARALLEL)
# region purging points
# The chance to purge points.
# In the beginning when pixtemp is almost TEMPERATURE,
# the chance to purge is high. As the temperature gets lower,
# the chance to purge approaches zero.
# assert 0 <= C.PURGE_MULTIPLIER < 1
if np.random.rand() < pixtemp / C.TEMPERATURE * C.PURGE_MULTIPLIER:
mesh.slow_purge(n=10)
# endregion
pixtemp *= C.TEMP_MULTIPLIER
# endregion
# region print time
if C.PRINT_CONSOLE:
# clear the screen
import os
os.system('cls' if os.name == 'nt' else 'clear')
print("Temperature: "+str(pixtemp))
now = time.time()
print("Time elapsed: ", now - past)
past = now
#endregion
if (C.PRINT_ERROR_COUNTER > 0 and cnt % C.PRINT_ERROR_COUNTER == 0):
plotter.plot_global_errors(mesh._error)
plotter.plot_mesh_error_collection(err_col)
if (cnt % C.PRINT_COUNTER == 0):
plotter.plot_original(img, 1 - C.TRIANGLE_ALPHA)
col = FlatMeshCollection(mesh._triangulation, alpha=C.TRIANGLE_ALPHA)
err_col = FlatMeshErrorCollection(mesh._triangulation)
plotter.plot_mesh_collection(col)
# plotter.plot_error_hist(mesh.point_errors, mesh.triangle_errors)
if C.PLOT_ARROWS:
plotter.plot_points(mesh)
plotter.plot_arrow(mesh)
if mesh._error <= min_error:
min_error = mesh._error
plotter.save_mesh("out.svg")
plotter.keep_plot_open()