Mercurial Hosting > traffic-intelligence
comparison c/Motion.cpp @ 139:47329bd16cc0
cleaned code, added condition on smooth displacement
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 23 Aug 2011 13:14:47 -0400 |
parents | c1b260b48d2a |
children | a3532db00c28 |
comparison
equal
deleted
inserted
replaced
138:c1b260b48d2a | 139:47329bd16cc0 |
---|---|
1 #include "Motion.hpp" | 1 #include "Motion.hpp" |
2 #include "cvutils.hpp" | |
2 | 3 |
3 #include "opencv2/core/core.hpp" | 4 #include "opencv2/core/core.hpp" |
4 #include "opencv2/highgui/highgui.hpp" | 5 #include "opencv2/highgui/highgui.hpp" |
5 | 6 |
6 #include "src/TrajectoryDBAccessList.h" | 7 #include "src/TrajectoryDBAccessList.h" |
22 result = disp < minTotalFeatureDisplacement; | 23 result = disp < minTotalFeatureDisplacement; |
23 } | 24 } |
24 return result; | 25 return result; |
25 } | 26 } |
26 | 27 |
28 bool FeatureTrajectory::motionSmooth(const int& accelerationBound, const int& deviationBound) const { | |
29 bool result = true; | |
30 unsigned int nPositions = positions.size(); | |
31 if (nPositions >= 3) { | |
32 float ratio; | |
33 if (displacementDistances[nPositions-2] > displacementDistances[nPositions-3]) | |
34 ratio = displacementDistances[nPositions-2] / displacementDistances[nPositions-3]; | |
35 else | |
36 ratio = displacementDistances[nPositions-3] / displacementDistances[nPositions-2]; | |
37 | |
38 float cosine = scalarProduct(velocities[nPositions-3],velocities[nPositions-2]) / (displacementDistances[nPositions-3] * displacementDistances[nPositions-2]); | |
39 | |
40 result &= (ratio < accelerationBound) & (cosine > deviationBound); | |
41 } | |
42 return result; | |
43 } | |
44 | |
27 void FeatureTrajectory::addPoint(const int& frameNum, const Point2f& p) { | 45 void FeatureTrajectory::addPoint(const int& frameNum, const Point2f& p) { |
28 positions.add(frameNum, p); | 46 positions.add(frameNum, p); |
29 computeMotionData(frameNum); | 47 computeMotionData(frameNum); |
48 assert(positions.size() == displacementDistances.size()+1); | |
49 assert(positions.size() == velocities.size()+1); | |
30 } | 50 } |
31 | 51 |
32 void FeatureTrajectory::shorten(void) { | 52 void FeatureTrajectory::shorten(void) { |
33 positions.pop_back(); | 53 positions.pop_back(); |
34 velocities.pop_back(); | 54 velocities.pop_back(); |
54 | 74 |
55 // protected | 75 // protected |
56 | 76 |
57 void FeatureTrajectory::computeMotionData(const int& frameNum) { | 77 void FeatureTrajectory::computeMotionData(const int& frameNum) { |
58 unsigned int nPositions = positions.size(); | 78 unsigned int nPositions = positions.size(); |
59 if (nPositions >= 3) { | 79 if (nPositions >= 2) { |
60 Point2f displacement = positions[nPositions-1] - positions[nPositions-2]; | 80 Point2f displacement = positions[nPositions-1] - positions[nPositions-2]; |
61 if (nPositions == 2) // duplicate first displacement so that positions and velocities have the same length | 81 //if (nPositions == 2) // duplicate first displacement so that positions and velocities have the same length |
62 velocities.add(frameNum-1, displacement); | 82 //velocities.add(frameNum-1, displacement); |
63 velocities.add(frameNum, displacement); | 83 velocities.add(frameNum, displacement); |
64 float dist = norm(displacement); | 84 float dist = norm(displacement); |
65 displacementDistances.push_back(dist); | 85 displacementDistances.push_back(dist); |
66 } | 86 } |
67 } | 87 } |