def populateLines(left_fit, right_fit, left_fitx, right_fitx, ploty, left_curvature, right_curvature): left_line = Line() left_line.current_fit = left_fit left_line.recent_xfitted.append(left_fitx) if len(left_line.recent_xfitted) > 10: left_line.recent_xfitted.remove(0) left_line.last_fits.append(left_fit) if len(left_line.last_fits) > 5: left_line.last_fits.remove(0) left_line.allx = left_fitx left_line.ally = ploty right_line = Line() right_line.current_fit = right_fit right_line.recent_xfitted.append(right_fitx) if len(right_line.recent_xfitted) > 10: right_line.recent_xfitted.remove(0) right_line.last_fits.append(right_fit) if len(right_line.last_fits) > 5: right_line.last_fits.remove(0) right_line.allx = right_fitx right_line.ally = ploty left_line.radius_of_curvature = left_curvature right_line.radius_of_curvature = right_curvature left_line.shift = left_fitx[500] right_line.shift = right_fitx[500] return left_line, right_line
left_line.top.append(left_top) left_x_int = np.mean(left_line.x_int) left_top = np.mean(left_line.top) left_line.lastx_int = left_x_int left_line.last_top = left_top #Add averaging top and bottom to avoid losing line left_x = np.append(left_line.allx, left_x_int) left_y = np.append(left_line.ally, 720) left_x = np.append(left_x, left_top) left_y = np.append(left_y, 0) #sort values with added left_x, left_y = left_line.sort(left_x, left_y) left_line.allx = left_x left_line.ally = left_y # Recalculate polynomial left_fit = np.polyfit(left_y, left_x, 2) left_line.fit0.append(left_fit[0]) left_line.fit1.append(left_fit[1]) left_line.fit2.append(left_fit[2]) left_line.curvature.append( cr.get_curvature(left_line.allx, left_line.ally)) if (right_line.detected): right_fit = np.polyfit(right_line.ally, right_line.allx, 2) right_x_int, right_top = right_line.get_top_and_bottom(right_fit)
show_img(img) undist = calibrator.undistort(img) # found gradient gradient = pipeline.compute_gradient(undist) # wrap imgs wrapped = pipeline.wrap(gradient) # find left and right pixel poses # find left and right polyline left_line.count_check() right_line.count_check() lx, ly, rx, ry = pipeline.find_lines(wrapped) if len(rx) > 0 and len(ry) > 0: # set was detected right_line.was_detected = True # add founded points to instanse right_line.allx = rx right_line.ally = ry # add poly l_fit, right_line.polx, right_line.ploty = pipeline.find_poly(wrapped.shape,right_line.allx, right_line.ally) right_line.add_fit(l_fit) # if find points of left line if len(lx) > 0 and len(ly) > 0: # set was detected left_line.was_detected = True # add founded points to instanse left_line.allx = lx left_line.ally = ly # add poly r_fit, left_line.polx, left_line.ploty = pipeline.find_poly(wrapped.shape,left_line.allx, left_line.ally) left_line.add_fit(r_fit)