Mercurial > hg > nsaunier > traffic-intelligence
annotate python/tests/moving.txt @ 510:b0dac840c24f
compute homography works with undistortion
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 23 May 2014 17:33:11 -0400 |
| parents | cd342a774806 |
| children | a40c75f04903 |
| rev | line source |
|---|---|
|
43
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
1 >>> from moving import * |
|
92
a5ef9e40688e
makes use of matplotlib function to test if point is in a polygon
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
91
diff
changeset
|
2 >>> import numpy as np |
|
43
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
3 |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
4 >>> Interval().empty() |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
5 True |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
6 >>> Interval(0,1).empty() |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
7 False |
|
104
13187af8622d
finally added the representation of intervals
Nicolas Saunier <nico@confins.net>
parents:
96
diff
changeset
|
8 >>> Interval(0,1) |
|
13187af8622d
finally added the representation of intervals
Nicolas Saunier <nico@confins.net>
parents:
96
diff
changeset
|
9 [0, 1] |
|
43
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
10 >>> Interval(0,1).length() |
|
91
daa05fae1a70
modified the type of the result of interval lengths to float, added comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
79
diff
changeset
|
11 1.0 |
|
43
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
12 >>> Interval(23.2,24.9).length() |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
13 1.6999999999999993 |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
14 >>> Interval(10,8).length() |
|
91
daa05fae1a70
modified the type of the result of interval lengths to float, added comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
79
diff
changeset
|
15 0.0 |
|
43
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
16 |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
17 >>> TimeInterval(0,1).length() |
|
91
daa05fae1a70
modified the type of the result of interval lengths to float, added comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
79
diff
changeset
|
18 2.0 |
|
43
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
19 >>> TimeInterval(10,8).length() |
|
91
daa05fae1a70
modified the type of the result of interval lengths to float, added comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
79
diff
changeset
|
20 0.0 |
|
43
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
21 |
|
107
916678481896
corrected bug for TimeInterval interation and added corresponding test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
104
diff
changeset
|
22 >>> [i for i in TimeInterval(9,13)] |
|
916678481896
corrected bug for TimeInterval interation and added corresponding test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
104
diff
changeset
|
23 [9, 10, 11, 12, 13] |
|
916678481896
corrected bug for TimeInterval interation and added corresponding test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
104
diff
changeset
|
24 |
|
96
9928c2fa72cc
added equal method to intervals
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
92
diff
changeset
|
25 >>> TimeInterval(2,5).equal(TimeInterval(2,5)) |
|
9928c2fa72cc
added equal method to intervals
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
92
diff
changeset
|
26 True |
|
9928c2fa72cc
added equal method to intervals
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
92
diff
changeset
|
27 >>> TimeInterval(2,5).equal(TimeInterval(2,4)) |
|
9928c2fa72cc
added equal method to intervals
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
92
diff
changeset
|
28 False |
|
9928c2fa72cc
added equal method to intervals
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
92
diff
changeset
|
29 >>> TimeInterval(2,5).equal(TimeInterval(5,2)) |
|
9928c2fa72cc
added equal method to intervals
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
92
diff
changeset
|
30 False |
|
9928c2fa72cc
added equal method to intervals
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
92
diff
changeset
|
31 |
|
248
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
32 >>> TimeInterval(3,6).distance(TimeInterval(4,6)) |
|
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
33 0 |
|
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
34 >>> TimeInterval(3,6).distance(TimeInterval(6,10)) |
|
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
35 0 |
|
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
36 >>> TimeInterval(3,6).distance(TimeInterval(8,10)) |
|
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
37 2 |
|
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
38 >>> TimeInterval(20,30).distance(TimeInterval(3,15)) |
|
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
39 5 |
|
249
99173da7afae
corrected small bugs and typos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
248
diff
changeset
|
40 >>> unionIntervals([TimeInterval(3,6), TimeInterval(8,10),TimeInterval(11,15)]) |
|
99173da7afae
corrected small bugs and typos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
248
diff
changeset
|
41 [3, 15] |
|
248
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
42 |
|
43
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
43 >>> Point(3,4)-Point(1,7) |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
44 (2.000000,-3.000000) |
|
451
cd342a774806
Point/CurvilinearTrajectory/Interaction utiles
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
372
diff
changeset
|
45 >>> -Point(1,2) |
|
cd342a774806
Point/CurvilinearTrajectory/Interaction utiles
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
372
diff
changeset
|
46 (-1.000000,-2.000000) |
|
43
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
47 |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
48 >>> Point(3,2).norm2Squared() |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
49 13 |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
50 |
|
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
51 >>> Point.distanceNorm2(Point(3,4),Point(1,7)) |
|
248
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
52 3.605551275463989 |
|
43
6d11d9e7ad4e
methods for trajectories and objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
53 |
|
372
349eb1e09f45
Cleaned the methods/functions indicating if a point is in a polygon
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
369
diff
changeset
|
54 >>> Point(3,2).inPolygonNoShapely(np.array([[0,0],[1,0],[1,1],[0,1]])) |
|
79
5d487f183fe2
added method to test points in polygons and tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
69
diff
changeset
|
55 False |
|
372
349eb1e09f45
Cleaned the methods/functions indicating if a point is in a polygon
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
369
diff
changeset
|
56 >>> Point(3,2).inPolygonNoShapely(np.array([[0,0],[4,0],[4,3],[0,3]])) |
|
79
5d487f183fe2
added method to test points in polygons and tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
69
diff
changeset
|
57 True |
|
5d487f183fe2
added method to test points in polygons and tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
69
diff
changeset
|
58 |
|
255
13ec22bec5d4
corrected typos and bugs and added a test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
249
diff
changeset
|
59 >>> predictPositionNoLimit(10, Point(0,0), Point(1,1)) # doctest:+ELLIPSIS |
|
13ec22bec5d4
corrected typos and bugs and added a test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
249
diff
changeset
|
60 ((1.0...,1.0...), (10.0...,10.0...)) |
|
249
99173da7afae
corrected small bugs and typos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
248
diff
changeset
|
61 |
|
152
74b1fc68d4df
re-organized code to avoid cyclic python module dependencies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
113
diff
changeset
|
62 >>> segmentIntersection(Point(0,0),Point(1,1), Point(0,1), Point(1,2)) |
|
74b1fc68d4df
re-organized code to avoid cyclic python module dependencies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
113
diff
changeset
|
63 >>> segmentIntersection(Point(0,1),Point(1,0), Point(0,2), Point(2,1)) |
|
74b1fc68d4df
re-organized code to avoid cyclic python module dependencies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
113
diff
changeset
|
64 >>> segmentIntersection(Point(0,0),Point(2,0), Point(1,-1),Point(1,1)) |
|
74b1fc68d4df
re-organized code to avoid cyclic python module dependencies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
113
diff
changeset
|
65 (1.000000,0.000000) |
|
74b1fc68d4df
re-organized code to avoid cyclic python module dependencies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
113
diff
changeset
|
66 >>> segmentIntersection(Point(0,1),Point(2,0),Point(1,1),Point(1,2)) |
|
74b1fc68d4df
re-organized code to avoid cyclic python module dependencies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
113
diff
changeset
|
67 |
|
113
606010d1d9a4
corrected errors in trajectories (if empty) and getTrajectoryInPolygon
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
107
diff
changeset
|
68 >>> Trajectory().length() |
|
606010d1d9a4
corrected errors in trajectories (if empty) and getTrajectoryInPolygon
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
107
diff
changeset
|
69 0 |
|
69
cc192d0450b3
added full support for two implementations of indicators, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
43
diff
changeset
|
70 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]]) |
|
91
daa05fae1a70
modified the type of the result of interval lengths to float, added comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
79
diff
changeset
|
71 >>> t1.length() == 3. |
|
daa05fae1a70
modified the type of the result of interval lengths to float, added comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
79
diff
changeset
|
72 True |
|
69
cc192d0450b3
added full support for two implementations of indicators, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
43
diff
changeset
|
73 >>> t1[1] |
|
cc192d0450b3
added full support for two implementations of indicators, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
43
diff
changeset
|
74 (1.500000,3.500000) |
|
372
349eb1e09f45
Cleaned the methods/functions indicating if a point is in a polygon
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
369
diff
changeset
|
75 >>> t1.getTrajectoryInPolygonNoShapely(np.array([[0,0],[4,0],[4,3],[0,3]])) |
|
79
5d487f183fe2
added method to test points in polygons and tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
69
diff
changeset
|
76 (0.500000,0.500000) |
|
372
349eb1e09f45
Cleaned the methods/functions indicating if a point is in a polygon
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
369
diff
changeset
|
77 >>> t1.getTrajectoryInPolygonNoShapely(np.array([[10,10],[14,10],[14,13],[10,13]])).length() |
|
113
606010d1d9a4
corrected errors in trajectories (if empty) and getTrajectoryInPolygon
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
107
diff
changeset
|
78 0 |
|
284
f2cf16ad798f
added LCSS for trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
79 |
|
369
027e254f0b53
lcss subclass for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
345
diff
changeset
|
80 >>> from utils import LCSS |
|
027e254f0b53
lcss subclass for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
345
diff
changeset
|
81 >>> lcss = LCSS(lambda x,y: Point.distanceNorm2(x,y) <= 0.1) |
|
027e254f0b53
lcss subclass for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
345
diff
changeset
|
82 >>> Trajectory.lcss(t1, t1, lcss) |
|
284
f2cf16ad798f
added LCSS for trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
83 3 |
|
369
027e254f0b53
lcss subclass for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
345
diff
changeset
|
84 >>> lcss = LCSS(lambda p1, p2: (p1-p2).normMax() <= 0.1) |
|
027e254f0b53
lcss subclass for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
345
diff
changeset
|
85 >>> Trajectory.lcss(t1, t1, lcss) |
|
284
f2cf16ad798f
added LCSS for trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
86 3 |
|
345
fa64b2e3a64f
added simple classification based on speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
284
diff
changeset
|
87 |
|
fa64b2e3a64f
added simple classification based on speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
284
diff
changeset
|
88 >>> o1 = MovingObject(positions = Trajectory([[0]*3,[2]*3]), velocities = Trajectory([[0]*3,[1]*3])) |
|
fa64b2e3a64f
added simple classification based on speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
284
diff
changeset
|
89 >>> o1.classifyUserTypeSpeed(0.5, np.median) |
|
fa64b2e3a64f
added simple classification based on speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
284
diff
changeset
|
90 >>> userTypeNames[o1.getUserType()] |
|
fa64b2e3a64f
added simple classification based on speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
284
diff
changeset
|
91 'car' |
|
fa64b2e3a64f
added simple classification based on speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
284
diff
changeset
|
92 >>> o1.classifyUserTypeSpeed(0.5, np.mean) |
|
fa64b2e3a64f
added simple classification based on speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
284
diff
changeset
|
93 >>> userTypeNames[o1.getUserType()] |
|
fa64b2e3a64f
added simple classification based on speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
284
diff
changeset
|
94 'car' |
|
fa64b2e3a64f
added simple classification based on speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
284
diff
changeset
|
95 >>> o1.classifyUserTypeSpeed(1.5, np.median) |
|
fa64b2e3a64f
added simple classification based on speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
284
diff
changeset
|
96 >>> userTypeNames[o1.getUserType()] |
|
fa64b2e3a64f
added simple classification based on speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
284
diff
changeset
|
97 'pedestrian' |
