詳解車道線檢測(cè)算法之傳統(tǒng)圖像處理
# Threshold x gradientsxbinary = np.zeros_like(scaled_sobel)sxbinary[(scaled_sobel >= sx_thresh[0]) & (scaled_sobel <= sx_thresh[1])] = 1
# Threshold S channel of HLSs_binary = np.zeros_like(s_channel)s_binary[(s_channel >= s_thresh[0]) & (s_channel <= s_thresh[1])] = 1
# Threshold L channel of HLSl_binary = np.zeros_like(l_channel)l_binary[(l_channel >= l_thresh[0]) & (l_channel <= l_thresh[1])] = 1
# 將各種處理方式進(jìn)行融合,得到車道線的二進(jìn)制圖。color_binary = 255*np.dstack(( l_binary, sxbinary, s_binary)).a(chǎn)stype('uint8')
combined_binary = np.zeros_like(sxbinary)combined_binary[((l_binary == 1) & (s_binary == 1) | (sxbinary==1))] = 1
combined_binary = 255*np.dstack((combined_binary,combined_binary,combined_binary)).a(chǎn)stype('uint8')
透視變換和ROI提取
# 使用透視變換(perspective transform)得到二進(jìn)制圖(binary image)的鳥瞰圖(birds-eye view).img=plt.imread('test_image.jpg')corners = np.float32([[190,720],[580,460],[705,460],[1120,720]])# tuningimshape = img.shape
new_top_left=np.a(chǎn)rray([corners[0,0],0])new_top_right=np.a(chǎn)rray([corners[3,0],0])
offset=[150,0]src = np.float32([corners[0],corners[1],corners[2],corners[3]])dst = np.float32([corners[0]+offset,new_top_left+offset,new_top_right-offset ,corners[3]-offset])
M = cv2.getPerspectiveTransform(src, dst)warped = cv2.warpPerspective(img, M, img_size , flags=cv2.INTER_LINEAR)
# ROI提取shape = warped.shapevertices = np.a(chǎn)rray([[(0,0),(shape[1],0),(shape[1],0),(6*shape[1]/7,shape[0]), (shape[1]/7,shape[0]), (0,0)]],dtype=np.int32)mask = np.zeros_like(warped) if len(shape) > 2: channel_count = shape[2] ignore_mask_color = (255,) * channel_countelse: ignore_mask_color = 255cv2.fillPoly(mask, vertices, ignore_mask_color) masked_image = cv2.bitwise_and(img, mask)
利用直方圖濾波和滑動(dòng)窗口進(jìn)行曲線擬合
# 對(duì)二進(jìn)制圖片的像素進(jìn)行直方圖統(tǒng)計(jì),統(tǒng)計(jì)左右兩側(cè)的峰值點(diǎn)作為左右車道線的起始點(diǎn)坐標(biāo)進(jìn)行曲線擬合。(利用前幀圖像探索后幀曲線)
def find_peaks(img,thresh): img_half=img[img.shape[0]//2:,:,0] data = np.sum(img_half, axis=0) filtered = scipy.ndimage.filters.gaussian_filter1d(data,20) xs = np.a(chǎn)range(len(filtered)) peak_ind = signal.find_peaks_cwt(filtered, np.a(chǎn)range(20,300)) peaks = np.array(peak_ind) peaks = peaks[filtered[peak_ind]>thresh] return peaks,filtered
def get_next_window(img,center_point,width): ny,nx,_ = img.shape mask = np.zeros_like(img) if (center_point <= width/2): center_point = width/2 if (center_point >= nx-width/2): center_point = nx-width/2 left = center_point - width/2 right = center_point + width/2 vertices = np.a(chǎn)rray([[(left,0),(left,ny), (right,ny),(right,0)]], dtype=np.int32) ignore_mask_color=(255,255,255) cv2.fillPoly(mask, vertices, ignore_mask_color) masked = cv2.bitwise_and(mask,img)
hist = np.sum(masked[:,:,0],axis=0) if max(hist>10000): center = np.a(chǎn)rgmax(hist) else: center = center_point return masked,center
def lane_from_window(binary,center_point,width): n_zones=6 ny,nx,nc = binary.shape zones = binary.reshape(n_zones,-1,nx,nc) zones = zones[::-1] window,center = get_next_window(zones[0],center_point,width) for zone in zones[1:]: next_window,center = get_next_window(zone,center,width) window = np.vstack((next_window,window)) return window
left_binary = lane_from_window(warped_binary,380,300)right_binary = lane_from_window(warped_binary,1000,300)
計(jì)算車道曲率
ym_per_pix = 30/720 # meters per pixel in y dimensionxm_per_pix = 3.7/700 # meters per pixel in x dimlane_width = 3.7
def cal_curvature(line): fit_coeffs_curv = np.polyfit(y*ym_per_pix, x*xm_per_pix, 2) radius_of_curvature = ((1 + (2*fit_coeffs_curv[0]*y_eval*ym_per_pix + fit_coeffs_curv[1])**2)**1.5) /np.a(chǎn)bsolute(2*fit_coeffs_curv[0]) return radius_of_curvature left_curvature= cal_curvature(left_line)right_curvature = cal_curvature(right_line)
curvature = 0.5*(round(right_curvature,1) + round(left_curvature,1))
將曲線逆透視到原圖片
# 將完成車道線標(biāo)記的鳥瞰圖反透視變換為初始圖像視角
newwarp = cv2.warpPerspective(color_warp, Minv, (img.shape[1], img.shape[0]))
將算法應(yīng)用于視頻
output = 'test_video_output.mp4'clip = VideoFileClip("test_video.mp4")out_clip = clip.fl_image(process_image) %time out_clip.write_videofile(output, audio=False)
- End -
發(fā)表評(píng)論
請(qǐng)輸入評(píng)論內(nèi)容...
請(qǐng)輸入評(píng)論/評(píng)論長(zhǎng)度6~500個(gè)字
圖片新聞
最新活動(dòng)更多
-
11月19日立即報(bào)名>> 【線下論壇】華邦電子與恩智浦聯(lián)合技術(shù)論壇
-
12月19日立即報(bào)名>> 【線下會(huì)議】OFweek 2024(第九屆)物聯(lián)網(wǎng)產(chǎn)業(yè)大會(huì)
-
精彩回顧立即查看>> 蔡司新能源汽車三電質(zhì)量解決方案
-
精彩回顧立即查看>> 蔡司新能源汽車三電質(zhì)量解決方案
-
精彩回顧立即查看>> 2024(第五屆)全球數(shù)字經(jīng)濟(jì)產(chǎn)業(yè)大會(huì)暨展覽會(huì)
-
精彩回顧立即查看>> 【線下會(huì)議】全數(shù)會(huì)2024電子元器件展覽會(huì)
- 1 “作弊器”不靈了?智駕的激光雷達(dá),正在被攝像頭替代
- 2 被逼墻角的Mobileye,祭出 CAIS 大旗,挑戰(zhàn)端到端大模型智能駕駛
- 3 4 激光雷達(dá)與純視覺(jué)方案,哪個(gè)才是自動(dòng)駕駛最優(yōu)選?
- 5 激光雷達(dá)即將降價(jià),純視覺(jué)回到鄙視鏈底層?
- 6 如何跑贏汽車智能化下半場(chǎng)?
- 7 從小鵬、理想、蔚來(lái)布局看自動(dòng)駕駛發(fā)展趨勢(shì)
- 8 智能駕駛的百生相,你是該信呢?還是該信呢?
- 9 比亞迪技術(shù)魚池大戰(zhàn)豐田工具箱,誰(shuí)將主導(dǎo)未來(lái)汽車市場(chǎng)?
- 10 全網(wǎng)最詳解! 美國(guó)禁止中國(guó)智駕究竟包括哪些?
- IE工程師(汽車智聯(lián)) 惠州碩貝德無(wú)線科技股份有限公司
- 現(xiàn)場(chǎng)技術(shù)支持工程師(汽車) 易思維(杭州)科技股份有限公司
- 銷售經(jīng)理(汽車新能源行業(yè)) 廣州瑞松智能科技股份有限公司
- 結(jié)構(gòu)工程師-汽車電子事業(yè)部(J10116) 深圳奧尼電子股份有限公司
- 銷售總監(jiān)-汽車電子方向 深圳市智立方自動(dòng)化設(shè)備股份有限公司
- 項(xiàng)目經(jīng)理(汽車內(nèi)飾&汽車電子) 伯恩光學(xué)(惠州)有限公司
- 高級(jí)軟件工程師 廣東省/深圳市
- 自動(dòng)化高級(jí)工程師 廣東省/深圳市
- 光器件研發(fā)工程師 福建省/福州市
- 銷售總監(jiān)(光器件) 北京市/海淀區(qū)
- 激光器高級(jí)銷售經(jīng)理 上海市/虹口區(qū)
- 光器件物理工程師 北京市/海淀區(qū)
- 激光研發(fā)工程師 北京市/昌平區(qū)
- 技術(shù)專家 廣東省/江門市
- 封裝工程師 北京市/海淀區(qū)
- 結(jié)構(gòu)工程師 廣東省/深圳市