(Udacity Learning Note: CarND-Term1 Project 4)
Camera Calibration & Distortion Correction
Two Types of Distortion
- Radial Distortion
- Tangential Distortion
Using OpenCV
- cv2.findChessboardCorners()
- cv2.drawChessboardCorners()
- cv2.calibrateCamera()
- cv2.undistort()
Example
- Finding chessboard corners (for an 8x6 board):
ret, corners = cv2.findChessboardCorners(gray, (8,6), None)
- Drawing detected corners on an image:
img = cv2.drawChessboardCorners(img, (8,6), corners, ret)
- Camera calibration, given object points, image points, and the shape of the grayscale image:
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[:-1], None, None)
- Undistorting a test image:
dst = cv2.undistort(img, mtx, dist, None, mtx)
Perspective Transform
Commonly Used View
- Front-facing View (Normal View)
- Top-down View (Bird-eye View)
Why?
- Because ultimately we want to measure the curvature of the lines, and to do that, we need to transform to a top-down view.
Apply Perpective Transform using OpenCV
- Compute the perspective transform, M, given source and destination points:
M = cv2.getPerspectiveTransform(src, dst)
- Compute the inverse perspective transform:
Minv = cv2.getPerspectiveTransform(dst, src)
- Warp an image using the perspective transform, M: (warp v. 扭曲)
warped = cv2.warpPerspective(img, M, img_size, flags=cv2.INTER_LINEAR)
Gradient Threshold
Sobel Operator
- The Sobel operator is at the heart of the Canny edge detection algorithm.
Example use of Sober operator
-
Calculate the derivative in the x direction (the 1, 0 at the end denotes x direction):
sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0)
-
Calculate the derivative in the y direction (the 0, 1 at the end denotes y direction):
sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1)
-
Calculate the absolute value of the x derivative:
abs_sobelx = np.absolute(sobelx)
-
Convert the absolute value image to 8-bit:
scaled_sobel = np.uint8(255*abs_sobelx/np.max(abs_sobelx))
Direction of Gradient
- The direction of the gradient is simply the inverse tangent (arctangent) of the y gradient divided by the x gradient:
- arctan(sobely/sobelx).
Color Space
- RGB
- HSV
- HLS
Reference