from .colour_segmentation import segment_lanes
from ...config import config
from .midlane_estimation import estimate_midlane
import cv2
import numpy as np
from .data_extraction import FetchInfoAndDisplay
from .cleaning import GetYellowInnerEdge, ExtendShortLane
# this is my lane_detection file
def detect_lanes(img):
img_cropped = img[config.CropHeight_resized:,:]
mid_lane_mask, mid_lane_edge,outer_lane_edge, outerlane_side_sep,outerlane_points = segment_lanes(img_cropped,config.minArea_resized)
estimated_midlane = estimate_midlane(mid_lane_edge,config.MaxDist_resized)
OuterLane_OneSide, Outer_cnts_oneSide,Mid_cnts, Offset_correction = GetYellowInnerEdge(outer_lane_edge, estimated_midlane, outerlane_points)
extended_midlane, extended_outerlane = ExtendShortLane(estimated_midlane,Mid_cnts,Outer_cnts_oneSide, OuterLane_OneSide)
Distance , Curvature = FetchInfoAndDisplay(mid_lane_edge, extended_midlane, extended_outerlane, img_cropped, Offset_correction=Offset_correction)
cv2.imshow("mid_lane_mask", mid_lane_mask)
cv2.imshow("mid_lane_edge", mid_lane_edge)
cv2.imshow("outer_lane_edge", outer_lane_edge)
cv2.imshow("outerlane_side_sep", outerlane_side_sep)
cv2.imshow("estimated_midlane", estimated_midlane)
cv2.imshow("OuterLane_OneSide", OuterLane_OneSide)
cv2.imshow("extended_midlane", extended_midlane)
cv2.imshow("extended_outerlane", extended_outerlane)
cv2.waitKey(1)
and this is my func
def ExtendShortLane(MidLane,Mid_cnts,Outer_cnts,OuterLane):
if(Mid_cnts and Outer_cnts):
Mid_cnts_Rowsorted = Cord_Sort(Mid_cnts,"rows")
Outer_cnts_Rowsorted = Cord_Sort(Outer_cnts,"rows")
Image_bottom = MidLane.shape[0]
total_no_of_cnts_midlane = Mid_cnts_Rowsorted.shape[0]
total_no_of_cnts_outerlane = Outer_cnts_Rowsorted.shape[0]
BottomPoint_Mid = Mid_cnts_Rowsorted[total_no_of_cnts_midlane-1,:]
if (BottomPoint_Mid[1] < Image_bottom):
MidLane = cv2.line(MidLane,tuple(BottomPoint_Mid),(BottomPoint_Mid[0],Image_bottom),255,2)
BottomPoint_Outer = Outer_cnts_Rowsorted[total_no_of_cnts_outerlane-1,:]
if (BottomPoint_Outer[1] < Image_bottom):
if(total_no_of_cnts_outerlane>20):
shift=20
else:
shift=2
RefLast10Points = Outer_cnts_Rowsorted[total_no_of_cnts_outerlane-shift:total_no_of_cnts_outerlane]
if(len(RefLast10Points)>1):
Ref_x = RefLast10Points[:,0] #cols
Ref_y = RefLast10Points[:,1] #rows
Ref_parameters = np.polyfit(Ref_x, Ref_y,1)
Ref_slope = Ref_parameters[0]
Ref_yiCntercept = Ref_parameters[1]
if(Ref_slope < 0):
Ref_LineTouchPoint_col = 0
Ref_LineTouchPoint_row = Ref_yiCntercept
else:
Ref_LineTouchPoint_col = OuterLane.shape[1]-1
Ref_LineTouchPoint_row = Ref_slope * Ref_LineTouchPoint_col + Ref_yiCntercept
Ref_TouchPoint = (Ref_LineTouchPoint_col,int(Ref_LineTouchPoint_row))#col,row
Ref_BottomPoint_tup = tuple(BottomPoint_Outer)
OuterLane =cv2.line(OuterLane,Ref_TouchPoint,Ref_BottomPoint_tup,255)
if(Ref_LineTouchPoint_row < Image_bottom):
Ref_TouchPoint_Ref = (Ref_LineTouchPoint_col, Image_bottom)
OuterLane = cv2.line(OuterLane,Ref_TouchPoint,Ref_TouchPoint_Ref,255,2)
return MidLane,OuterLane
why it is return None
lane assist. please help me
Your function returns values only if the if(Mid_cnts and Outer_cnts):
condition is satisfied. Otherwise it returns None
I suspect you either forgot to write the else
block for that condition, or the return
instruction should be out of the if
block