def auto_lane(img): polyfit = Polyfit() img = cv2.resize(img,dsize=(320,180)) lower_black = np.array([0,0,0]) upper_black = np.array([180,255,70]) frame = warp(img) cv2.imshow('frame',frame) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) mask = cv2.inRange(hsv, lower_black, upper_black) cv2.imwrite('./mask.jpg',mask) cv2.imshow('frame:',mask) cv2.waitKey(1) # frame = combined_threshold(frame) try: left_fit, right_fit, vars = polyfit.poly_fit_skip(mask) if left_fit =='None' and right_fit == 'None': result,offset,Radius = img,0,10000 cv2.imshow('re', cv2.resize(img, dsize=(640, 320))) cv2.waitKey(1) elif left_fit !='None' and right_fit == 'None' or left_fit !='None' and right_fit != 'None' : result,offset,Radius = draw(img, mask, left_fit, right_fit,para = 277,meter = 30) cv2.imshow('re',cv2.resize(result,dsize=(640,320))) cv2.waitKey(1) else: print '-----1----unexcept error--------1----' result,offset,Radius = img,0,10000 except: print '---------unexcept error------------' result,offset,Radius = img,0,10000 return result,offset,Radius
def draw_lane(img_arr): polyfit = Polyfit() combined_output = combined_threshold(img_arr) warped = warp(combined_output) left_fit, right_fit, vars = polyfit.poly_fit_skip(warped) # print(left_fit,right_fit) result = draw(img_arr, warped, left_fit, right_fit) return result,left_fit,right_fit
def auto_lane(img, n): polyfit = Polyfit() img = cv2.resize(img, dsize=(320, 180)) frame = warp(img) cv2.imshow('warped', frame) # mask_flag = hsv(frame) # dec_flag = dec_lane(mask_flag) # mask = sobel(frame) # corner_det(mask,frame) mask = hsv(frame) print(mask[2]) cv2.waitKey(1) #mask = cv2.GaussianBlur(frame,(5,5),0) kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2)) mask = cv2.erode(mask, kernel) mask = cv2.dilate(mask, kernel) cv2.imwrite('./image1/' + str(n) + '.jpg', hsv(img)) cv2.imwrite('./mask.jpg', mask) cv2.imshow('frame:', mask) cv2.waitKey(1) # frame = combined_threshold(frame) try: left_fit, right_fit, vars = polyfit.poly_fit_skip(mask) if left_fit == 'None' and right_fit == 'None': result, offset, Radius = img, 'None', 10000 cv2.imshow('re', cv2.resize(img, dsize=(640, 320))) cv2.waitKey(1) elif left_fit != 'None' and right_fit == 'None' or left_fit != 'None' and right_fit != 'None': result, offset, Radius = draw(img, mask, left_fit, right_fit) cv2.imshow('re', cv2.resize(result, dsize=(640, 320))) cv2.waitKey(1) else: result, offset, Radius = img, 0, 10000 except: result, offset, Radius = img, 0, 10000 '''offset --------------------''' if offset == 'None': offset = 'None' else: offset = offset + 24.00 return result, offset, Radius
def auto_lane(img): polyfit = Polyfit() img = cv2.resize(img,dsize=(320,180)) frame = warp(img) cv2.imshow('warped',frame) mask_flag = hsv(frame) dec_flag = dec_lane(mask_flag) print 'dec_lane flag = ',dec_flag mask = sobel(frame) #mask = hsv(frame) #mask = canny(frame,50,150) #mask = cv2.GaussianBlur(frame,(5,5),0) kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(2,2)) mask = cv2.erode(mask,kernel) mask = cv2.dilate(mask,kernel) cv2.imshow('mask',mask) cv2.waitKey(1) # frame = combined_threshold(frame) try: left_fit, right_fit, vars = polyfit.poly_fit_skip(mask) if left_fit =='None' and right_fit == 'None': result,offset,Radius = img,'None',10000 cv2.imshow('re', cv2.resize(img, dsize=(640, 320))) cv2.waitKey(1) elif left_fit !='None' and right_fit == 'None' or left_fit !='None' and right_fit != 'None' : result,offset,Radius = draw(img, mask, left_fit, right_fit) cv2.imshow('re',cv2.resize(result,dsize=(640,320))) cv2.waitKey(1) else: print '-----1----unexcept error--------1----' result,offset,Radius = img,0,10000 except: print '---------unexcept error------------' result,offset,Radius = img,0,10000 '''offset --------------------''' if offset == 'None': offset = 'None' else: offset = offset return result,offset,Radius
def auto_lane(img): polyfit = Polyfit() img = cv2.resize(img, dsize=(320, 180)) cv2.imwrite('./resize.jpg', img) warped = warp(img) mask = abs_threshold(warped) # mask = hsv(warped) # frame = combined_threshold(frame) left_fit, right_fit, vars = polyfit.poly_fit_skip(mask) if left_fit == 'None' or right_fit == 'None': result, offset, Radius = None, None, None cv2.imshow('re', cv2.resize(img, dsize=(853, 480))) cv2.waitKey(0) return result, offset, Radius else: result, offset, Radius = draw(img, mask, left_fit, right_fit) cv2.imshow('re', cv2.resize(result, dsize=(853, 480))) cv2.waitKey(0) cv2.imwrite("./res.jpg", result) return result, offset, Radius
def auto_lane(img): polyfit = Polyfit() img = cv2.resize(img, dsize=(320, 180)) lower_black = np.array([0, 0, 0]) upper_black = np.array([180, 255, 70]) frame = warp(img) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) mask = cv2.inRange(hsv, lower_black, upper_black) cv2.imshow('mask', mask) # frame = combined_threshold(frame) left_fit, right_fit, vars = polyfit.poly_fit_skip(mask) if left_fit == 'None' or right_fit == 'None': result, offset, Radius = None, None, None cv2.imshow('re', cv2.resize(img, dsize=(853, 480))) cv2.waitKey(0) return result, offset, Radius else: result, offset, Radius = draw(img, mask, left_fit, right_fit) cv2.imshow('re', cv2.resize(result, dsize=(853, 480))) cv2.waitKey(0) return result, offset, Radius
def auto_lane(img): polyfit = Polyfit() img = cv2.resize(img, dsize=(320, 180)) #light recongise GreenLight, RedLight, SpeedLimit, HireSign = recongise(img) GreenLight = main(img) frame = warp(img) mask = hsv(frame) # dec_flag = dec_lane(mask) #mask = canny(frame,50,150) #mask = cv2.GaussianBlur(frame,(5,5),0) kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2)) mask = cv2.erode(mask, kernel) mask = cv2.dilate(mask, kernel) cv2.imshow('mask', mask) cv2.waitKey(1) try: left_fit, right_fit, vars = polyfit.poly_fit_skip(mask) if left_fit == 'None' and right_fit == 'None': result, offset, Radius, k_error = img, 'None', 10000, 0 ## cv2.imshow('re', cv2.resize(img, dsize=(640, 320))) ## cv2.waitKey(1) elif left_fit != 'None' and right_fit == 'None' or left_fit != 'None' and right_fit != 'None': result, offset, Radius, k_error = draw(img, mask, left_fit, right_fit) ## cv2.imshow('re',cv2.resize(result,dsize=(640,320))) cv2.waitKey(1) else: result, offset, Radius, k_error = img, 0, 10000, 0 except: result, offset, Radius, k_error = img, 0, 10000, 0 '''offset --------------------''' '''--------------------------lanetype--------------------------''' '''zhixian:1..wandao:2...zhijiaowan: 3''' if offset == 'None': offset = 'None' else: offset = offset if abs(k_error) < 0.06: cur_mode = 1 #wandao elif abs(k_error) >= 0.06: cur_mode = 2 #zhidao elif k_error == 'None': cur_mode = last_mode #keeping '''cornerflage''' corner_flag = corner_det(mask, img) if corner_flag == 0: pass if corner_flag == 1: cur_mode = 3 last_mode = cur_mode Lane_type = cur_mode '''-----------SpeedLimit----------''' SpeedLimit = 0 '''-----------RedLight------------''' RedLight = 0 '''-----------GreenLight----------''' GreenLight = 0 '''-----------HireSign------------''' HireSign = 0 '''-----------StopSign------------''' StopSign = 0 cv2.imshow('result', result) cv2.waitKey(1) return result, offset, Radius, Lane_type, SpeedLimit, RedLight, GreenLight, HireSign, StopSign
if off_center<0: print("Offset to right:",abs(off_center),str("m")) center_messages = "Offset to right: : " + str(abs(off_center))+str("m") return center_messages if off_center>0: print("Offset to left:",abs(off_center),str("m")) center_messages = "Offset to left:" + str(abs(off_center))+str("m") return center_messages if off_center == 0: print("On the center:",abs(off_center),str("m")) center_messages = "On the center:" + str(abs(off_center))+str("m") return center_messages if __name__ == "__main__": # x,y = ######计算距离 x,y=197,894 flag,alpha,n,m,raw,colum = direction_calculate(x,y) if flag == 1 : distance = distance_calculate(n,m,raw,colum) print(flag,alpha,distance) else: pass #####计算偏离中心的距离 img_arr =cv2.imread("./input/test6.jpg") polyfit = Polyfit() combined_output = combined_threshold(img_arr) warped = perspective_1(combined_output) left_fit, right_fit, vars = polyfit.poly_fit_skip(warped) offset = off_center(img_arr,left_fit,right_fit)
return result, left_fit, right_fit if __name__ == "__main__": # polyfit = Polyfit() # original_video = './video.mp4' # cap = cv2.VideoCapture(original_video) # n = 0 # while (1): # n = n+1 # ret,img = cap.read() # img = cv2.resize(img,dsize=(320,180)) # frame = warp(img) # cv2.imshow('warp',frame) # frame = combined_threshold(frame) # left_fit, right_fit, vars = polyfit.poly_fit_skip(frame) # result = draw(img, frame, left_fit, right_fit) # cv2.imshow('re', result) # cv2.waitKey(1) #1280 720 polyfit = Polyfit() img = cv2.imread('./101.jpg') frame = warp(img) frame = combined_threshold(frame) left_fit, right_fit, vars = polyfit.poly_fit_skip(frame) result = draw(img, frame, left_fit, right_fit) cv2.imshow('re', result) cv2.waitKey(0)