无法检测特定颜色的对象(RGB / HSV / HSL)

时间:2017-06-05 18:34:52

标签: python opencv image-processing opencv3.0

我的目标是探测GTA Vice City的车道。 gtares2.jpg

当我在绘画上分析这张照片时,这些线条就像RGB色彩空间中的[120,100,45]。当我用cv2.inRange应用它时,我无法得到奇怪的结果。我不知道该怎么做,也不知道为什么它没有向我展示这种黄色(实际上看起来像黄色)车道的任何迹象。

EDIT1:

我发现只获取这些行的值,它们是: 低:0,110,0 鞋面:160,195,80

以下是stack2.png

的照片

但是,当我尝试使用ImageGrab模块(在canny和gaussblur之后)在实时播放中获得此行时,我得到:

stackoverflow.png

我的目标是用HoughProbabilistic绘制车道,但是,我不能看到连续的线条,即使每次现场演奏都没有线路。我很困惑,这里是代码:

   def process_img(image):
    lower_yellow = np.array([0, 110, 0])
    upper_yellow = np.array([160, 195, 80])
    # yellow color mask
    processimagehsl = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    yellow_mask = cv2.inRange(processimagehsl, lower_yellow, upper_yellow)  # and we are masking it
    masked = cv2.bitwise_and(image, image, mask=yellow_mask)  # and then we combine it with original image
    # turned into gray
    processimagecanny = cv2.Canny(masked, threshold1=150,
                                  threshold2=300)  # with canny edge detection method, we detect edges
    # of only our yellow lines' edges. We used masking
    # at the beginning of the code because of this.
    processimagegauss = cv2.GaussianBlur(processimagecanny, (5, 5), 0)  # This'Ll fix some in order to avoid noises
    processedimage = regionofinterest(processimagegauss)  # Let's get back to our predetermined region
    lines = cv2.HoughLinesP(processedimage, 1, np.pi / 180, 180, 0, 0)

    return processedimage

解决

您可以在OpenCv上使用此应用程序选择范围,这里是链接:http://answers.opencv.org/question/134248/how-to-define-the-lower-and-upper-range-of-a-color/

以下是解释的内容:

imagepick.png

1 个答案:

答案 0 :(得分:2)

您错过cv2.HoughLinesP()中的第五个参数lines。位置参数期望订单:

cv2.HoughLinesP(image, rho, theta, threshold[, lines[, minLineLength[, maxLineGap]]])

你可以用两种方法解决这个问题;要么使用None,要求lines参数:

lines = cv2.HoughLinesP(image, rho, theta, threshold, None, minLineLength, maxLineGap)

或调用您想要使用的所有可选参数及其密钥:

lines = cv2.HoughLinesP(image, rho, theta, threshold=..., minLineLength=..., maxLineGap=...)