This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fitpolynomial_with_previous_fitting_value(binary_warped, left_fit_before, right_fit_before,ploty): | |
margin = 120 | |
left_fit_current, right_fit_current = (None, None) | |
img_shape = binary_warped.shape | |
nonzero = binary_warped.nonzero() | |
nonzeroy = np.array(nonzero[0]) | |
nonzerox = np.array(nonzero[1]) | |
left_lane_inds = ((nonzerox > (left_fit_before[0]*(nonzeroy**2) + left_fit_before[1]*nonzeroy + | |
left_fit_before[2] - margin)) & (nonzerox < (left_fit_before[0]*(nonzeroy**2) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def measure_curvature_pixels(left_fit, right_fit, ploty, leftx, lefty, rightx, righty): | |
''' | |
Calculates the curvature of polynomial functions in pixels. | |
''' | |
# Define y-value where we want radius of curvature | |
# We'll choose the maximum y-value, corresponding to the bottom of the image | |
y_eval = np.max(ploty) | |
left_curverad = ((1 + (2*left_fit[0]*y_eval + left_fit[1])**2)**1.5) / np.absolute(2*left_fit[0]) | |
right_curverad = ((1 + (2*right_fit[0]*y_eval + right_fit[1])**2)**1.5) / np.absolute(2*right_fit[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_lane_pixels(binary_warped): | |
# Take a histogram of the bottom half of the image | |
#binary_warped = binary_warped[:,:,0] #Just get the one of the three channels | |
histogram = np.sum(binary_warped[binary_warped.shape[0]//2:,:], axis=0) | |
plt.plot(histogram) | |
# Create an output image to draw on and visualize the result | |
out_img = (np.dstack((binary_warped, binary_warped, binary_warped))).astype(np.uint8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def perspective_transform(image): | |
if len(image.shape) > 2: | |
height, width, chanels = image.shape | |
else: | |
height, width = image.shape | |
src = np.array([[(width*0.1,height*0.9), | |
(width/2.3,height/1.6), | |
(width/1.7,height/1.6), | |
(width*0.9,height*0.9)]],dtype=np.float32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mask_image(img, vertices): | |
mask = np.zeros_like(img) | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def threshold(image,ksize, abs_sobel_thresh_param_x, abs_sobel_thresh_param_y ,mag_thresh_param, dir_thresh_param,saturation_thresh_param, hue_thresh_param): | |
# Convert original RGB image to Gray Image | |
grayImg = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) | |
# Gradient Threshold | |
gradx = abs_sobel_thresh(grayImg, orient='x', sobel_kernel=ksize, thresh=abs_sobel_thresh_param_x) | |
grady = abs_sobel_thresh(grayImg, orient='y', sobel_kernel=ksize, thresh=abs_sobel_thresh_param_y) | |
mag_binary = mag_thresh(grayImg, sobel_kernel=ksize, mag_thresh=mag_thresh_param) | |
dir_binary = dir_threshold(grayImg, sobel_kernel=ksize, thresh=dir_thresh_param) | |
combined_gradient_binary = np.zeros_like(dir_binary) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def color_threshold(imgage, S_thresh=(0, 255),H_thresh=(0, 255)): | |
hls = cv2.cvtColor(image, cv2.COLOR_RGB2HLS) | |
H = hls[:,:,0] | |
S = hls[:,:,2] | |
binary_output = np.zeros_like(S) | |
binary_output[(S > S_thresh[0]) & (S <= S_thresh[1])& (H > H_thresh[0])& (H <= H_thresh[1])] = 1 | |
return binary_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def abs_sobel_thresh(img, orient='x', sobel_kernel=-1, thresh=(60, 150)): | |
# Calculate directional gradient | |
# Apply threshold | |
thresh_min = thresh[0] | |
thresh_max = thresh[1] | |
grayImg = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) | |
if orient =='x': | |
sobelDir = cv2.Sobel(grayImg, cv2.CV_64F, 1,0, ksize=sobel_kernel) #x oritentaion | |
elif orient =='y': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
import glob | |
import matplotlib.pyplot as plt | |
import matplotlib.image as mpimg | |
import json | |
%matplotlib qt | |
# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0) | |
objp = np.zeros((6*9,3), np.float32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def draw_lines(img, lines, color=[255, 0, 0], thickness=4): | |
leftLineSegmentx = [] | |
leftLineSegmenty = [] | |
rightLineSegmentx = [] | |
rightLineSegmenty = [] | |
if lines is not None: #Error Handling | |
for line in lines: | |
for x1,y1,x2,y2 in line: | |
#Idetify whether the line is left or right line |
NewerOlder