我在 stl 文件中有一个网格(https://dl.dropboxusercontent.com/u/710615/stlMidpoint.stl)
使用此代码:
from stl import mesh
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import cv2
def unique(a):
order = np.lexsort(a.T)
a = a[order]
diff = np.diff(a, axis=0)
ui = np.ones(len(a), 'bool')
ui[1:] = (diff != 0).any(axis=1)
return a[ui]
A = np.loadtxt("vectors.txt")
A = A[np.logical_not(A[:,2] > 0)]
uniqA = unique(A)
coordA = A[:,0:2]
我能够得到与三角形表面的点有对应关系(我认为)的坐标。我正在尝试绘制三角形但没有成功。这些点在那里,但不是三角形格式。我正在使用波兰语:
img= cv2.imread('nimg.jpg')
imgMask = np.ones(img.shape[:2], dtype="uint8")*255
m_xor= np.ones(imgMask.shape, dtype="uint8") * 255
points = np.array(uniqA[:,0:2], np.int32)
print points
cv2.polylines( m_xor,[points], 1, (0,0,0))
cv2.imwrite('result.jpg', m_xor)
矢量.txt:https ://dl.dropboxusercontent.com/u/710615/vectors.txt