Mercurial > hg > nsaunier > traffic-intelligence
comparison c/Feature.cpp @ 129:4742b2b6d851
created basic feature saving code
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 17 Aug 2011 17:14:00 -0400 |
| parents | |
| children | 45c64e68053c |
comparison
equal
deleted
inserted
replaced
| 128:536510f60854 | 129:4742b2b6d851 |
|---|---|
| 1 #include "Feature.hpp" | |
| 2 | |
| 3 #include "opencv2/core/core.hpp" | |
| 4 | |
| 5 using namespace std; | |
| 6 using namespace cv; | |
| 7 | |
| 8 void FeatureTrajectory::addPoint(const int& frameNum, const Point2f& p) { | |
| 9 positions.add(frameNum, p); | |
| 10 computeMotionData(frameNum); | |
| 11 } | |
| 12 | |
| 13 // protected | |
| 14 | |
| 15 void FeatureTrajectory::computeMotionData(const int& frameNum) { | |
| 16 unsigned int nPositions = positions.size(); | |
| 17 if (nPositions >= 3) { | |
| 18 Point2f displacement = positions[nPositions-1] - positions[nPositions-2]; | |
| 19 velocities.add(frameNum, displacement); | |
| 20 float dist = norm(displacement); | |
| 21 displacementDistances.push_back(dist); | |
| 22 } else if (nPositions == 2) { | |
| 23 Point2f displacement = positions[1] - positions[0]; | |
| 24 velocities.add(frameNum-1, displacement); | |
| 25 velocities.add(frameNum, displacement); | |
| 26 float dist = norm(displacement); | |
| 27 displacementDistances.push_back(dist); | |
| 28 displacementDistances.push_back(dist); | |
| 29 } | |
| 30 } |
