iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 6
0
AI & Data

當自動駕駛遇見AI系列 第 6

Day6-當自動駕駛遇見AI-Project1: Finding Lane Lines(2)

前言

這部份接續專案後續程式建立 pipeline及測試圖檔、影片之成果

內容

測試圖檔及pipeline程式說明如下:[1]

Test Images

import os
os.listdir("test_images/")

產出結果如下:
https://ithelp.ithome.com.tw/upload/images/20181021/20107143zPSjeyhSea.png

Build a Lane Finding Pipeline

構建pipeline,針對所有test_images上圖檔提供解決方案。 將副本複製到test_images_output目錄中,您可以使用這些圖像寫入成果報告中。
試著調整各種參數,包括Canny門檻值以及Hough門檻值參數,提供較佳的車道道呈現。

載入所需函式庫

# Import everything needed to edit/save/watch video clips
from moviepy.editor import VideoFileClip
from IPython.display import HTML

撰寫處理圖檔函式

def process_image(image):
    # NOTE: The output you return should be a color image (3 channel) for processing video below
    # TODO: put your pipeline here,
    # you should return the final output (image where lines are drawn on lanes)
    gray_image = grayscale(image)
    gaus_blur = gaussian_blur(gray_image, 3)
    edges = canny(gaus_blur, 50,150)    
    imshape = image.shape
    
    vertices = np.array([[(0,imshape[0]),(450, 320), (500, 320), (imshape[1],imshape[0])]], dtype=np.int32)    
    masked = region_of_interest(edges, vertices)
    
    rho = 2            #distance resolution in pixels of the Hough grid
    theta = np.pi/180  #angular resolution in radians of the Hough grid
    threshold = 5     #minimum number of votes (intersections in Hough grid cell)
    min_line_len = 10  #minimum number of pixels making up a line
    max_line_gap = 20  #maximum gap in pixels between connectable line segments
    line_image = hough_lines(masked, rho, theta, threshold, min_line_len, max_line_gap)
    
    result = weighted_img(line_image, image)
    return result


images = os.listdir("test_images/")
for img_file in images:
    #print(img_file)
    # Skip all files starting with line.
    if img_file[0:4] == 'line':
        continue
    
    image = mpimg.imread('test_images/' + img_file)   
    
    weighted = process_image(image)

    plt.imshow(weighted)
    #break
    mpimg.imsave('test_images/lines-' + img_file, weighted)

產出:
https://ithelp.ithome.com.tw/upload/images/20181021/20107143wQwRN2wV4r.png

針對影片進行測試

white_output = 'test_videos_output/solidWhiteRight.mp4'
## To speed up the testing process you may want to try your pipeline on a shorter subclip of the video
## To do so add .subclip(start_second,end_second) to the end of the line below
## Where start_second and end_second are integer values representing the start and end of the subclip
## You may also uncomment the following line for a subclip of the first 5 seconds
##clip1 = VideoFileClip("test_videos/solidWhiteRight.mp4").subclip(0,5)
clip1 = VideoFileClip("test_videos/solidWhiteRight.mp4")
white_clip = clip1.fl_image(process_image) #NOTE: this function expects color images!!
%time white_clip.write_videofile(white_output, audio=False)

線上播放成果

HTML("""
<video width="960" height="540" controls>
  <source src="{0}">
</video>
""".format(white_output))

成果影片:
Yes

參考

1.13rac1/CarND-P01-Lane-Lines


上一篇
Day5-當自動駕駛遇見AI-Project1: Finding Lane Lines(1)
下一篇
Day7-當自動駕駛遇見AI-Project1: Finding Lane Lines(3)-writeup
系列文
當自動駕駛遇見AI30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言