Skip to content

Instantly share code, notes, and snippets.

@gy2256
Created December 18, 2018 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gy2256/ef17b8a276b23fbad737656cbdac63e8 to your computer and use it in GitHub Desktop.
Save gy2256/ef17b8a276b23fbad737656cbdac63e8 to your computer and use it in GitHub Desktop.
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) +
left_fit_before[1]*nonzeroy + left_fit_before[2] + margin)))
right_lane_inds = ((nonzerox > (right_fit_before[0]*(nonzeroy**2) + right_fit_before[1]*nonzeroy +
right_fit_before[2] - margin)) & (nonzerox < (right_fit_before[0]*(nonzeroy**2) +
right_fit_before[1]*nonzeroy + right_fit_before[2] + margin)))
# Again, extract left and right line pixel positions
leftx = nonzerox[left_lane_inds]
lefty = nonzeroy[left_lane_inds]
rightx = nonzerox[right_lane_inds]
righty = nonzeroy[right_lane_inds]
left_fit_current = np.polyfit(lefty, leftx, 2)
right_fit_current = np.polyfit(righty, rightx, 2)
# Generate x and y values for plotting
ploty_current = np.linspace(0, img_shape[0]-1, img_shape[0])
### TO-DO: Calc both polynomials using ploty, left_fit and right_fit ###
left_fitx_current = left_fit[0]*ploty**2 + left_fit[1]*ploty + left_fit[2]
right_fitx_current = right_fit[0]*ploty**2 + right_fit[1]*ploty + right_fit[2]
return left_fit_current, right_fit_current, ploty, leftx, lefty, rightx, righty, left_fitx_current, right_fitx_current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment