OpenCV小案例(1)——判断图片中是否包含指定颜色

img = cv2.imread(picture_path)
img_hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)

lower_blue = np.array([100, 30, 100])
upper_blue = np.array([150, 255, 255])

mask = cv2.inRange(img_hsv, lower_blue, upper_blue)

res = cv2.bitwise_and(img, img, mask=mask)
r, g, b = cv2.split(res)
r_num = 0
for i in b:
    for j in i:
        if j > 170:
            r_num += 1
if r_num > 30:
print(picture_path)

你可能感兴趣的:(opencv,Python,opencv,计算机视觉,python)