顏色閾值+圖像掩模的方法雖然簡單,但是只能應對一些固定顏色車道線的場景。圖像像素受光照影響將是一個極其常見的問題。
canny邊緣檢測+霍夫變換是另外一種簡單提取車道線的方法。首先依靠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邊緣后,進行霍夫直線檢測的結果
在此基礎上,增加一個四邊形的圖像掩模的結果
四邊形的設定,寫在了代碼中,只是進行了注釋
總結:
以上兩種方法只適合簡單的demo,顯然并不能識別具備一定曲率的車道線,也無法適應光照不同的情況。
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權轉載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規(guī)問題,請聯(lián)系本站處理。
舉報投訴
-
邊緣檢測
+關注
關注
0文章
92瀏覽量
18249 -
Canny
+關注
關注
0文章
14瀏覽量
9713 -
python
+關注
關注
56文章
4807瀏覽量
85039
發(fā)布評論請先 登錄
相關推薦
基于Canny邊緣檢測算子的圖像檢索算法
【摘要】:針對依賴傳統(tǒng)Canny算子的基于邊緣的圖像檢索系統(tǒng)所存在的不足,提出一種基于Canny邊緣檢測的圖像檢索算法。使用改進的
發(fā)表于 04-24 10:03
【DragonBoard 410c試用體驗】之OpenCV中canny算子邊緣檢測
有顯著變化的點凸顯出來。在具體編程實現(xiàn)時,可通過計算梯度幅值來確定。 檢測:經(jīng)過增強的圖像,往往鄰域中有很多點的梯度值比較大,而在特定的應用中,這些點并不是我們要找的邊緣點,所以應該采用某種方
發(fā)表于 09-11 23:24
關于canny算子邊緣檢測的問題
本帖最后由 豆吖豆 于 2017-4-4 23:14 編輯
grd=edge(Egray,'canny',0.09,'both');大神門 問一下這個后面的0.09和both什么意思是指的是Egray圖像的上下大小還是,另外可以的話能大概說說這個canny
發(fā)表于 04-04 22:27
Labview圖像處理——邊緣檢測
邊緣的灰度值過度較為明顯,梯度算子可以得到較好的邊緣檢測結果。邊緣提取其實也是一種濾波,不同的算子有不同的提取效果。比較常用的方法有三種,S
發(fā)表于 12-01 12:16
基于Canny 法的紅外小目標邊緣檢測方法
從紅外圖像的特點出發(fā),基于Canny算法進行了目標邊緣檢測。首先,對源圖像進行小波分解和重構,對圖像進行消噪,抑制噪聲對目標提取的影響。然后對消噪后的圖像用Canny算法進
發(fā)表于 05-27 15:02
?12次下載
基于Canny邊緣檢測算子的圖像檢索算法
針對依賴傳統(tǒng)Canny算子的基于邊緣的圖像檢索系統(tǒng)所存在的不足,提出一種基于Canny邊緣檢測的圖像檢索算法。使用改進的
發(fā)表于 02-11 11:22
?28次下載
基于Canny算法的改進Kirsch人臉邊緣檢測方法
針對Kirsch邊緣檢測算法的不足,提出了一種基于Canny算法改進的Kirsch人臉邊緣檢測算法。該算法先對原始圖像用高斯濾波器平滑,計算
發(fā)表于 02-23 14:31
?10次下載
基于邊界特征的車道標識線檢測方法
為了得到較理想的車道的標線邊緣,利用車道的邊緣特征對車道圖像進行二值化和形態(tài)學處理,對車道區(qū)域
發(fā)表于 01-13 09:48
?54次下載
![基于邊界特征的<b class='flag-5'>車道</b>標識<b class='flag-5'>線</b><b class='flag-5'>檢測</b><b class='flag-5'>方法</b>](https://file.elecfans.com/web2/M00/49/45/pYYBAGKhtEKAYFqvAAAQtVreokI531.jpg)
一套車道線檢測系統(tǒng)
車道線檢測主要用于駕駛輔助和無人駕駛系統(tǒng),根據(jù)攝像頭數(shù)量,分為單目和雙目兩種檢測系統(tǒng)。出于實時性和經(jīng)濟性的考慮,一般采用單目檢測,在對采集過
發(fā)表于 01-31 11:26
?1次下載
![一套<b class='flag-5'>車道</b><b class='flag-5'>線</b><b class='flag-5'>檢測</b>系統(tǒng)](https://file.elecfans.com/web1/M00/45/96/pIYBAFpxOAeADqNOAABmrSthqW0630.jpg)
使用iVeia視覺套件進行Canny邊緣檢測HLS IP
iVeia使用嵌入式世界2015中的iVeia視覺套件演示了Canny邊緣檢測HLS IP
python中用區(qū)域掩模實現(xiàn)車道線檢測
如下 我們發(fā)現(xiàn)符合閾值的像素既包括了車道線,也包含了其他非車道線部分。 顯然,一個成熟的自動駕駛感知算法,是不可能使用這種方法的。僅僅依靠顏
![<b class='flag-5'>python</b><b class='flag-5'>中用</b>區(qū)域掩模<b class='flag-5'>實現(xiàn)</b><b class='flag-5'>車道</b><b class='flag-5'>線</b><b class='flag-5'>檢測</b>](https://file1.elecfans.com/web2/M00/B0/A8/wKgZomVXJ_SAWJI6AAAeC7gJ124353.jpg)
評論