0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內(nèi)不再提示

python中用Canny邊緣檢測和霍夫變實現(xiàn)車道線檢測方法

麥辣雞腿堡 ? 來源:CSDN博客 ? 作者:綠竹巷人 ? 2023-11-17 16:55 ? 次閱讀

Canny邊緣檢測+霍夫變換

顏色閾值+圖像掩模的方法雖然簡單,但是只能應對一些固定顏色車道線的場景。圖像像素受光照影響將是一個極其常見的問題。

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,顯然并不能識別具備一定曲率的車道線,也無法適應光照不同的情況。

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權轉載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 邊緣檢測
    +關注

    關注

    0

    文章

    92

    瀏覽量

    18184
  • Canny
    +關注

    關注

    0

    文章

    14

    瀏覽量

    9694
  • python
    +關注

    關注

    54

    文章

    4758

    瀏覽量

    84293
收藏 人收藏

    評論

    相關推薦

    Canny雙閾值邊緣檢測和弱邊緣連接詳解

    在上一篇FPGA圖像處理--Canny邊緣檢測(一)里介紹了Canny邊緣檢測的NMS計算,這里
    的頭像 發(fā)表于 11-18 17:07 ?2178次閱讀

    基于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

    圖象處理中的哈變換和Canny邊緣檢測算法

    圖象處理中的邊緣檢測------canny算子
    發(fā)表于 03-16 06:48

    Labview圖像處理——邊緣檢測

    邊緣的灰度值過度較為明顯,梯度算子可以得到較好的邊緣檢測結果。邊緣提取其實也是一種濾波,不同的算子有不同的提取效果。比較常用的方法有三種,S
    發(fā)表于 12-01 12:16

    基于圖像的車道檢測

    基于圖像的車道檢測,點擊上方“3D視覺工坊”,選擇“星標”干貨第一時間送達文章導讀本文是一篇從零開始做車道
    發(fā)表于 07-20 06:24

    基于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>

    canny邊緣檢測

    《OpenCV3編程入門》書本配套源代碼canny邊緣檢測
    發(fā)表于 06-06 15:20 ?2次下載

    一套車道檢測系統(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)

    使用iVeia視覺套件進行Canny邊緣檢測HLS IP

    iVeia使用嵌入式世界2015中的iVeia視覺套件演示了Canny邊緣檢測HLS IP
    的頭像 發(fā)表于 11-30 06:41 ?2862次閱讀

    python中用區(qū)域掩模實現(xiàn)車道檢測

    如下 我們發(fā)現(xiàn)符合閾值的像素既包括了車道,也包含了其他非車道部分。 顯然,一個成熟的自動駕駛感知算法,是不可能使用這種方法的。僅僅依靠顏
    的頭像 發(fā)表于 11-17 16:49 ?344次閱讀
    <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>