def process_image(image): # Undistort Image undist = cam.undistort(image) # Set up Frame pipeline frame = Frame(image, undist) # test(frame.image, "Original Frame", undist, "Undistorted Image") S = frame.HLS[:, :, 2] hLs = frame.HLS[:, :, 1] # Luv = frame.LUV[:, :, 0] # B = frame.LAB[:, :, 2] # gray = frame.gray # Absolute Value Sobel X Gradient using L-Channel in HLS sobel_x_binary = frame.abs_sobel_thresh(hLs, orient='x', sobel_kernel=ksize, thresh=(20, 255)) # test(frame.image, "Original Frame", sobel_x_binary, "Sobel X Binary") # Binary Thresholded from S-Channel of HLS s_binary = np.zeros_like(S) s_binary[(S >= 120) & (S <= 255)] = 1 # test(frame.image, "Original Frame", s_binary, "S Binary") # Thresholded Binary of L-Channel from HLS l_binary = np.zeros_like(hLs) l_binary[(hLs >= 40) & (hLs <= 255)] = 1 # test(frame.image, "Original Frame", l_binary, "L Binary") # Combined Binary of previous 3 binary images combined = 255 * np.dstack( (l_binary, sobel_x_binary, s_binary)).astype('uint8') # test(frame.image, "Original Frame", combined, "Combined") binary = np.zeros_like(sobel_x_binary) binary[((l_binary == 1) & (s_binary == 1) | (sobel_x_binary == 1))] = 1 binary = 255 * np.dstack((binary, binary, binary)).astype('uint8') # test(frame.image, "Original Frame", binary, "New Binary") # Perspective Transform of Combined Binary p_t = frame.perspective_transform(binary) p_t = frame.crop(p_t) # test(frame.image, "Original Frame", p_t, "Perspective Transform and Crop") # Find Lane Lines or return untouched and undistorted frame if lane.find_lines(lane_left, lane_right, p_t, image): return lane.draw(lane_left, lane_right, frame) else: return frame.undist
def morph(begin, end, pt, corner, factor): """ interpolates a new frame between two given frames 'begin and 'end' putting the given 'corner' of the new frame's rectangle to point 'pt'. 'factor' is the position bewteen begin (0.0) and end (1.0). """ result = Frame() # calculate current size size = fade(begin.size(), end.size(), factor) # calculate current rectangle result.rect = [ pt[X] if corner[X] is L else pt[X] - size[X], pt[Y] if corner[Y] is T else pt[Y] - size[Y], pt[X] if corner[X] is R else pt[X] + size[X], pt[Y] if corner[Y] is B else pt[Y] + size[Y], ] # calculate current alpha value and cropping result.alpha = fade(begin.alpha, end.alpha, factor) result.crop = fade(begin.crop, end.crop, factor) # copy orignial size from begin result.original_size = begin.original_size return result