[英]Separating the coordinates of multiple canny edge detections from opencv in python
[英]Find coordinates of a Canny Edge Image - OpenCV & python
你已经找到了边缘,现在你需要找到那些边缘的位置。
(我没有使用你提供的图像,我宁愿在桌面上使用示例图像:D)
以下行为您提供了这些坐标:
import cv2
import numpy as np
img = cv2.imread('Messi.jpg', 0)
edges = cv2.Canny(img, 100, 255) #--- image containing edges ---
现在您需要找到值大于0的坐标
indices = np.where(edges != [0])
coordinates = zip(indices[0], indices[1])
numpy.where()
方法来检索两个数组的元组indices
,其中第一个数组包含白点的x坐标,第二个数组包含白色像素的y坐标。 indices
回报:
(array([ 1, 1, 2, ..., 637, 638, 638], dtype=int64),
array([292, 298, 292, ..., 52, 49, 52], dtype=int64))
zip()
方法获取包含点的元组列表。 打印coordinates
为我提供了带边的坐标列表:
[(1, 292), (1, 298), (2, 292), .....(8, 289), (8, 295), (9, 289), (9, 295), (10, 288), (10, 289), (10, 294)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.