【问题标题】:Python OpenCV get bottom most value of maskPython OpenCV 获得掩码的最低值
【发布时间】:2017-01-22 18:02:20
【问题描述】:

我有一个图像,我从中提取颜色到掩码中,如下面的代码所示。蒙版提供黑白图像。白色是我检测到的颜色。白色的像素值为255,黑色为0。

我想获取蒙版白色部分最底部的 x 和 Y 像素。我该怎么做呢? 我的代码如下:

image = cv2.imread(FILENAME)

# THE COLOURS ARE IN RGB
lower_blue = np.array([50, 0, 0])
upper_blue = np.array([255, 50, 50])

# loop over the boundaries
#    for (lower, upper) in boundaries:
    # create NumPy arrays from the boundaries
lower = np.array(lower_blue, dtype = "uint8")
upper = np.array(upper_blue, dtype = "uint8")

# find the colors within the specified boundaries and apply
# the mask
mask = cv2.inRange(image, lower, upper)

【问题讨论】:

    标签: python-2.7 opencv


    【解决方案1】:

    您可以使用 numpy 的 where 来搜索您的掩码以获取特定值:

    np.max(np.where(np.max(img_binary,axis=1)==255)

    【讨论】:

      猜你喜欢
      • 2017-08-27
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      • 1970-01-01
      相关资源
      最近更新 更多