日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

Python道路車道線檢測的實現

瀏覽:183日期:2022-06-15 16:58:07

車道線檢測是自動駕駛汽車以及一般計算機視覺的關鍵組件。這個概念用于描述自動駕駛汽車的路徑并避免進入另一條車道的風險。

在本文中,我們將構建一個機器學習項目來實時檢測車道線。我們將使用 OpenCV 庫使用計算機視覺的概念來做到這一點。為了檢測車道,我們必須檢測車道兩側的白色標記。

Python道路車道線檢測的實現

使用 Python 和 OpenCV 進行道路車道線檢測使用 Python 中的計算機視覺技術,我們將識別自動駕駛汽車必須行駛的道路車道線。這將是自動駕駛汽車的關鍵部分,因為自動駕駛汽車不應該越過它的車道,也不應該進入對面車道以避免事故。

幀掩碼和霍夫線變換要檢測車道中的白色標記,首先,我們需要屏蔽幀的其余部分。我們使用幀屏蔽來做到這一點。該幀只不過是圖像像素值的 NumPy 數組。為了掩蓋幀中不必要的像素,我們只需將 NumPy 數組中的這些像素值更新為 0。

制作后我們需要檢測車道線。用于檢測此類數學形狀的技術稱為霍夫變換?;舴蜃儞Q可以檢測矩形、圓形、三角形和直線等形狀。

代碼下載源碼請下載:車道線檢測項目代碼

按照以下步驟在 Python 中進行車道線檢測:

1.導入包

import matplotlib.pyplot as pltimport numpy as npimport cv2import osimport matplotlib.image as mpimgfrom moviepy.editor import VideoFileClipimport math

2. 應用幀屏蔽并找到感興趣的區域:

def interested_region(img, vertices): if len(img.shape) > 2: mask_color_ignore = (255,) * img.shape[2] else:mask_color_ignore = 255 cv2.fillPoly(np.zeros_like(img), vertices, mask_color_ignore) return cv2.bitwise_and(img, np.zeros_like(img))

3.霍夫變換空間中像素到線的轉換:

def hough_lines(img, rho, theta, threshold, min_line_len, max_line_gap): lines = cv2.HoughLinesP(img, rho, theta, threshold, np.array([]), minLineLength=min_line_len, maxLineGap=max_line_gap) line_img = np.zeros((img.shape[0], img.shape[1], 3), dtype=np.uint8) lines_drawn(line_img,lines) return line_img

4. 霍夫變換后在每一幀中創建兩條線:

def lines_drawn(img, lines, color=[255, 0, 0], thickness=6): global cache global first_frame slope_l, slope_r = [],[] lane_l,lane_r = [],[] α =0.2 for line in lines:for x1,y1,x2,y2 in line: slope = (y2-y1)/(x2-x1) if slope > 0.4:slope_r.append(slope)lane_r.append(line) elif slope < -0.4:slope_l.append(slope)lane_l.append(line)img.shape[0] = min(y1,y2,img.shape[0]) if((len(lane_l) == 0) or (len(lane_r) == 0)):print (’no lane detected’)return 1 slope_mean_l = np.mean(slope_l,axis =0) slope_mean_r = np.mean(slope_r,axis =0) mean_l = np.mean(np.array(lane_l),axis=0) mean_r = np.mean(np.array(lane_r),axis=0)if ((slope_mean_r == 0) or (slope_mean_l == 0 )):print(’dividing by zero’)return 1x1_l = int((img.shape[0] - mean_l[0][1] - (slope_mean_l * mean_l[0][0]))/slope_mean_l) x2_l = int((img.shape[0] - mean_l[0][1] - (slope_mean_l * mean_l[0][0]))/slope_mean_l) x1_r = int((img.shape[0] - mean_r[0][1] - (slope_mean_r * mean_r[0][0]))/slope_mean_r) x2_r = int((img.shape[0] - mean_r[0][1] - (slope_mean_r * mean_r[0][0]))/slope_mean_r) if x1_l > x1_r:x1_l = int((x1_l+x1_r)/2)x1_r = x1_ly1_l = int((slope_mean_l * x1_l ) + mean_l[0][1] - (slope_mean_l * mean_l[0][0]))y1_r = int((slope_mean_r * x1_r ) + mean_r[0][1] - (slope_mean_r * mean_r[0][0]))y2_l = int((slope_mean_l * x2_l ) + mean_l[0][1] - (slope_mean_l * mean_l[0][0]))y2_r = int((slope_mean_r * x2_r ) + mean_r[0][1] - (slope_mean_r * mean_r[0][0])) else:y1_l = img.shape[0]y2_l = img.shape[0]y1_r = img.shape[0]y2_r = img.shape[0] present_frame = np.array([x1_l,y1_l,x2_l,y2_l,x1_r,y1_r,x2_r,y2_r],dtype ='float32')if first_frame == 1:next_frame = present_framefirst_frame = 0 else :prev_frame = cachenext_frame = (1-α)*prev_frame+α*present_frame cv2.line(img, (int(next_frame[0]), int(next_frame[1])), (int(next_frame[2]),int(next_frame[3])), color, thickness) cv2.line(img, (int(next_frame[4]), int(next_frame[5])), (int(next_frame[6]),int(next_frame[7])), color, thickness)cache = next_frame

5.處理每一幀視頻以檢測車道:

def weighted_img(img, initial_img, α=0.8, β=1., λ=0.): return cv2.addWeighted(initial_img, α, img, β, λ)def process_image(image): global first_frame gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) img_hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV) lower_yellow = np.array([20, 100, 100], dtype = 'uint8') upper_yellow = np.array([30, 255, 255], dtype='uint8') mask_yellow = cv2.inRange(img_hsv, lower_yellow, upper_yellow) mask_white = cv2.inRange(gray_image, 200, 255) mask_yw = cv2.bitwise_or(mask_white, mask_yellow) mask_yw_image = cv2.bitwise_and(gray_image, mask_yw) gauss_gray= cv2.GaussianBlur(mask_yw_image, (5, 5), 0) canny_edges=cv2.Canny(gauss_gray, 50, 150) imshape = image.shape lower_left = [imshape[1]/9,imshape[0]] lower_right = [imshape[1]-imshape[1]/9,imshape[0]] top_left = [imshape[1]/2-imshape[1]/8,imshape[0]/2+imshape[0]/10] top_right = [imshape[1]/2+imshape[1]/8,imshape[0]/2+imshape[0]/10] vertices = [np.array([lower_left,top_left,top_right,lower_right],dtype=np.int32)] roi_image = interested_region(canny_edges, vertices) theta = np.pi/180 line_image = hough_lines(roi_image, 4, theta, 30, 100, 180) result = weighted_img(line_image, image, α=0.8, β=1., λ=0.) return result

6. 將輸入視頻剪輯成幀并得到結果輸出視頻文件:

first_frame = 1white_output = ’__path_to_output_file__’clip1 = VideoFileClip('__path_to_input_file__')white_clip = clip1.fl_image(process_image)white_clip.write_videofile(white_output, audio=False)

車道線檢測項目 GUI 代碼:

Python道路車道線檢測的實現

import tkinter as tkfrom tkinter import *import cv2from PIL import Image, ImageTkimport osimport numpy as npglobal last_frame1 last_frame1 = np.zeros((480, 640, 3), dtype=np.uint8)global last_frame2 last_frame2 = np.zeros((480, 640, 3), dtype=np.uint8)global cap1global cap2cap1 = cv2.VideoCapture('path_to_input_test_video')cap2 = cv2.VideoCapture('path_to_resultant_lane_detected_video')def show_vid(): if not cap1.isOpened(): print('cant open the camera1') flag1, frame1 = cap1.read() frame1 = cv2.resize(frame1,(400,500)) if flag1 is None:print ('Major error!') elif flag1:global last_frame1last_frame1 = frame1.copy()pic = cv2.cvtColor(last_frame1, cv2.COLOR_BGR2RGB) img = Image.fromarray(pic)imgtk = ImageTk.PhotoImage(image=img)lmain.imgtk = imgtklmain.configure(image=imgtk)lmain.after(10, show_vid)def show_vid2(): if not cap2.isOpened(): print('cant open the camera2') flag2, frame2 = cap2.read() frame2 = cv2.resize(frame2,(400,500)) if flag2 is None:print ('Major error2!') elif flag2:global last_frame2last_frame2 = frame2.copy()pic2 = cv2.cvtColor(last_frame2, cv2.COLOR_BGR2RGB)img2 = Image.fromarray(pic2)img2tk = ImageTk.PhotoImage(image=img2)lmain2.img2tk = img2tklmain2.configure(image=img2tk)lmain2.after(10, show_vid2)if __name__ == ’__main__’: root=tk.Tk() lmain = tk.Label(master=root) lmain2 = tk.Label(master=root) lmain.pack(side = LEFT) lmain2.pack(side = RIGHT) root.title('Lane-line detection')root.geometry('900x700+100+10') exitbutton = Button(root, text=’Quit’,fg='red',command= root.destroy).pack(side = BOTTOM,) show_vid() show_vid2() root.mainloop() cap.release()

到此這篇關于Python道路車道線檢測的實現的文章就介紹到這了,更多相關Python 道路車道線檢測內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
欧美日韩精品一本二本三本| 国产乱码精品| 黄色欧美在线| 欧美丰满日韩| 日本国产精品| 99久精品视频在线观看视频| 亚洲视频综合| 免费的成人av| 国产精品美女久久久久久不卡| 欧美国产视频| 日韩福利一区| 国产精品日本欧美一区二区三区| 蜜桃久久av一区| 国产色99精品9i| 亚洲深夜视频| 99国产精品私拍| 日本成人中文字幕在线视频| 国产精品一区二区三区四区在线观看| 国产亚洲精品美女久久久久久久久久| 欧美亚洲免费| 麻豆精品久久久| 久久精品官网| 亚洲人成在线影院| 麻豆精品一区二区综合av| 久久久久99| 日韩高清二区| 日韩电影免费网址| 热久久国产精品| 国产一区二区三区免费在线| 伊人久久大香线蕉av超碰演员| 婷婷久久免费视频| 久久男人av资源站| 爽好久久久欧美精品| 国产经典一区| 国产精品美女久久久| 久久超级碰碰| 国精品一区二区| 日韩av不卡在线观看| 国产综合色区在线观看| 综合五月婷婷| 韩国三级一区| 久久国产尿小便嘘嘘| 成人av动漫在线观看| 国产精品亚洲二区| 日韩视频在线一区二区三区| 精品一二三区| 日本在线一区二区三区| 今天的高清视频免费播放成人| 欧美视频久久| 亚洲欧美日韩国产| 欧美好骚综合网| 一级欧美视频| 国产91一区| 精品国产三区在线| 日韩精品电影一区亚洲| 国产色综合网| 在线观看精品| 精品福利久久久| 日本午夜精品视频在线观看| 亚洲精品2区| 亚洲三级欧美| 麻豆成人av在线| 国产日韩一区二区三区在线播放| 欧美专区一区二区三区| 欧美亚洲国产激情| 人人草在线视频| 国产精品观看| 欧美一区免费| 日韩精品视频网站| 天堂成人免费av电影一区| 亚洲国产影院| 在线日韩av| 国内亚洲精品| 久久久一二三| 日韩高清中文字幕一区二区| 国产精品xxx| 日韩成人一级| 日韩国产欧美一区二区三区| 中文字幕一区二区精品区| 香蕉精品999视频一区二区| 蜜桃成人av| 91看片一区| 色婷婷精品视频| 99视频精品视频高清免费| 午夜欧美巨大性欧美巨大| 久久精品导航| 樱桃成人精品视频在线播放| 亚洲激情精品| 久久一二三区| 日本成人中文字幕在线视频| 911亚洲精品| 国产美女视频一区二区| 青草久久视频| 国产亚洲电影| 麻豆91在线播放| 精品视频97| 久久99精品久久久久久园产越南 | 美女视频黄 久久| 精品视频97| 日韩免费小视频| 欧美不卡高清| 另类激情亚洲| 亚洲aa在线| 亚洲开心激情| 91国内精品| 国内自拍视频一区二区三区| 精品不卡一区| 久久黄色影院| 亚洲网址在线观看| 蜜臀久久99精品久久久画质超高清| 久久亚洲美女| 国产日韩亚洲欧美精品| 狠狠久久伊人| 午夜国产一区二区| 免费日本视频一区| 国产日本精品| 麻豆网站免费在线观看| 欧美日韩国产亚洲一区| 噜噜噜躁狠狠躁狠狠精品视频| 亚洲精品在线国产| 国产欧美啪啪| 国产在线观看www| 亚洲精品99| 欧美日韩午夜电影网| 麻豆精品久久久| 婷婷综合网站| 国产精品一区高清| 欧美亚洲国产一区| 日韩欧美三区| 亚洲欧洲高清| 亚洲天堂免费| 国产一区二区三区四区二区| 亚洲精品中文字幕乱码| 日韩av电影一区| 午夜精品成人av| 日韩在线黄色| 波多野结衣久久精品| 在线看片日韩| 日韩不卡一区| 噜噜噜躁狠狠躁狠狠精品视频 | 日本伊人久久| 成人一二三区| 男人的天堂亚洲一区| 国产一区二区三区四区五区| 亚洲色诱最新| 国产一区二区三区探花| 亚洲天堂日韩在线| 中文字幕在线视频网站| 亚洲理论在线| 韩国一区二区三区视频| 模特精品在线| 丰满少妇一区| 中文字幕一区二区三区日韩精品| 国产精品精品| 日韩国产一二三区| 九九综合九九| 国产一区丝袜| 亚洲精品在线a| 亚洲国产专区校园欧美| 国产福利亚洲| 一区二区国产在线| 久久国产小视频| 欧美激情aⅴ一区二区三区 | 五月天久久网站| 精品中文在线| 欧美影院精品| 日韩一区精品视频| 色爱综合av| 久久精品二区亚洲w码| 日韩一区二区三区在线看| 亚洲精品午夜av福利久久蜜桃| 国产成人黄色| 国产精品密蕾丝视频下载| 亚洲精品欧美| 在线亚洲欧美| 午夜国产精品视频| 成人啊v在线| 红杏一区二区三区| 国产精品久久久久毛片大屁完整版| 国产视频亚洲| 偷拍欧美精品| 欧美一区二区三区高清视频| 伊人网在线播放| 久久中文字幕一区二区| 青青草国产精品亚洲专区无| 久久成人亚洲| 亚洲男女自偷自拍| 99国产精品久久久久久久| 99久久www免费| 日韩在线中文| av综合电影网站| 黄在线观看免费网站ktv| 成人污污视频| 欧美激情五月| 国产乱码精品一区二区三区亚洲人| 亚洲精品高潮| 日韩一区二区三区精品| 日韩精品中文字幕吗一区二区| 人人精品人人爱| 亚洲综合色婷婷在线观看|