Canny邊緣檢測(cè)+霍夫變換
顏色閾值+圖像掩模的方法雖然簡(jiǎn)單,但是只能應(yīng)對(duì)一些固定顏色車道線的場(chǎng)景。圖像像素受光照影響將是一個(gè)極其常見的問題。
canny邊緣檢測(cè)+霍夫變換是另外一種簡(jiǎn)單提取車道線的方法。首先依靠canny提取到原圖像的邊緣信息,再依靠霍夫變換提取滿足要求的直線
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import cv2
# Read in and grayscale the image
image = mpimg.imread('test.jpg')
gray = cv2.cvtColor(image,cv2.COLOR_RGB2GRAY)
# Define a kernel size and apply Gaussian smoothing
kernel_size = 5
blur_gray = cv2.GaussianBlur(gray,(kernel_size, kernel_size),0)
# Define our parameters for Canny and apply
low_threshold = 50
high_threshold = 150
edges = cv2.Canny(blur_gray, low_threshold, high_threshold)
# Next we'll create a masked edges image using cv2.fillPoly()
mask = np.zeros_like(edges)
ignore_mask_color = 255
# This time we are defining a four sided polygon to mask
imshape = image.shape
vertices = np.array([[(0,imshape[0]),(0, 0), (imshape[1], 0), (imshape[1],imshape[0])]], dtype=np.int32) # all image
# vertices = np.array([[(0,imshape[0]),(554, 460), (700, 446), (imshape[1],imshape[0])]], dtype=np.int32) # defining a quadrilateral region
cv2.fillPoly(mask, vertices, ignore_mask_color)
masked_edges = cv2.bitwise_and(edges, mask)
# Define the Hough transform parameters
# Make a blank the same size as our image to draw on
rho = 1 # distance resolution in pixels of the Hough grid
theta = np.pi/180 # angular resolution in radians of the Hough grid
threshold = 1 # minimum number of votes (intersections in Hough grid cell)
min_line_length = 5 #minimum number of pixels making up a line
max_line_gap = 1 # maximum gap in pixels between connectable line segments
line_image = np.copy(image)*0 # creating a blank to draw lines on
# Run Hough on edge detected image
# Output "lines" is an array containing endpoints of detected line segments
lines = cv2.HoughLinesP(masked_edges, rho, theta, threshold, np.array([]),
min_line_length, max_line_gap)
# Iterate over the output "lines" and draw lines on a blank image
for line in lines:
for x1,y1,x2,y2 in line:
cv2.line(line_image,(x1,y1),(x2,y2),(255,0,0),10)
# Create a "color" binary image to combine with line image
color_edges = np.dstack((edges, edges, edges))
# Draw the lines on the edge image
lines_edges = cv2.addWeighted(color_edges, 0.8, line_image, 1, 0)
plt.imshow(lines_edges)
plt.show()
canny邊緣后,進(jìn)行霍夫直線檢測(cè)的結(jié)果
在此基礎(chǔ)上,增加一個(gè)四邊形的圖像掩模的結(jié)果
四邊形的設(shè)定,寫在了代碼中,只是進(jìn)行了注釋
總結(jié):
以上兩種方法只適合簡(jiǎn)單的demo,顯然并不能識(shí)別具備一定曲率的車道線,也無法適應(yīng)光照不同的情況。
-
邊緣檢測(cè)
+關(guān)注
關(guān)注
0文章
94瀏覽量
18422 -
Canny
+關(guān)注
關(guān)注
0文章
14瀏覽量
9826 -
python
+關(guān)注
關(guān)注
56文章
4827瀏覽量
86761
發(fā)布評(píng)論請(qǐng)先 登錄
Canny雙閾值邊緣檢測(cè)和弱邊緣連接詳解
基于Canny邊緣檢測(cè)算子的圖像檢索算法
【DragonBoard 410c試用體驗(yàn)】之OpenCV中canny算子邊緣檢測(cè)
關(guān)于canny算子邊緣檢測(cè)的問題
Labview圖像處理——邊緣檢測(cè)
基于圖像的車道線檢測(cè)
基于Canny 法的紅外小目標(biāo)邊緣檢測(cè)方法
基于Canny邊緣檢測(cè)算子的圖像檢索算法
基于Canny算法的改進(jìn)Kirsch人臉邊緣檢測(cè)方法
基于邊界特征的車道標(biāo)識(shí)線檢測(cè)方法

一套車道線檢測(cè)系統(tǒng)

使用iVeia視覺套件進(jìn)行Canny邊緣檢測(cè)HLS IP
python中用區(qū)域掩模實(shí)現(xiàn)車道線檢測(cè)

評(píng)論