python - 分类黑色和银色图像
问题描述
我正在努力对黑色和银色的图像进行分类 如何使用 OpenCV 对它们进行分类?黑色图像 银色图像?下面有什么错误?
import numpy as np
import cv2
# RGB color boundaries
black = ([0, 0, 0], [50, 50, 50])
boundaries = [black]
#
# Load an color image in grayscale
img = cv2.imread('zmFf4.jpg')
print(img.shape)
breakpoint()
for (lower, upper) in boundaries:
# create NumPy arrays from the boundaries
lower = np.array(lower, dtype="uint8")
upper = np.array(upper, dtype="uint8")
# find the colors within the specified boundaries and apply
# the mask
mask = cv2.inRange(img, lower, upper)
output = cv2.bitwise_and(img, img, mask=mask)
# show the images
cv2.imshow("images", np.hstack([img, output]))
cv2.waitKey(0)
解决方案
你不是在寻找银色范围做如下
import numpy as np
import cv2
# RGB color boundaries
black = ([0, 0, 0], [50, 50, 50])
silver = ([192, 192, 192], [212, 212, 212])
boundaries = [black, silver]
#
# Load an color image in grayscale
img = cv2.imread('zmFf4.jpg')
print(img.shape)
breakpoint()
for (lower, upper) in boundaries:
# create NumPy arrays from the boundaries
lower = np.array(lower, dtype="uint8")
upper = np.array(upper, dtype="uint8")
# find the colors within the specified boundaries and apply
# the mask
mask = cv2.inRange(img, lower, upper)
output = cv2.bitwise_and(img, img, mask=mask)
# show the images
cv2.imshow("images", np.hstack([img, output]))
cv2.waitKey(0)
推荐阅读
- python-3.x - how to aggregate information in one column of dataframe in python3?
- r - 如何强制 R 中的 Hmisc 包舍入到小数点后 3 位?
- caching - 在 IKS 上设置 RedisCache
- java - 为什么在 AMD GPU 上运行的 Aparapi 内核允许非常大的 @Local 数组,但不支持 Nvidia?
- django - Django formset - 自定义输入 HTML
- c++ - 错误 C4716 'Party::operator+': 必须返回一个值
- php - 在 Code Igniter 中使用和条件从多个日期列中选择数据
- swift - 如何分配可变的数字范围并在函数上重用它?
- java - 我正在使用 insertSort 方法,但由于某种原因,当输出我的数组时,其中一个插入会覆盖数组中的另一个输入
- svg - 移动 Safari 中的小 SVG 失真