Mercurial Hosting > traffic-intelligence
annotate python/processing.py @ 848:0cb69238e6f5
corrected load/save prototypes
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 21 Jul 2016 17:51:11 -0400 |
parents | 15e244d2a1b5 |
children | 933670761a57 |
rev | line source |
---|---|
246
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 '''Algorithms to process trajectories and moving objects''' |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
3 |
665
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
246
diff
changeset
|
4 import moving |
246
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
5 |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
6 import numpy as np |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
7 |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
8 |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
9 def extractSpeeds(objects, zone): |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
10 speeds = {} |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
11 objectsNotInZone = [] |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
12 import matplotlib.nxutils as nx |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
13 for o in objects: |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
14 inPolygon = nx.points_inside_poly(o.getPositions().asArray().T, zone.T) |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
15 if inPolygon.any(): |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
16 objspeeds = [o.getVelocityAt(i).norm2() for i in xrange(int(o.length()-1)) if inPolygon[i]] |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
17 speeds[o.num] = np.mean(objspeeds) # km/h |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
18 else: |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
19 objectsNotInZone.append(o) |
583a2c4622f9
created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
20 return speeds.values(), speeds, objectsNotInZone |