Python中使用kitti數(shù)據(jù)集實(shí)現(xiàn)自動(dòng)駕駛(繪制出所有物體的行駛軌跡)
本次內(nèi)容主要是上周內(nèi)容的延續(xù),主要畫(huà)出kitti車(chē)的行駛的軌跡
同樣的,我們先來(lái)看看最終實(shí)現(xiàn)的效果:
接下來(lái)就進(jìn)入一步步的編碼環(huán)節(jié)。。。
1、利用IMU、GPS計(jì)算汽車(chē)移動(dòng)距離和旋轉(zhuǎn)角度
計(jì)算移動(dòng)距離
- 通過(guò)GPS計(jì)算
#定義計(jì)算GPS距離方法 def computer_great_circle_distance(lat1,lon1,lat2,lon2): delta_sigma = float(np.sin(lat1*np.pi/180)*np.sin(lat2*np.pi/180)+\ np.cos(lat1*np.pi/180)*np.cos(lat2*np.pi/180)*np.cos(lon1*np.pi/180-lon2*np.pi/180)) return 6371000.0*np.arccos(np.clip(delta_sigma,-1,1)) #使用GPS計(jì)算距離 gps_distance += [computer_great_circle_distance(imu_data.lat,imu_data.lon,prev_imu_data.lat,prev_imu_data.lon)]
- 通過(guò)IMU計(jì)算
IMU_COLUMN_NAMES = ['lat','lon','alt','roll','pitch','yaw','vn','ve','vf','vl','vu','ax','ay','az','af', 'al','au','wx','wy','wz','wf','wl','wu','posacc','velacc','navstat','numsats','posmode', 'velmode','orimode'] #獲取IMU數(shù)據(jù) imu_data = read_imu('/home/wsj/data/kitty/RawData/2011_09_26/2011_09_26_drive_0005_sync/oxts/data/%010d.txt'%frame) #使用IMU計(jì)算距離 imu_distance += [0.1*np.linalg.norm(imu_data[['vf','vl']])]
- 比較兩種方式計(jì)算出的距離(GPS/IMU)
import matplotlib.pyplot as plt plt.figure(figsize=(20,10)) plt.plot(gps_distance, label='gps_distance') plt.plot(imu_distance, label='imu_distance') plt.legend() plt.show()
顯然,IMU計(jì)算的距離較為平滑。
- 計(jì)算旋轉(zhuǎn)角度 旋轉(zhuǎn)角度的計(jì)算較為簡(jiǎn)單,我們只需要根據(jù)IMU獲取到的yaw值就可以計(jì)算(前后兩幀圖像的yaw值相減)
2、畫(huà)出kitti車(chē)的行駛軌跡
prev_imu_data = None locations = [] for frame in range(150): imu_data = read_imu('/home/wsj/data/kitty/RawData/2011_09_26/2011_09_26_drive_0005_sync/oxts/data/%010d.txt'%frame) if prev_imu_data is not None: displacement = 0.1*np.linalg.norm(imu_data[['vf','vl']]) yaw_change = float(imu_data.yaw-prev_imu_data.yaw) for i in range(len(locations)): x0, y0 = locations[i] x1 = x0 * np.cos(yaw_change) + y0 * np.sin(yaw_change) - displacement y1 = -x0 * np.sin(yaw_change) + y0 * np.cos(yaw_change) locations[i] = np.array([x1,y1]) locations += [np.array([0,0])] prev_imu_data =imu_data plt.figure(figsize=(20,10)) plt.plot(np.array(locations)[:, 0],np.array(locations)[:, 1])
3、畫(huà)出所有車(chē)輛的軌跡
class Object(): def __init__(self, center): self.locations = deque(maxlen=20) self.locations.appendleft(center) def update(self, center, displacement, yaw): for i in range(len(self.locations)): x0, y0 = self.locations[i] x1 = x0 * np.cos(yaw_change) + y0 * np.sin(yaw_change) - displacement y1 = -x0 * np.sin(yaw_change) + y0 * np.cos(yaw_change) self.locations[i] = np.array([x1,y1]) if center is not None: self.locations.appendleft(center) def reset(self): self.locations = deque(maxlen=20) #創(chuàng)建發(fā)布者 loc_pub = rospy.Publisher('kitti_loc', MarkerArray, queue_size=10) #獲取距離和旋轉(zhuǎn)角度 imu_data = read_imu('/home/wsj/data/kitty/RawData/2011_09_26/2011_09_26_drive_0005_sync/oxts/data/%010d.txt'%frame) if prev_imu_data is None: for track_id in centers: tracker[track_id] = Object(centers[track_id]) else: displacement = 0.1*np.linalg.norm(imu_data[['vf','vl']]) yaw_change = float(imu_data.yaw - prev_imu_data.yaw) for track_id in centers: # for one frame id if track_id in tracker: tracker[track_id].update(centers[track_id], displacement, yaw_change) else: tracker[track_id] = Object(centers[track_id]) for track_id in tracker:# for whole ids tracked by prev frame,but current frame did not if track_id not in centers: # dont know its center pos tracker[track_id].update(None, displacement, yaw_change) prev_imu_data = imu_data def publish_loc(loc_pub, tracker, centers): marker_array = MarkerArray() for track_id in centers: marker = Marker() marker.header.frame_id = FRAME_ID marker.header.stamp = rospy.Time.now() marker.action = marker.ADD marker.lifetime = rospy.Duration(LIFETIME) marker.type = Marker.LINE_STRIP marker.id = track_id marker.color.r = 1.0 marker.color.g = 1.0 marker.color.b = 0.0 marker.color.a = 1.0 marker.scale.x = 0.2 marker.points = [] for p in tracker[track_id].locations: marker.points.append(Point(p[0], p[1], 0)) marker_array.markers.append(marker) loc_pub.publish(marker_array)
到此這篇關(guān)于Python中使用kitti數(shù)據(jù)集實(shí)現(xiàn)自動(dòng)駕駛——繪制出所有物體的行駛軌跡的文章就介紹到這了,更多相關(guān)kitti數(shù)據(jù)集自動(dòng)駕駛內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python面向?qū)ο笾接袑傩院退接蟹椒☉?yīng)用案例分析
這篇文章主要介紹了Python面向?qū)ο笾接袑傩院退接蟹椒?結(jié)合具體案例形式簡(jiǎn)單分析了面向?qū)ο蟪绦蛟O(shè)計(jì)中私有屬性與私有方法的基本功能與使用注意事項(xiàng),需要的朋友可以參考下2019-12-12Python?ctypes庫(kù)底層交互秘籍實(shí)例探究
ctypes是Python標(biāo)準(zhǔn)庫(kù)中的外部函數(shù)庫(kù),允許Python調(diào)用動(dòng)態(tài)鏈接庫(kù)中的函數(shù),它提供了與C兼容的數(shù)據(jù)類(lèi)型和允許Python調(diào)用共享庫(kù)中的函數(shù),對(duì)系統(tǒng)級(jí)編程和與硬件交互非常有用2024-01-01python socket網(wǎng)絡(luò)編程之粘包問(wèn)題詳解
這篇文章主要介紹了python socket網(wǎng)絡(luò)編程之粘包問(wèn)題詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-04-04Python中使用logging模塊代替print(logging簡(jiǎn)明指南)
這篇文章主要介紹了Python中使用logging模塊代替print的好處說(shuō)明,主旨是logging模塊簡(jiǎn)明指南,logging模塊的使用方法介紹,需要的朋友可以參考下2014-07-07在tensorflow中實(shí)現(xiàn)去除不足一個(gè)batch的數(shù)據(jù)
今天小編就為大家分享一篇在tensorflow中實(shí)現(xiàn)去除不足一個(gè)batch的數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-01-01pyenv與virtualenv安裝實(shí)現(xiàn)python多版本多項(xiàng)目管理
這篇文章主要介紹了pyenv與virtualenv安裝實(shí)現(xiàn)python多版本多項(xiàng)目管理過(guò)程,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08