如何获得OpenCV RGB颜色检测滑块?

时间:2020-07-28 20:12:50

标签: python opencv color-detection

我对使用OpenCV很陌生。我正在用它来查找图像中的不同颜色,特别是针对Google Maps中的流量。我为此编写了一些代码:

import numpy as np
import argparse
import cv2
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", help = "path to the image")
args = vars(ap.parse_args())
# load the image
image = cv2.imread(args["image"])
# define the list of boundaries
boundaries = [
    ([255, 255, 255], [0, 0, 0]),
    ([75, 75, 75], [150, 150, 150]),
    ([125, 125, 125], [150, 150, 150]),
    ([150, 150, 150], [150, 150, 150])
]
# loop over the boundaries
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(image, lower, upper)
    output = cv2.bitwise_and(image, image, mask = mask)
    # show the images
    cv2.imshow("images", np.hstack([image, output]))
    cv2.waitKey(0)

我很难找到正确的RGB值,该值可以消除我想要的颜色以外的所有颜色。有没有一种方法可以创建可以更改RGB值的滑块,以便可以显示图片中被遮挡的内容?我在这里找到了使用HSV颜色的示例:Finding red color in image using Python & OpenCV

0 个答案:

没有答案
相关问题