我对Python很陌生,我想我试图尝试一些非常复杂的东西?我一再试图寻找这个并认为我缺少一些基础知识,因为我实在是不明白我读过的内容。
实际上我有3个数组,包含x个点,y个点和z点。它们形成近似半球形的形状。我有这些点来自于获取2D轴对称半圆形状的轮廓,将x点和y点从中提取到单独的数组中,并创建一个与前两个数组长度相同的零的“z点”数组。
然后,我将y点用角度旋转到z域,以创建2D轮廓的3D近似。
这个3D形状是完全有界的(因为它创建了底部和顶部),如下所示:
我已经从我更长的程序中剔除了以下代码,但这是与我的问题相关的唯一部分:
c, contours, _ = cv2.findContours(WB, mode = cv2.RETR_EXTERNAL, method = cv2.CHAIN_APPROX_NONE) # Find new contours in recently bisected mask
contours = sorted (contours, key = cv2.contourArea, reverse = True) # # Sort contours (there is only 2 contours left, plinth/background, and droplet)
contour = contours[1] # Second longest contour is the desired contour
xpointsList = [xpoints[0][0] for xpoints in contour] # Create new array of all x co-ordinates
ypointsList = [ypoints[0][1] for ypoints in contour] # Create new array of all y co-ordinates
zpointsList = np.zeros(len(xpointsList)) # # Create an array of 0 values to represent the z domain. True contour sits at 0 on all points in the z-domain
angles = np.arange(0,180,5, dtype = int) # # Creating an array of angles between to form a full drop in degrees of 5
i = 0
b = 0
d = 0
qx = np.zeros(len(xpointsList)*len(angles)) # Setting variable to equal the length of x points times the length of iterative angle calculations
qy = np.zeros(len(ypointsList)*len(angles)) # Setting variable to equal the length of x points times the length of iterative angle calculations
qz = np.zeros(len(zpointsList)*len(angles)) # Setting variable to equal the length of x points times the length of iterative angle calculations
ax = plt.axes(projection='3d')
for b in range(0,len(angles)):
angle = angles[b]
for i in range(0,len(ypointsList)):
qx[i+d] = xpointsList[i]-origin[0] # Setting the x-axis to equal it's current values around the origin
qz[i+d] = origin[0] + math.cos(math.radians(angle)) * (zpointsList[i]) - math.sin(math.radians(angle)) * (ypointsList[i] - origin[1]) # creating a z value based on 10 degree rotations of the y values around the x axis
qy[i+d] = origin[1] + math.sin(math.radians(angle)) * (zpointsList[i]) + math.cos(math.radians(angle)) * (ypointsList[i] - origin[1]) # adapting the y value based on the creation of the z values.
i = i + 1
b = b + 1
d = d + len (xpointsList)
ax.plot3D (qy, qz, qx, color = 'blue', linewidth = 0.1)
有效地我的问题是,如何使用这种结构以某种方式使用坐标数组找到音量?我想我需要使用某种scipy.spatial ConvexHull填充我的旋转之间的区域,以便它有一个表面并从那里开始工作?提前感谢您提供任何帮助!
答案 0 :(得分:0)
我不理解你的方法(我在Python中没那么好)所以无法帮助你修复它,但是这里有一个类似的问题,更简单的解决方案:
https://stackoverflow.com/a/48114604/1479630
你的情况更加容易,因为你基本上拥有的是一个扭曲的球体,你的表面上有一个规则的网格。您可以遍历所有曲面三角形,并为每个三角形计算由此三角形和对象中心构成的四面体体积。如果你总结这些卷,你将获得整个对象的体积。