줘이리의 인생적기

CV - opencv(Python) White, Yellow 차선 검출 본문

공부/Computer Vision(py)

CV - opencv(Python) White, Yellow 차선 검출

줘이리 2020. 7. 10. 08:00
728x90

흰색 차선과 노란 차선을 검출해보도록 하겠습니다.

 

1번 흰색 차선 검출

 

2번 흰색 노란색 차선 검출

 

전체 코드

더보기
# -*- coding: utf-8 -*-
from OpenCV_Functions import *

def imageProcessing(image):
    result = imageCopy(image)
    lower_white_hls = np.array([0, 200, 0])
    upper_white_hls = np.array([179, 255, 255])
    lower_yellow_hls = np.array([15, 30, 115])
    upper_yellow_hls = np.array([35, 204, 255])
    result = convertColor(result, cv2.COLOR_BGR2HLS)
    white_hls_overlay = splitColor(result, lower_white_hls, upper_white_hls)
    yellow_hls_overlay = splitColor(result, lower_yellow_hls, upper_yellow_hls)
    result = white_hls_overlay + yellow_hls_overlay
    result = convertColor(result, cv2.COLOR_HLS2BGR)
    return result

road_image_01 = "<이미지 경로>"
image_color1 = imageRead(road_image_01, cv2.IMREAD_COLOR)
result1 = imageProcessing(image_color1)
imageShow("ex03 White Lane", result1, cv2.WINDOW_NORMAL)

road_image_02 = "<이미지 경로>"
image_color2 = imageRead(road_image_02, cv2.IMREAD_COLOR)
result2 = imageProcessing(image_color2)
imageShow("ex03 Yellow and White Lane", result2, cv2.WINDOW_NORMAL)