Mercurial > hg > nsaunier > traffic-intelligence
comparison c/Motion.cpp @ 804:17e54690af8a dev
work in progress, not fully functional yet
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 01 Jun 2016 17:57:49 -0400 |
| parents | 6022350f8173 |
| children |
comparison
equal
deleted
inserted
replaced
| 803:f7cf43b5ad3b | 804:17e54690af8a |
|---|---|
| 20 using namespace cv; | 20 using namespace cv; |
| 21 using namespace boost; | 21 using namespace boost; |
| 22 | 22 |
| 23 /******************** FeatureTrajectory ********************/ | 23 /******************** FeatureTrajectory ********************/ |
| 24 | 24 |
| 25 FeatureTrajectory::FeatureTrajectory(const unsigned int& frameNum, const cv::Point2f& p, const Mat& homography) | 25 FeatureTrajectory::FeatureTrajectory(const unsigned int& frameNum, const cv::Point2f& p) |
| 26 : firstInstant(frameNum), lastInstant(frameNum) { | 26 : firstInstant(frameNum), lastInstant(frameNum) { |
| 27 positions = TrajectoryPoint2fPtr(new TrajectoryPoint2f()); | 27 positions = TrajectoryPoint2fPtr(new TrajectoryPoint2f()); |
| 28 velocities = TrajectoryPoint2fPtr(new TrajectoryPoint2f()); | 28 velocities = TrajectoryPoint2fPtr(new TrajectoryPoint2f()); |
| 29 addPoint(frameNum, p, homography); | 29 addPoint(frameNum, p); |
| 30 } | 30 } |
| 31 | 31 |
| 32 FeatureTrajectory::FeatureTrajectory(TrajectoryPoint2fPtr& _positions, TrajectoryPoint2fPtr& _velocities) { | 32 FeatureTrajectory::FeatureTrajectory(TrajectoryPoint2fPtr& _positions, TrajectoryPoint2fPtr& _velocities) { |
| 33 positions = _positions; | 33 positions = _positions; |
| 34 velocities = _velocities; | 34 velocities = _velocities; |
| 91 } | 91 } |
| 92 | 92 |
| 93 return connected; | 93 return connected; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void FeatureTrajectory::addPoint(const unsigned int& frameNum, const Point2f& p, const Mat& homography) { | 96 void FeatureTrajectory::addPoint(const unsigned int& frameNum, const Point2f& p) { |
| 97 Point2f pp = p; | 97 positions->add(frameNum, p); |
| 98 if (!homography.empty()) | |
| 99 pp = project(p, homography); | |
| 100 positions->add(frameNum, pp); | |
| 101 if (frameNum < firstInstant) | 98 if (frameNum < firstInstant) |
| 102 firstInstant = frameNum; | 99 firstInstant = frameNum; |
| 103 if (frameNum > lastInstant) | 100 if (frameNum > lastInstant) |
| 104 lastInstant = frameNum; | 101 lastInstant = frameNum; |
| 105 computeMotionData(frameNum); | 102 computeMotionData(frameNum); |
| 126 #ifdef USE_OPENCV | 123 #ifdef USE_OPENCV |
| 127 /// \todo add option for anti-aliased drawing, thickness | 124 /// \todo add option for anti-aliased drawing, thickness |
| 128 void FeatureTrajectory::draw(Mat& img, const Mat& homography, const Scalar& color) const { | 125 void FeatureTrajectory::draw(Mat& img, const Mat& homography, const Scalar& color) const { |
| 129 Point2f p1, p2; | 126 Point2f p1, p2; |
| 130 if (!homography.empty()) | 127 if (!homography.empty()) |
| 131 p1 = project((*positions)[0], homography); | 128 p1 = project<double>((*positions)[0], homography); |
| 132 else | 129 else |
| 133 p1 = (*positions)[0]; | 130 p1 = (*positions)[0]; |
| 134 for (unsigned int i=1; i<positions->size(); i++) { | 131 for (unsigned int i=1; i<positions->size(); i++) { |
| 135 if (!homography.empty()) | 132 if (!homography.empty()) |
| 136 p2 = project((*positions)[i], homography); | 133 p2 = project<double>((*positions)[i], homography); |
| 137 else | 134 else |
| 138 p2 = (*positions)[i]; | 135 p2 = (*positions)[i]; |
| 139 line(img, p1, p2, color, 1); | 136 line(img, p1, p2, color, 1); |
| 140 p1 = p2; | 137 p1 = p2; |
| 141 } | 138 } |
