[英]how to find white pixel with lowest location?
首先,最低点是具有最大 y 的点。 由于 OpenCV 图像存储在y, x, color
等数组中,因此您需要找到具有最大第 0 个坐标的点。 看来, numpy.argwhere
返回已经排序的结果,但文档并不能保证这一点。
nz = np.argwhere(res)
# to guarantee the sorting.
nz = list(nz).sort(key=lambda point: point[0])
assert nz, "No white points"
# take the last point, the point with biggest Y
Y, X = nz[-1]
然后是绘图部分。 您的图像是灰度的,因此您尝试在其上绘制的所有点都将以白色绘制。 将无法区分绘制的点,与之前存在的 To draw points 我建议将图像转换为BGR
,并绘制彩色点。
image_color = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
# note the order, (X, Y)
cv2.circle(image_color, (X, Y), 3, (0, 0, 255), -1)
# make sure you show the image, where you have drawn a circle
cv2.imshow('result',image_color)
cv2.waitKey(0)
如果您正在阅读灰度或图像本身是灰度的,我的猜测是:
values = cv2.imread('img',0)
# I am taking greater than 100, as opposed to 255 as the values may not be exactly 255
y_coord = max(np.where(values > 100)[1])
如果您正在使用二进制图像,则将条件替换为values == 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.