|
发表于 2020-3-12 15:29:41
|
显示全部楼层
from scipy.spatial import Delaunay
import numpy as np
import matplotlib.pyplot as plt
width = 80
height = 40
pointNumber = 50
points = np.zeros((pointNumber, 2))
points[:, 0] = np.random.randint(0, width, pointNumber)
points[:, 1] = np.random.randint(0, height, pointNumber)
tri = Delaunay(points)
center = np.sum(points[tri.simplices], axis=1)/3.0
color = []
for index, sim in enumerate(points[tri.simplices]):
cx, cy = center[index][0], center[index][1]
x1, y1 = sim[0][0], sim[0][1]
x2, y2 = sim[1][0], sim[1][1]
x3, y3 = sim[2][0], sim[2][1]
s = ((x1-cx)**2+(y1-cy)**2)**0.5 + ((cx-x3)**2+(cy-y3)**2)**0.5 + ((cx-x2)**2+(cy-y2)**2)**0.5
color.append(s)
color = np.array(color)
plt.figure(figsize=(20, 10))
plt.tripcolor(points[:, 0], points[:, 1], tri.simplices.copy(), facecolors=color, edgecolors='k')
plt.tick_params(labelbottom='off', labelleft='off', left='off', right='off', bottom='off', top='off')
ax = plt.gca()
plt.scatter(points[:,0],points[:,1], color='r')
#plt.grid()
plt.savefig('Delaunay.png', transparent=True, dpi=600)
plt.show()
您好,我的代码就是上面的样子,出现的问题是
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: 'scipy.spatial.qhull._Qhull.__dealloc__'
AttributeError: 'NoneType' object has no attribute 'close'
Traceback (most recent call last):
File "d:/李纲/三维相机料堆检测课设/无滤波/wulvbo/深度数据/Delaunay.py", line 13, in <module>
tri = Delaunay(points)
File "qhull.pyx", line 1839, in scipy.spatial.qhull.Delaunay.__init__
File "qhull.pyx", line 271, in scipy.spatial.qhull._Qhull.__init__
File "messagestream.pyx", line 36, in scipy._lib.messagestream.MessageStream.__init__
OSError: Failed to open file b'C:\\Users\\\xe5\xa9\xb7\xe5\xa9\xb7\xe7\x8e\x8b\\AppData\\Local\\Temp\\scipy-w5xmmmyz'
我是将代码拷贝到.py文件中运行的,请问怎么解决。感谢您的回复 |
|