Project: Detect Lane Lines
Detect highway lane lines from a video stream. Use OpenCV image analysis techniques to identify lines, including Hough transforms and Canny edge detection.
Galen Ballew의 해결 방안
0. 개요
- OpenCV의
Canny Edge Detector:canny()
활용 - The Hough transform
1. 전처리
- Grayscale로 이미지 변환 : 칼러정보(RGB)가 사라지고 0~255의 흑백정보만 남게 된다.
- 차선은 주로 노란색이나 흰색이다.
- Yellow can be a tricky color to isolate in RGB space
- 따라서 HVS, HSV 로 변환한다.
- we will apply a mask to the original RGB image to return the pixels we’re interested in.
- Gaussian blur 적용 : This filter suppress noise by averaging out the pixel values in a neighborhood.
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)
kernel_size = 5
gauss_gray = gaussian_blur(mask_yw_image,kernel_size)
2. 본처리
2.1 탐지 (Canny Edge Detection)
canny()
parses the pixel values according to their directional derivative (i.e. gradient)
- gradient 계산을 위한 thresholds1 지정 필요
- John Canny himself recommended a low to high threshold ratio of 1:2 or 1:3.
low_threshold = 50
high_threshold = 150
canny_edges = canny(gauss_gray,low_threshold,high_threshold)
2.2 create region of interest (ROI) mask
- 불필요한 연산 제거를 위해 옆차선, 하늘 제거
- Everything outside of the ROI will be set to black/zero, so we only focus on what’s in front of the car.
def region_of_interest(img, vertices):
"""
Applies an image mask.
Only keeps the region of the image defined by the polygon
formed from `vertices`. The rest of the image is set to black.
"""
#defining a blank mask to start with
mask = np.zeros_like(img)
#defining a 3 channel or 1 channel color to fill the mask with depending on the input image
if len(img.shape) > 2:
channel_count = img.shape[2] # i.e. 3 or 4 depending on your image
ignore_mask_color = (255,) * channel_count
else:
ignore_mask_color = 255
#filling pixels inside the polygon defined by "vertices" with the fill color
cv2.fillPoly(mask, vertices, ignore_mask_color)
#returning the image only where mask pixels are nonzero
masked_image = cv2.bitwise_and(img, mask)
return masked_image
2.3 Hough Space
The Hough transform[1]
- Hough Transform to convert the pixel dots that were detected as edges into meaningful lines(점을 선으로 변경)
- Hough space lines correspond to points in XY space and points correspond to lines in XY space. This is what our pipeline will look like:
- Pixels are considered points in XY space
- hough_lines() transforms these points into lines inside of Hough space
- Wherever these lines intersect, there is a point of intersection in Hough space
- The point of intersection corresponds to a line in XY space
3. 후처리
Once we have our two master lines, we can average our line image with the original, unaltered image of the road to have a nice, smooth overlay.
complete = cv2.addWeighted(initial_img, alpha, line_image, beta, lambda)
4. 결론
- ROI 결정은 신중히 하자. 오르막길 등에서 인식이 안될수 있다.
Param Aggarwal의 해결 방안
0. 개요
1. 전처리
- blur the image so that only truly contrasting parts of the picture stand out in the next step.
cv2.GaussianBlur(img, (kernel_size, kernel_size), 0)
2. 본처리
2.1 탐지 (Canny Edge Detection)
- edge-detection : Canny Transform
cv2.Canny(img, low_threshold, high_threshold)
2.2 create region of interest (ROI) mask
- we mask out most of the image and only keep the bottom part of the road in view.
2.3 Hough Space
The Hough transform[1]
cv2.HoughLinesP(img, rho, theta, threshold, np.array([]), minLineLength=min_line_len, maxLineGap=max_line_gap)
3. 후처리
- 두개의 선 중에서 가장 긴선이 나에게 중요한 라인으로 인식 하도록 처리
4. 결론
1. Determine how little and how much change is acceptable to be considered a valid edge ↩
[1] 09gr820, Line Detection by Hough transformation (2009)