Mercurial > hg > nsaunier > traffic-intelligence
comparison python/ubc_utils.py @ 52:441c8387f34f
changed type detection to load trajectories
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 12 Oct 2010 18:24:11 -0400 |
| parents | 3aed17fc468d |
| children | 0a5bdbf0d1b4 |
comparison
equal
deleted
inserted
replaced
| 51:3aed17fc468d | 52:441c8387f34f |
|---|---|
| 10 'pedestrian', | 10 'pedestrian', |
| 11 'twowheels', | 11 'twowheels', |
| 12 'bus' | 12 'bus' |
| 13 'truck'] | 13 'truck'] |
| 14 | 14 |
| 15 fileTypeNames = ['feature', | |
| 16 'object', | |
| 17 'prototype', | |
| 18 'contoursequence'] | |
| 19 | |
| 15 def getFileType(s): | 20 def getFileType(s): |
| 16 filePrefix = utils.removeExtension(s) | 21 'Finds the type in fileTypeNames' |
| 17 i = filePrefix.rfind('-') | 22 for fileType in fileTypeNames: |
| 18 if i>0: | 23 if s.find(fileType)>0: |
| 19 return filePrefix[i+1:] | 24 return fileType |
| 20 else: | 25 return '' |
| 21 return '' | 26 |
| 27 def isFileType(s, fileType): | |
| 28 return (s.find(fileType)>0) | |
| 22 | 29 |
| 23 def saveTrajectoryUserTypes(inFilename, outFilename, objects): | 30 def saveTrajectoryUserTypes(inFilename, outFilename, objects): |
| 24 '''The program saves the objects, | 31 '''The program saves the objects, |
| 25 by just copying the corresponding trajectory and velocity data | 32 by just copying the corresponding trajectory and velocity data |
| 26 from the inFilename, and saving the characteristics in objects (first line) | 33 from the inFilename, and saving the characteristics in objects (first line) |
| 68 #add = True | 75 #add = True |
| 69 if len(lines) >= 3: | 76 if len(lines) >= 3: |
| 70 obj.positions = Trajectory.load(lines[1], lines[2]) | 77 obj.positions = Trajectory.load(lines[1], lines[2]) |
| 71 if len(lines) >= 5: | 78 if len(lines) >= 5: |
| 72 obj.velocities = Trajectory.load(lines[3], lines[4]) | 79 obj.velocities = Trajectory.load(lines[3], lines[4]) |
| 73 if objectType == 'objects': | 80 if objectType == 'object': |
| 74 obj.userType = parsedLine[3] | 81 obj.userType = parsedLine[3] |
| 75 obj.nObjects = float(l[4]) | 82 obj.nObjects = float(l[4]) |
| 76 obj.featureNumbers = [int(n) for n in l[5:]] | 83 obj.featureNumbers = [int(n) for n in l[5:]] |
| 77 | 84 |
| 78 # load contour data if available | 85 # load contour data if available |
| 79 if len(lines) >= 6: | 86 if len(lines) >= 6: |
| 80 obj.contourType = utils.line2Floats(lines[6]) | 87 obj.contourType = utils.line2Floats(lines[6]) |
| 81 obj.contourOrigins = Trajectory.load(lines[7], lines[8]) | 88 obj.contourOrigins = Trajectory.load(lines[7], lines[8]) |
| 82 obj.contourSizes = Trajectory.load(lines[9], lines[10]) | 89 obj.contourSizes = Trajectory.load(lines[9], lines[10]) |
| 83 elif objectType == 'prototypes': | 90 elif objectType == 'prototype': |
| 84 obj.userType = parsedLine[3] | 91 obj.userType = parsedLine[3] |
| 85 obj.nMatchings = int(l[4]) | 92 obj.nMatchings = int(l[4]) |
| 86 | 93 |
| 87 if len(lines) != 2: | 94 if len(lines) != 2: |
| 88 objects.append(obj) | 95 objects.append(obj) |
