您可以使用 numpy 函数来实现您正在寻找的内容:
numpy.where(condition[, x, y])
链接中功能的详细解释:https://docs.scipy.org/doc/numpy-1.15.1/reference/ generated/numpy.where.html https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.where.html
在您的情况下,您希望它返回具有非零值的坐标。使用此方法,您可以在空数组上绘制任何内容,它将返回与非零对应的所有行和列。
它将返回满足您设置的条件的数组的索引。下面是显示用法示例的代码。
import cv2
import numpy as np
raw_img = cv2.imread('sample_picture.png')
x = 50
y = 50
rad = 20
cv2.circle(raw_img,(x,y),rad,(0,255,0),-1)
# Here is where you can obtain the coordinate you are looking for
combined = raw_img[:,:,0] + raw_img[:,:,1] + raw_img[:,:,2]
rows, cols, channel = np.where(combined > 0)
cv2.imshow('output', raw_img)
cv2.waitKey(0)
cv2.destroyAllWindows()