Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/storage.py @ 1251:2b1c8fe8f7e4
added function for KITTI 2D format (just a simple csv-like format with xy coordinates)
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 15 Mar 2024 17:05:54 -0400 |
| parents | 77fbd0e2ba7d |
| children | ef68d4ba7dae |
comparison
equal
deleted
inserted
replaced
| 1250:77fbd0e2ba7d | 1251:2b1c8fe8f7e4 |
|---|---|
| 1345 interval = moving.TimeInterval(int(tmp.frame.min()), int(tmp.frame.max())) | 1345 interval = moving.TimeInterval(int(tmp.frame.min()), int(tmp.frame.max())) |
| 1346 userType = tmp.iloc[0].usertype | 1346 userType = tmp.iloc[0].usertype |
| 1347 if len(tmp) != interval.length(): #interpolate | 1347 if len(tmp) != interval.length(): #interpolate |
| 1348 print(objNum, len(tmp), interval.length()) | 1348 print(objNum, len(tmp), interval.length()) |
| 1349 instants = set(interval).difference(tmp.frame) | 1349 instants = set(interval).difference(tmp.frame) |
| 1350 tmp = concat([tmp, DataFrame([[t, objNum, userType]+[NaN]*(len(header)-3) for t in instants], columns = header)], ignore_index=True).sort_values('frame') | 1350 missing = concat([tmp[header[10:]], DataFrame([[t]+[NaN]*(len(header)-10) for t in instants], columns = ['frame']+header[10:])], ignore_index=True).sort_values('frame') |
| 1351 tmp.interpolate(inplace=True) | 1351 tmp = missing.interpolate() |
| 1352 featureTrajectories = [moving.Trajectory() for i in range(4)] | 1352 featureTrajectories = [moving.Trajectory() for i in range(4)] |
| 1353 for i, r in tmp.iterrows(): | 1353 for i, r in tmp.iterrows(): |
| 1354 _, Tr_imu_to_world = oxts[r.frame] | 1354 _, Tr_imu_to_world = oxts[r.frame] |
| 1355 # transfer_matrix = {'P2': reshape(kittiCalibration['P2'], (3, 4)), | 1355 # transfer_matrix = {'P2': reshape(kittiCalibration['P2'], (3, 4)), |
| 1356 # 'R_rect': kittiCalibration['R_rect'], | 1356 # 'R_rect': kittiCalibration['R_rect'], |
| 1437 newObj = moving.MovingObject(num = objNum+1, timeInterval = interval, positions = t, velocities = t.differentiate(True), userType = 'Car', features = [moving.MovingObject(num = featureNum+i, timeInterval = copy(interval), positions = featureTrajectories[i], velocities = featureTrajectories[i].differentiate(True)) for i in range(4)]) | 1437 newObj = moving.MovingObject(num = objNum+1, timeInterval = interval, positions = t, velocities = t.differentiate(True), userType = 'Car', features = [moving.MovingObject(num = featureNum+i, timeInterval = copy(interval), positions = featureTrajectories[i], velocities = featureTrajectories[i].differentiate(True)) for i in range(4)]) |
| 1438 objects.append(newObj) | 1438 objects.append(newObj) |
| 1439 | 1439 |
| 1440 return objects | 1440 return objects |
| 1441 | 1441 |
| 1442 def loadTrajectoriesFromKITTI2D(filename): | |
| 1443 '''Loads x,y coordinate series | |
| 1444 e.g. obtained by projecting from image to ground world plane using a homography | |
| 1445 Format: frame_id,track_id,usertype,x,y,score ''' | |
| 1446 | |
| 1447 header = ['frame','trackingid','usertype','x','y','score'] | |
| 1448 data = read_csv(filename, delimiter=' ', names = header) | |
| 1449 objects = [] | |
| 1450 for objNum in data.trackingid.unique(): | |
| 1451 tmp = data[data.trackingid == objNum].sort_values('frame') | |
| 1452 interval = moving.TimeInterval(int(tmp.frame.min()), int(tmp.frame.max())) | |
| 1453 userType = tmp.iloc[0].usertype | |
| 1454 if len(tmp) != interval.length(): #interpolate | |
| 1455 print(objNum, len(tmp), interval.length()) | |
| 1456 instants = set(interval).difference(tmp.frame) | |
| 1457 missing = concat([tmp[['frame', 'x', 'y']], DataFrame([[t, NaN, NaN] for t in instants], columns = ['frame', 'x', 'y'])], ignore_index=True).sort_values('frame') | |
| 1458 tmp = missing.interpolate() | |
| 1459 #print(tmp.info()) | |
| 1460 if interval.length()>1: | |
| 1461 t = moving.Trajectory([tmp.x.to_list(), tmp.y.to_list()]) | |
| 1462 newObj = moving.MovingObject(num = objNum, timeInterval = interval, positions = t, velocities = t.differentiate(True), userType = userType) | |
| 1463 objects.append(newObj) | |
| 1464 | |
| 1465 return objects | |
| 1466 | |
| 1442 def convertNgsimFile(inputfile, outputfile, append = False, nObjects = -1, sequenceNum = 0): | 1467 def convertNgsimFile(inputfile, outputfile, append = False, nObjects = -1, sequenceNum = 0): |
| 1443 '''Reads data from the trajectory data provided by NGSIM project | 1468 '''Reads data from the trajectory data provided by NGSIM project |
| 1444 and converts to our current format.''' | 1469 and converts to our current format.''' |
| 1445 if append: | 1470 if append: |
| 1446 out = utils.openCheck(outputfile,'a') | 1471 out = utils.openCheck(outputfile,'a') |
