Very cool!
Brendan Bailey

Thanks, Brendan!

The helper functions are not that exciting — just cleaning up / slightly abstracting the TensorFlow implementations…

def grayscale(img):
return cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

def canny(img, low_threshold, high_threshold):
return cv2.Canny(img, low_threshold, high_threshold)

def gaussian_blur(img, kernel_size):
return cv2.GaussianBlur(img, (kernel_size, kernel_size), 0)

def region_of_interest(img, vertices):

if len(img.shape) > 2:
channel_count = img.shape[2]
ignore_mask_color = (255,) * channel_count
ignore_mask_color = 255

cv2.fillPoly(mask, vertices, ignore_mask_color)

masked_image = cv2.bitwise_and(img, mask)
return masked_image

def hough_lines(img, rho, theta, threshold, min_line_len, max_line_gap):

lines = cv2.HoughLinesP(img, rho, theta, threshold,
minLineLength=min_line_len, maxLineGap=max_line_gap)
line_img = np.zeros(img.shape, dtype=np.uint8)
draw_lines(line_img, lines)
return line_img

def weighted_img(img, initial_img, α=0.8, β=1., λ=0.):
return cv2.addWeighted(initial_img, α, img, β, λ)