iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 8
0
AI & Data

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

Day8-當自動駕駛遇見AI-失真校正(Correcting for Distortion)

  • 分享至 

  • xImage
  •  

前言

此部份可以進行相機校準和失真校正工作

內容

這個過程有兩個主要步驟:使用棋盤圖像獲取圖像點和對象點,然後使用OpenCV函數cv2.calibrateCamera()和cv2.undistort()來計算校準和非失真。

import pickle
import cv2
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

# Read in the saved objpoints and imgpoints
dist_pickle = pickle.load( open( "wide_dist_pickle.p", "rb" ) )
objpoints = dist_pickle["objpoints"]
imgpoints = dist_pickle["imgpoints"]

# Read in an image
img = cv2.imread('test_image.png')

# TODO: Write a function that takes an image, object points, and image points
# performs the camera calibration, image distortion correction and 
# returns the undistorted image
def cal_undistort(img, objpoints, imgpoints):
    # Use cv2.calibrateCamera() and cv2.undistort()
    undist = np.copy(img)  # Delete this line
    return undist

undistorted = cal_undistort(img, objpoints, imgpoints)

f, (ax1, ax2) = plt.subplots(1, 2, figsize=(24, 9))
f.tight_layout()
ax1.imshow(img)
ax1.set_title('Original Image', fontsize=50)
ax2.imshow(undistorted)
ax2.set_title('Undistorted Image', fontsize=50)
plt.subplots_adjust(left=0., right=1, top=0.9, bottom=0.)

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

尚未有邦友留言

立即登入留言