Loading train1/main.py +48 −14 Changes for train1/main.py: 48 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ import ld_module_detection start_time = time.time() # rootdir = 'D:/train_set/clips/0531/' rootdir = 'D:/train_set/clips/examine/' rootdir = 'D:/train_set/clips/submit/test/' foldername = "null" Loading @@ -33,11 +33,11 @@ def lane_detection(input_img, original_img, i): r_thresh=r_thresh, s_thresh=s_thresh, b_thresh=b_thresh, g_thresh=g_thresh) \ + ld_module_binary.abs_thresh(transformed_img, sobel_kernel=3, mag_thresh=( 35, 210), direction='x') # + ld_module_binary.abs_thresh(transformed_img, # sobel_kernel=3, # mag_thresh=( # 35, 210), # direction='x') # 3 add line mark # 3.1 determine the start point of the mark Loading Loading @@ -65,21 +65,41 @@ def lane_detection(input_img, original_img, i): # # plt.subplot(121) # plt.imshow(hough_line_layer) # plt.subplot(122) plt.imshow(input_img) plt.show() # flow1 plot # plt.rcParams["font.size"] = "2.5" # plt.subplot(151) # plt.imshow(cv2.cvtColor(original_img, cv2.COLOR_BGR2RGB)) # plt.title("Raw Input") # plt.subplot(152) # plt.imshow(cv2.cvtColor(transformed_img, cv2.COLOR_BGR2RGB)) # plt.title("Perspective Transformed") # plt.subplot(153) # plt.imshow(ld_module_binary.get_hls_sthresh_img(transformed_img, thresh=s_thresh)) # plt.title("LAB Colour Space (Yellow Lane)",wrap=True) # plt.subplot(154) # plt.imshow(ld_module_binary.get_rgb_thresh_img(transformed_img, thresh=r_thresh)+ld_module_binary.get_rgb_thresh_img(transformed_img, thresh=g_thresh, channel='G')) # plt.title("RGB Colour Space (White Lane)",wrap=True) # plt.subplot(155) # plt.imshow(input_img) # plt.title("Binarization") # plt.savefig("flow12.svg", format='svg', dpi=600) # 3.1.2 find peak (line) number img_peak_histogram = ld_module_detection.intensity_map(input_img, 150) img_peak_histogram = ld_module_detection.intensity_map(input_img, 150) \ \ # plt.subplot(121) # 3.1.3 find lane via sliding window plt.imshow(input_img) mark_layer = np.zeros((600, 600, 3), np.uint8) for midpoint in img_peak_histogram: # midpoint (width) mark_layer = np.zeros((600, 600, 3), np.uint8) if 100 < midpoint < 500: point_array, ycl, xcl, rcl = ld_module_detection.fit_lane(input_img, midpoint) # print(point_array) # plt.scatter(x=point_array.T[0], y=point_array.T[1], s=16) # 3.1.3.1 draw line over the original image if point_array.size > 0 and rcl > 800 and rcl < 2147483647: Loading @@ -88,7 +108,7 @@ def lane_detection(input_img, original_img, i): # print(i) cv2.circle(mark_layer, tuple(point), 10, (0, 0, 255), thickness=-1) cv2.circle(mark_layer, tuple([int(ycl), int(xcl)]), int(rcl), (0, 255, 0), thickness=10) # plt.gca().add_artist(plt.Circle((ycl, xcl), rcl, color='r', fill=False,lw=8)) # 3.1.3.2 transform the mark layer back pts2 = np.float32([[450, 300], [-851, 720], [870, 300], [2057, 720]]) pts1 = np.float32([[0, 0], [0, 600], [600, 0], [600, 600]]) Loading @@ -99,10 +119,24 @@ def lane_detection(input_img, original_img, i): mark_layer_mask = np.where(mark_layer_trans > 0, 0, 1) original_img = original_img * mark_layer_mask + mark_layer_trans # plt.xlim(right=599) # xmax is your value # plt.xlim(left=0) # xmin is your value # plt.ylim(top=599) # ymax is your value # plt.ylim(bottom=0) # ymin is your value # plt.gca().invert_yaxis() # plt.subplot(122) # plt.imshow(original_img) # plt.show() # 4 save image # simulate not save image cv2.imwrite("op_module/" + foldername + "_" + filename + ".png", original_img) plt.imshow(cv2.cvtColor(original_img.astype("uint8"), cv2.COLOR_BGR2RGB)) plt.savefig("output.svg", format='svg', dpi=600) for subdir, dirs, files in os.walk(rootdir): for d in dirs: Loading @@ -120,7 +154,7 @@ for subdir, dirs, files in os.walk(rootdir): # print(k1) # rotate_num = 3 for k2 in range(1, 21): for k2 in range(1, 2): input_img = cv2.imread(subdir + d + "/" + str(k2) + ".jpg") input_img = cv2.cvtColor(input_img, cv2.COLOR_BGR2RGB) Loading Loading
train1/main.py +48 −14 Changes for train1/main.py: 48 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ import ld_module_detection start_time = time.time() # rootdir = 'D:/train_set/clips/0531/' rootdir = 'D:/train_set/clips/examine/' rootdir = 'D:/train_set/clips/submit/test/' foldername = "null" Loading @@ -33,11 +33,11 @@ def lane_detection(input_img, original_img, i): r_thresh=r_thresh, s_thresh=s_thresh, b_thresh=b_thresh, g_thresh=g_thresh) \ + ld_module_binary.abs_thresh(transformed_img, sobel_kernel=3, mag_thresh=( 35, 210), direction='x') # + ld_module_binary.abs_thresh(transformed_img, # sobel_kernel=3, # mag_thresh=( # 35, 210), # direction='x') # 3 add line mark # 3.1 determine the start point of the mark Loading Loading @@ -65,21 +65,41 @@ def lane_detection(input_img, original_img, i): # # plt.subplot(121) # plt.imshow(hough_line_layer) # plt.subplot(122) plt.imshow(input_img) plt.show() # flow1 plot # plt.rcParams["font.size"] = "2.5" # plt.subplot(151) # plt.imshow(cv2.cvtColor(original_img, cv2.COLOR_BGR2RGB)) # plt.title("Raw Input") # plt.subplot(152) # plt.imshow(cv2.cvtColor(transformed_img, cv2.COLOR_BGR2RGB)) # plt.title("Perspective Transformed") # plt.subplot(153) # plt.imshow(ld_module_binary.get_hls_sthresh_img(transformed_img, thresh=s_thresh)) # plt.title("LAB Colour Space (Yellow Lane)",wrap=True) # plt.subplot(154) # plt.imshow(ld_module_binary.get_rgb_thresh_img(transformed_img, thresh=r_thresh)+ld_module_binary.get_rgb_thresh_img(transformed_img, thresh=g_thresh, channel='G')) # plt.title("RGB Colour Space (White Lane)",wrap=True) # plt.subplot(155) # plt.imshow(input_img) # plt.title("Binarization") # plt.savefig("flow12.svg", format='svg', dpi=600) # 3.1.2 find peak (line) number img_peak_histogram = ld_module_detection.intensity_map(input_img, 150) img_peak_histogram = ld_module_detection.intensity_map(input_img, 150) \ \ # plt.subplot(121) # 3.1.3 find lane via sliding window plt.imshow(input_img) mark_layer = np.zeros((600, 600, 3), np.uint8) for midpoint in img_peak_histogram: # midpoint (width) mark_layer = np.zeros((600, 600, 3), np.uint8) if 100 < midpoint < 500: point_array, ycl, xcl, rcl = ld_module_detection.fit_lane(input_img, midpoint) # print(point_array) # plt.scatter(x=point_array.T[0], y=point_array.T[1], s=16) # 3.1.3.1 draw line over the original image if point_array.size > 0 and rcl > 800 and rcl < 2147483647: Loading @@ -88,7 +108,7 @@ def lane_detection(input_img, original_img, i): # print(i) cv2.circle(mark_layer, tuple(point), 10, (0, 0, 255), thickness=-1) cv2.circle(mark_layer, tuple([int(ycl), int(xcl)]), int(rcl), (0, 255, 0), thickness=10) # plt.gca().add_artist(plt.Circle((ycl, xcl), rcl, color='r', fill=False,lw=8)) # 3.1.3.2 transform the mark layer back pts2 = np.float32([[450, 300], [-851, 720], [870, 300], [2057, 720]]) pts1 = np.float32([[0, 0], [0, 600], [600, 0], [600, 600]]) Loading @@ -99,10 +119,24 @@ def lane_detection(input_img, original_img, i): mark_layer_mask = np.where(mark_layer_trans > 0, 0, 1) original_img = original_img * mark_layer_mask + mark_layer_trans # plt.xlim(right=599) # xmax is your value # plt.xlim(left=0) # xmin is your value # plt.ylim(top=599) # ymax is your value # plt.ylim(bottom=0) # ymin is your value # plt.gca().invert_yaxis() # plt.subplot(122) # plt.imshow(original_img) # plt.show() # 4 save image # simulate not save image cv2.imwrite("op_module/" + foldername + "_" + filename + ".png", original_img) plt.imshow(cv2.cvtColor(original_img.astype("uint8"), cv2.COLOR_BGR2RGB)) plt.savefig("output.svg", format='svg', dpi=600) for subdir, dirs, files in os.walk(rootdir): for d in dirs: Loading @@ -120,7 +154,7 @@ for subdir, dirs, files in os.walk(rootdir): # print(k1) # rotate_num = 3 for k2 in range(1, 21): for k2 in range(1, 2): input_img = cv2.imread(subdir + d + "/" + str(k2) + ".jpg") input_img = cv2.cvtColor(input_img, cv2.COLOR_BGR2RGB) Loading