我正在解决一个问题,以获取图像中特定颜色的坐标。所以我遇到了下面的代码,我不知道第四行和第五行。有人可以解释为什么使用 0.01 * dst.max() 的概念吗?提前致谢。
b, g, r = cv2.split(img)
gray = np.float32(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY))
dst = cv2.cornerHarris(gray, 2, 3, 0.04)
dst = np.where((dst > 0.01 * dst.max()) & (r > 130) & (g < 100) & (b < 100), dst, 0)
img[dst > 0.01 * dst.max()] = [0, 255, 0]
coord = np.where(np.all(img == (0, 255, 0), axis=-1))
coorarray = zip(coord[0], coord[1])
最佳答案
代码给出了图像中“角”的坐标。
dst > 0.01 * dst.max()
是“cornerHarris”进行的“角点”检测的阈值。 在“角”信号有意义的情况下(dst > 0.01 * dst.max()),您创建一个新的空白图像,并仅将感兴趣的像素设为黑色:
img[dst > 0.01 * dst.max()] = [0, 255, 0].
然后它确定那些黑色像素的坐标:
coord = np.where(np.all(img == (0, 255, 0), axis=-1))
在您的情况下,如果您想进行特定的颜色检测,则不需要“dst”线,您必须对颜色进行选择:
colorSelection = (r == 130) & (g == 100) & (b == 100) ### select your color rgb img[colorSelection] = [0, 255, 0] ### create a black/white image coord = np.where(np.all(img == (0, 255, 0), axis=-1)) ### find the coordinate of your interesting pixels
关于python - 获取图像中红色的坐标(0.01*dst.max()) - python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42503528/