def _get_index(self, label): w, h = label.size if h != self.data_dict['input_size'][0]: scale_f = lambda x: int( (x * 1.0 / self.data_dict['input_size'][0]) * h) sample_tmp = list(map(scale_f, self.row_anchor)) # 288 inx [121, 131, 141, 150, 160, 170, 180, 189, 199, 209, 219, 228, 238, 248, 258, 267, 277, 287] # 590 inx [247, 268, 288, 307, 327, 348, 368, 387, 407, 428, 448, 467, 487, 508, 528, 546, 567, 587] all_idx = np.zeros( (self.data_dict['num_lanes'], len(sample_tmp), 2)) #4*18*2 第一个通道存放590 对应的anchor 第二个通道存放车道线位置。如果不存在车道线位置为-1 for i, r in enumerate(sample_tmp): label_r = np.asarray(label)[int(round(r))] for lane_idx in range(1, self.data_dict['num_lanes'] + 1): # culane label 四条车道线像素分别喂1 2 3 4 pos = np.where(label_r == lane_idx)[0] if len(pos) == 0: all_idx[lane_idx - 1, i, 0] = r all_idx[lane_idx - 1, i, 1] = -1 continue pos = np.mean(pos) all_idx[lane_idx - 1, i, 0] = r all_idx[lane_idx - 1, i, 1] = pos # data augmentation: extend the lane to the boundary of image all_idx_cp = all_idx.copy() for i in range(self.data_dict['num_lanes']): if np.all(all_idx_cp[i, :, 1] == -1): continue # if there is no lane valid = all_idx_cp[i, :, 1] != -1 # get all valid lane points' index valid_idx = all_idx_cp[i, valid, :] # get all valid lane points if valid_idx[-1, 0] == all_idx_cp[0, -1, 0]: # if the last valid lane point's y-coordinate is already the last y-coordinate of all rows # this means this lane has reached the bottom boundary of the image # so we skip continue if len(valid_idx) < 6: continue # if the lane is too short to extend valid_idx_half = valid_idx[len(valid_idx) // 2:, :] p = np.polyfit(valid_idx_half[:, 0], valid_idx_half[:, 1], deg=1) #多项式拟合 start_line = valid_idx_half[-1, 0] pos = find_start_pos(all_idx_cp[i, :, 0], start_line) + 1 fitted = np.polyval(p, all_idx_cp[i, pos:, 0]) fitted = np.array( [-1 if y < 0 or y > w - 1 else y for y in fitted]) assert np.all(all_idx_cp[i, pos:, 1] == -1) all_idx_cp[i, pos:, 1] = fitted if -1 in all_idx[:, :, 0]: pdb.set_trace() return all_idx_cp
def _get_index(self, label): w, h = label.size if h != 288: scale_f = lambda x: int((x * 1.0 / 288) * h) sample_tmp = list(map(scale_f, self.row_anchor)) all_idx = np.zeros((self.num_lanes, len(sample_tmp), 2)) for i, r in enumerate(sample_tmp): label_r = np.asarray(label)[int(round(r))] for lane_idx in range(1, self.num_lanes + 1): pos = np.where(label_r == lane_idx)[0] if len(pos) == 0: all_idx[lane_idx - 1, i, 0] = r all_idx[lane_idx - 1, i, 1] = -1 continue pos = np.mean(pos) all_idx[lane_idx - 1, i, 0] = r all_idx[lane_idx - 1, i, 1] = pos if not self.extend: return all_idx # data augmentation: extend the lane to the boundary of image all_idx_cp = all_idx.copy() for i in range(self.num_lanes): if np.all(all_idx_cp[i, :, 1] == -1): continue # if there is no lane valid = all_idx_cp[i, :, 1] != -1 # get all valid lane points' index valid_idx = all_idx_cp[i, valid, :] # get all valid lane points if valid_idx[-1, 0] == all_idx_cp[0, -1, 0]: # if the last valid lane point's y-coordinate is already the last y-coordinate of all rows # this means this lane has reached the bottom boundary of the image # so we skip continue if len(valid_idx) < 6: continue # if the lane is too short to extend valid_idx_half = valid_idx[len(valid_idx) // 2:, :] p = np.polyfit(valid_idx_half[:, 0], valid_idx_half[:, 1], deg=1) start_line = valid_idx_half[-1, 0] pos = find_start_pos(all_idx_cp[i, :, 0], start_line) + 1 fitted = np.polyval(p, all_idx_cp[i, pos:, 0]) fitted = np.array( [-1 if y < 0 or y > w - 1 else y for y in fitted]) assert np.all(all_idx_cp[i, pos:, 1] == -1) all_idx_cp[i, pos:, 1] = fitted if -1 in all_idx[:, :, 0]: pdb.set_trace() return all_idx_cp
def _get_index(self, label): w, h = label.size if h != 256: scale_f = lambda x: int((x * 1.0 / 256) * h) sample_tmp = list(map(scale_f, self.row_anchor)) all_idx = np.zeros((4, len(sample_tmp), 2)) for i, r in enumerate(sample_tmp): label_r = np.asarray(label)[int(round(r))] for lane_idx in range(1, 5): pos = np.where(label_r == lane_idx)[0] if len(pos) == 0: all_idx[lane_idx - 1, i, 0] = r all_idx[lane_idx - 1, i, 1] = -1 continue pos = np.mean(pos) all_idx[lane_idx - 1, i, 0] = r all_idx[lane_idx - 1, i, 1] = pos all_idx_cp = all_idx.copy() for i in range(4): if np.all(all_idx_cp[i, :, 1] == -1): continue valid = all_idx_cp[i, :, 1] != -1 valid_idx = all_idx_cp[i, valid, :] if valid_idx[-1, 0] == all_idx_cp[0, -1, 0]: continue if len(valid_idx) < 6: continue valid_idx_half = valid_idx[len(valid_idx) // 2:, :] p = np.polyfit(valid_idx_half[:, 0], valid_idx_half[:, 1], deg=1) start_line = valid_idx_half[-1, 0] pos = find_start_pos(all_idx_cp[i, :, 0], start_line) + 1 fitted = np.polyval(p, all_idx_cp[i, pos:, 0]) fitted = np.array( [-1 if y < 0 or y > w - 1 else y for y in fitted]) assert np.all(all_idx_cp[i, pos:, 1] == -1) all_idx_cp[i, pos:, 1] = fitted if -1 in all_idx[:, :, 0]: pdb.set_trace() return all_idx_cp