iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 22
0
AI & Data

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

Day22-當自動駕駛遇見AI- Project2: Advanced Lane Finding(4)

  • 分享至 

  • xImage
  •  

前言

進行視角轉換工作

實作說明[1]

視角轉換函數

def unwarp(img, src, dst):
    h,w = img.shape[:2]
    # use cv2.getPerspectiveTransform() to get M, the transform matrix, and Minv, the inverse
    M = cv2.getPerspectiveTransform(src, dst)
    Minv = cv2.getPerspectiveTransform(dst, src)
    # use cv2.warpPerspective() to warp your image to a top-down view
    warped = cv2.warpPerspective(img, M, (w,h), flags=cv2.INTER_LINEAR)
    return warped, M, Minv
print('...')

針對圖檔進行處理

h,w = exampleImg_undistort.shape[:2]

# define source and destination points for transform
src = np.float32([(575,464),
                  (707,464), 
                  (258,682), 
                  (1049,682)])
dst = np.float32([(450,0),
                  (w-450,0),
                  (450,h),
                  (w-450,h)])

exampleImg_unwarp, M, Minv = unwarp(exampleImg_undistort, src, dst)

# Visualize unwarp
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(20,10))
f.subplots_adjust(hspace = .2, wspace=.05)
ax1.imshow(exampleImg_undistort)
x = [src[0][0],src[2][0],src[3][0],src[1][0],src[0][0]]
y = [src[0][1],src[2][1],src[3][1],src[1][1],src[0][1]]
ax1.plot(x, y, color='#33cc99', alpha=0.4, linewidth=3, solid_capstyle='round', zorder=2)
ax1.set_ylim([h,0])
ax1.set_xlim([0,w])
ax1.set_title('Undistorted Image', fontsize=30)
ax2.imshow(exampleImg_unwarp)
ax2.set_title('Unwarped Image', fontsize=30)

print('...')

產出成果

https://ithelp.ithome.com.tw/upload/images/20181106/20107143sYlnPWo1Oz.png

參考

[1]jeremy-shannon/CarND-Advanced-Lane-Lines@github


上一篇
Day21-當自動駕駛遇見AI- Project2: Advanced Lane Finding(3)
下一篇
Day23-當自動駕駛遇見AI- Project2: Advanced Lane Finding(5)
系列文
當自動駕駛遇見AI30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言