comparison c/Motion.cpp @ 147:0089fb29cd26

added projection of points and reprojection for display
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 30 Aug 2011 13:38:31 -0400
parents a3532db00c28
children cde87a07eb58
comparison
equal deleted inserted replaced
146:7150427c665e 147:0089fb29cd26
7 #include "src/TrajectoryDBAccessList.h" 7 #include "src/TrajectoryDBAccessList.h"
8 8
9 using namespace std; 9 using namespace std;
10 using namespace cv; 10 using namespace cv;
11 11
12 FeatureTrajectory::FeatureTrajectory(const int& frameNum, const cv::Point2f& p) { 12 FeatureTrajectory::FeatureTrajectory(const int& frameNum, const cv::Point2f& p, const Mat& homography) {
13 addPoint(frameNum, p); 13 addPoint(frameNum, p, homography);
14 } 14 }
15 15
16 bool FeatureTrajectory::smallDisplacement(const unsigned int& nDisplacements, const float& minTotalFeatureDisplacement) const { 16 bool FeatureTrajectory::smallDisplacement(const unsigned int& nDisplacements, const float& minTotalFeatureDisplacement) const {
17 bool result = false; 17 bool result = false;
18 unsigned int nPositions = positions.size(); 18 unsigned int nPositions = positions.size();
40 result &= (ratio < accelerationBound) & (cosine > deviationBound); 40 result &= (ratio < accelerationBound) & (cosine > deviationBound);
41 } 41 }
42 return result; 42 return result;
43 } 43 }
44 44
45 void FeatureTrajectory::addPoint(const int& frameNum, const Point2f& p) { 45 void FeatureTrajectory::addPoint(const int& frameNum, const Point2f& p, const Mat& homography) {
46 positions.add(frameNum, p); 46 Point2f pp = p;
47 if (!homography.empty())
48 pp = project(p, homography);
49 positions.add(frameNum, pp);
47 computeMotionData(frameNum); 50 computeMotionData(frameNum);
48 assert(positions.size() == displacementDistances.size()+1); 51 assert(positions.size() == displacementDistances.size()+1);
49 assert(positions.size() == velocities.size()+1); 52 assert(positions.size() == velocities.size()+1);
50 } 53 }
51 54
60 trajectoryDB.write(velocities, velocitiesTableName); 63 trajectoryDB.write(velocities, velocitiesTableName);
61 } 64 }
62 65
63 #ifdef USE_OPENCV 66 #ifdef USE_OPENCV
64 /// \todo add option for anti-aliased drawing, thickness 67 /// \todo add option for anti-aliased drawing, thickness
65 void FeatureTrajectory::draw(Mat& img, const Scalar& color) const { 68 void FeatureTrajectory::draw(Mat& img, const Mat& homography, const Scalar& color) const {
66 Point2f p1 = positions[0]; 69 Point2f p1, p2;
70 if (!homography.empty())
71 p1 = project(positions[0], homography);
72 else
73 p1 = positions[0];
67 for (unsigned int i=1; i<positions.size(); i++) { 74 for (unsigned int i=1; i<positions.size(); i++) {
68 Point2f p2 = positions[i]; 75 if (!homography.empty())
76 p2 = project(positions[i], homography);
77 else
78 p2 = positions[i];
69 line(img, p1, p2, color, 1); 79 line(img, p1, p2, color, 1);
70 p1 = p2; 80 p1 = p2;
71 } 81 }
72 } 82 }
73 #endif 83 #endif