python - opencv python具有坐标的三角形网格

标签 python opencv mesh triangular

我在 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

尼姆:https://dl.dropboxusercontent.com/u/710615/nimg.jpg

最佳答案

使用 numpy-STL ( https://github.com/WoLpH/numpy-stl ) 我可以轻松打开、读取和渲染文件:

from stl import mesh
from matplotlib import collections
from matplotlib import pyplot

# Create a figure and axes
figure, axes = pyplot.subplots()

# Read the STL file
your_mesh = mesh.Mesh.from_file('stlMidPoint.stl')

# Scale the image to the STL dimensions
axes.set_xlim(your_mesh.min_[0], your_mesh.max_[0])
axes.set_ylim(your_mesh.min_[1], your_mesh.max_[1])

# Add the polygons, but only the X and Y axis since it's 2D
axes.add_collection(collections.PolyCollection(your_mesh.vectors[:, :, :2]))

# Make sure the aspect ratio stays correct
pyplot.gca().set_aspect('equal')

# Render!
pyplot.show()

然而,巨大的尺寸让它真的很慢。

enter image description here

关于python - opencv python具有坐标的三角形网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36063129/

相关文章:

r - 如何使用R中的tmesh3d使用shade3d或wire3d在RGL中制作3D网格

javascript - 三.js。应用 EdgesHelper 后更改网格位置

python - numpy 与 python : convert 3d array to 2d

iphone - 在 iPhone 中使用 OpenCV 从图像创建视频

opencv - OpenCV CAMSHIFT 使用什么样的直方图,是比率还是加权?

python - 使用openCV python查找骨架与边界之间的距离

c++ - Wavefront OBJ 解析 - 为什么我总是得到不正确的数据作为输出?

python - Pyparsing:包含至少一个非数字字符的单词

python - Pandas 映射到 TRUE/FALSE 作为字符串,而不是 bool 值

python - 如何匹配字符串中任意位置的两个字符