黄色车道线的 HSL 范围 [英] HSL range for yellow lane lines

查看:24
本文介绍了黄色车道线的 HSL 范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究简单的车道检测,但在查找黄色车道线的范围/输入值时遇到了一些麻烦.

def color_filter(image):#convert to HLS to mask 基于HLShls = cv2.cvtColor(图像,cv2.COLOR_BGR2HLS)下 = np.array([0,190,0])上 = np.array([255,255,255])Yellower = np.array([40,70,60]) #不知道该放什么yelupper = np.array([50,90,65]) #不知道该放什么Yellowmask = cv2.inRange(hls, 黄色, yelupper)whitemask = cv2.inRange(hls,下,上)掩码 = cv2.bitwise_or(yellowmask, whitemask)掩码 = cv2.bitwise_and(图像,图像,掩码 = 掩码)返回蒙面

这是我过滤后的图像(仅显示白色车道):

黄色面具看起来像这样:

您的代码中的蒙版图像如下所示:

如您所见,必须对参数进行微调.但我希望,您现在已经大致了解了,并且可以继续自己的工作.

I am currently working on simple lane detection and I have some trouble finding the range/input values for yellow colored lane lines.

def color_filter(image):
    #convert to HLS to mask based on HLS
    hls = cv2.cvtColor(image, cv2.COLOR_BGR2HLS)
    lower = np.array([0,190,0])
    upper = np.array([255,255,255])

    yellower = np.array([40,70,60]) #NOT SURE WHAT TO PUT
    yelupper = np.array([50,90,65]) #NOT SURE WHAT TO PUT

    yellowmask = cv2.inRange(hls, yellower, yelupper)    
    whitemask = cv2.inRange(hls, lower, upper)

    mask = cv2.bitwise_or(yellowmask, whitemask)  
    masked = cv2.bitwise_and(image, image, mask = mask)    

    return masked

Here is the image that I've filtered (only white lanes are showing):

http://prntscr.com/ng2cgp

Here's the original image:

http://prntscr.com/ng2cx6

解决方案

I suggest, you have a further reading on how the HSL/HSV color space works, maybe starting at the Wikipedia article? Furthermore, to easily get some initial values to work on, you can use a HSL calculator, e.g. this one.

To detect white-ish parts in the image, the hue (H) value might by arbitrary, as long as the lightness (L) value is high enough (we want bright colors), and the saturation (S) value is low enough (we want low saturated colors).

In general, H values are within [0 ... 360], whereas S and L values are within [0.0 ... 1.0]. The OpenCV documentation on color conversions tells you, that these values are mapped to H within [0 ... 180], and S and L within [0 ... 255] (for 8-bit images).

Now, to detect yellow-ish parts in the image, appropriate H, S, and L values can be taken from the afore-mentioned HSL calculator by "playing around", what might fit to the colors to be found in the image.

I prepared the following example code, please have a look:

import cv2
import numpy as np

# Load input image
input = cv2.imread('images/input.png', cv2.IMREAD_COLOR)

# Convert to HLS color space
hls = cv2.cvtColor(input, cv2.COLOR_BGR2HLS)

# White-ish areas in image
# H value can be arbitrary, thus within [0 ... 360] (OpenCV: [0 ... 180])
# L value must be relatively high (we want high brightness), e.g. within [0.7 ... 1.0] (OpenCV: [0 ... 255])
# S value must be relatively low (we want low saturation), e.g. within [0.0 ... 0.3] (OpenCV: [0 ... 255])
white_lower = np.array([np.round(  0 / 2), np.round(0.75 * 255), np.round(0.00 * 255)])
white_upper = np.array([np.round(360 / 2), np.round(1.00 * 255), np.round(0.30 * 255)])
white_mask = cv2.inRange(hls, white_lower, white_upper)

# Yellow-ish areas in image
# H value must be appropriate (see HSL color space), e.g. within [40 ... 60]
# L value can be arbitrary (we want everything between bright and dark yellow), e.g. within [0.0 ... 1.0]
# S value must be above some threshold (we want at least some saturation), e.g. within [0.35 ... 1.0]
yellow_lower = np.array([np.round( 40 / 2), np.round(0.00 * 255), np.round(0.35 * 255)])
yellow_upper = np.array([np.round( 60 / 2), np.round(1.00 * 255), np.round(1.00 * 255)])
yellow_mask = cv2.inRange(hls, yellow_lower, yellow_upper)

# Calculate combined mask, and masked image
mask = cv2.bitwise_or(yellow_mask, white_mask)
masked = cv2.bitwise_and(input, input, mask = mask)

# Write output images
cv2.imwrite('images/white_mask.png', white_mask)
cv2.imwrite('images/yellow_mask.png', yellow_mask)
cv2.imwrite('images/masked.png', masked)

The white-ish mask looks like this:

The yellow-ish mask looks like this:

The masked image from your code looks like this:

As you can see, fine-tuning the parameters must be done. But I hope, you now get the general idea, and can continue on your own.

这篇关于黄色车道线的 HSL 范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆