python - 获取图像中红色的坐标(0.01*dst.max()) - python

标签 python image-processing

我正在解决一个问题,以获取图像中特定颜色的坐标。所以我遇到了下面的代码,我不知道第四行和第五行。有人可以解释为什么使用 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/

相关文章:

matlab - 添加高斯噪声的 Var

Java AffineTransformOp内存问题

opencv - 来自低质量图像的超分辨率图像

google-chrome - Firefox 和 Chrome 之间的 webgl 性能差异

python - Tight_Layout : Attribute Error . 'AxesSubplot' 对象没有属性 'tight_layout'

python - 如何使用python转换csv文件中文件夹中的多个xml文件?

python - Spyder 随机无法定位 chromedriver

python - 从二维数组中删除行?

python - 如何使用opencv计算给定底部的矩形的顶部坐标?

python - 在 matplotlib 注释中格式化数学文本