kitti Odometry數(shù)據(jù)集固耘,帶位置真值的數(shù)據(jù),包含11個(gè)場(chǎng)景词身,但可惜只對(duì)齊了圖像和激光數(shù)據(jù)厅目,沒有oxts數(shù)據(jù),也就是沒有rtk法严、imu等數(shù)據(jù)损敷,對(duì)于做vio、lio等任務(wù)就沒法搞了深啤,好在數(shù)據(jù)說明里有寫到這11個(gè)場(chǎng)景對(duì)應(yīng)的raw數(shù)據(jù)拗馒,如下:
seq_map = {
"00": {"name": "2011_10_03_drive_0027", "start": 0, "end": 4540},
"01": {"name": "2011_10_03_drive_0042", "start": 0, "end": 1100},
"02": {"name": "2011_10_03_drive_0034", "start": 0, "end": 4660},
"03": {"name": "2011_09_26_drive_0067", "start": 0, "end": 800},
"04": {"name": "2011_09_30_drive_0016", "start": 0, "end": 270},
"05": {"name": "2011_09_30_drive_0018", "start": 0, "end": 2760},
"06": {"name": "2011_09_30_drive_0020", "start": 0, "end": 1100},
"07": {"name": "2011_09_30_drive_0027", "start": 0, "end": 1100},
"08": {"name": "2011_09_30_drive_0028", "start": 1100, "end": 5170},
"09": {"name": "2011_09_30_drive_0033", "start": 0, "end": 1590},
"10": {"name": "2011_09_30_drive_0034", "start": 0, "end": 1200}
}
有了raw數(shù)據(jù),就有了oxts數(shù)據(jù)了溯街,只要基于時(shí)間戳做個(gè)對(duì)齊就行了诱桂,由于想要100hz的oxts數(shù)據(jù)洋丐,所以選擇unsync的raw數(shù)據(jù),sync的raw數(shù)據(jù)只有10hz
還有大神支出raw里的oxts數(shù)據(jù)時(shí)間戳存在跳變情況挥等,需要做些處理友绝,詳見:https://zhuanlan.zhihu.com/p/75672946
https://zhuanlan.zhihu.com/p/115562083
我實(shí)現(xiàn)的一個(gè)處理oxts時(shí)間戳跳變情況函數(shù),可以參考下
def load_timestamps(timestamps_file):
timestamps = []
with open(timestamps_file, 'r') as f:
for line in f.readlines():
# NB: datetime only supports microseconds, but KITTI timestamps
# give nanoseconds, so need to truncate last 4 characters to
# get rid of \n (counts as 1) and extra 3 digits
t = dt.datetime.strptime(line[:-4], '%Y-%m-%d %H:%M:%S.%f')
t = dt.datetime.timestamp(t)
timestamps.append(t)
return timestamps
def load_sync_timestamps(timestamps_file, std_dt=0.01):
max_dt = std_dt * 1.5
timestamps = np.array(load_timestamps(timestamps_file))
x = np.arange(0, len(timestamps))
last_timestamp = timestamps[:-1]
curr_timestamp = timestamps[1:]
dt = np.array(curr_timestamp - last_timestamp) # 計(jì)算前后幀時(shí)間差
print(timestamps_file)
print("dt > {}: \n{}".format(max_dt, dt[dt > max_dt]))
dt = dt.tolist()
dt.append(std_dt)
dt = np.array(dt)
unsync_x = x[dt > max_dt]
print("dt > {}: \n{}".format(max_dt, unsync_x))
for i in unsync_x:
succ = False
# 向前對(duì)齊
while (not succ):
ii = i-1
if ii < 0:
break
if ii not in unsync_x:
for j in range(ii+1, i+1):
timestamps[j] = timestamps[j-1] + std_dt
succ = True
break
# 向后對(duì)齊
while (not succ):
ii = i+1
if ii >= len(timestamps):
break
if ii not in unsync_x:
for j in range(ii, i, -1):
timestamps[j-1] = timestamps[j] - std_dt
succ = True
break
if not succ:
print("cannot sync timestamp", i, timestamps[i], dt[i])
return timestamps
對(duì)齊邏輯也簡單粗暴
def concat_oxts(oxts_timestamps, extract_raw_dir, start_time, end_time, out_file):
oxts_data = []
for idx, oxts_t in enumerate(oxts_timestamps):
if oxts_t < start_time:
continue
if oxts_t > end_time:
break
oxts_file = os.path.join(
extract_raw_dir, "oxts", "data", "{:0>10d}.txt".format(idx))
if not os.path.exists(oxts_file):
print("oxts file not exists", oxts_file)
continue
with open(oxts_file, "r") as f:
for line in f.readlines():
oxts_data.append(line)
os.makedirs(os.path.dirname(out_file), exist_ok=True)
with open(out_file, "w") as f:
f.writelines(oxts_data)
if __name__ == "__main__":
os.makedirs(oxts_out_dir, exist_ok=True)
# 對(duì)齊時(shí)間戳找到oxts數(shù)據(jù)
for seq in seq_map:
print(seq)
post_raw_dir = seq_map[seq]["name"][:10]
extract_raw_dir = os.path.join(
raw_dir, post_raw_dir, seq_map[seq]["name"] + "_extract")
if not os.path.exists(extract_raw_dir):
print("raw seq data not exists", extract_raw_dir)
continue
start_idx = seq_map[seq]["start"]
end_idx = seq_map[seq]["end"]
image_timestamps_file = os.path.join(
extract_raw_dir, "image_02", 'timestamps.txt')
image_timestamps = load_sync_timestamps(image_timestamps_file, 0.1)
# 扣出對(duì)應(yīng)時(shí)間戳內(nèi)的oxts數(shù)據(jù)
oxts_timestamps_file = os.path.join(
extract_raw_dir, "oxts", 'timestamps.txt')
oxts_timestamps = load_sync_timestamps(oxts_timestamps_file, 0.01)
# 上一幀到當(dāng)前幀之間的oxts數(shù)據(jù)
for i in range(start_idx, end_idx + 1):
if i == 0:
start_time = image_timestamps[i] - 0.1
else:
start_time = image_timestamps[i-1]
end_time = image_timestamps[i]
oxts_file = os.path.join(
oxts_out_dir, seq, "{:0>10d}.txt".format(i-start_idx))
concat_oxts(oxts_timestamps, extract_raw_dir,
start_time, end_time, oxts_file)
提供一個(gè)我對(duì)齊好的oxts數(shù)據(jù)肝劲,由于03對(duì)應(yīng)的2011_09_26_drive_0067數(shù)據(jù)官網(wǎng)無法下載迁客,所以沒有03對(duì)應(yīng)的oxts數(shù)據(jù)
鏈接: https://pan.baidu.com/s/1CR8aaNB83cWC0nrIatag5w 提取碼: gi9c