《Python计算机视觉编程》(《Programming Computer Vision with Python》)一书的第三章第二节分段仿射扭曲一节中,使用狄洛克三角剖分方法时提示错误
ModuleNotFoundError: No module named ‘matplotlib.delaunay’
即,matplotlib库中已经不再支持delaunay模块了。所以我们需要寻找一个别的模块来代替它。我在网上找到了from scipy.spatial import Delaunay
这个方法,scipy库中依然保留有这个模块,所以可以用scipy库来代替matplotlib这个库。
具体实现函数如下:(取自网络)
from scipy.spatial import Delaunay
import numpy as np
import matplotlib.pyplot as plt
# Triangle Settings
width = 100
height = 100
pointNumber = 100
points = np.zeros((pointNumber, 2))
points[:, 0] = np.random.randint(0, width, pointNumber)
points[:, 1] = np.random.randint(0, height, pointNumber)
# Use scipy.spatial.Delaunay for Triangulation
tri = Delaunay(points)
# Plot Delaunay triangle with color filled
center = np.sum(points[tri.simplices], axis=1)/3.0
color = np.array([(x - width/2)**2 + (y - height/<