[英]How to apply the distance formula to a list of [x,y] coordinates in python
[英]how to convert list of indices into x , y coordinates in python
我有从打开的 CV 中的凸 Hull() 获得的索引列表我想要该索引的 x 和 y 坐标。我已经尝试使用返回值 true 但我不能进一步使用 Convexity Defects()。 那么有什么方法可以获取坐标以及在打开的 CV 中使用凸性缺陷()。 我想要索引的 x 和 y 坐标。 这是我的代码,
`hull = cv2.convexHull(c, clockwise=True, returnPoints=False)
#print(hull)
hull1 = []
for i in hull:
if len(hull1) == 0:
hull1.append(i)
else:
last = hull1[-1]
diff = c[i] - c[last]
if cv2.norm(diff) > 20:
hull1.append(i)
hull1 = np.asarray(hull1)
hull2 = hull1[:-1].copy()
#print(hull2)
#print(outer_points)
defects = cv2.convexityDefects(c, hull2)
#print(defects)
find = []
for i in range(defects.shape[0]):
s, e, f, d = defects[i, 0]
far = tuple(c[f][0])
cv2.circle(img1, far, 5, [0, 0, 255], -1)`
相信您已经找到了正在操作的图像的轮廓; 您现在可以做的是使用凸缺陷的起点并创建一个数组来保存缺陷起点的特定 x 坐标
我的意思是:
_,contour,_ = cv2.findcontour()
#contour is a list holding (x,y) coordinate
con_hull = cv2.convexhull()
con_defect = cv2.convexitydefects(con_hull, contour)
由于凸性缺陷是 (start_pt, end_pt, farthest_pt, depth) 我们找到所有的起点:
start = con_defect[:,0][:,0]
x_coord = np.array(contours[s][:,0][:,0]
y_coord = np.array(contours[s][:,0][:,1])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.