Mercurial Hosting > traffic-intelligence
changeset 177:ae2286b1a3fd
added loading FeatureTrajectory from database, printing
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sun, 30 Oct 2011 11:25:51 -0400 |
parents | 9323427aa0a3 |
children | d7df8ecf5ccd |
files | c/Motion.cpp c/feature-based-tracking.cpp include/Motion.hpp |
diffstat | 3 files changed, 38 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/c/Motion.cpp Thu Oct 27 13:56:46 2011 -0400 +++ b/c/Motion.cpp Sun Oct 30 11:25:51 2011 -0400 @@ -18,6 +18,21 @@ addPoint(frameNum, p, homography); } +FeatureTrajectory::FeatureTrajectory(TrajectoryPoint2fPtr& _positions, TrajectoryPoint2fPtr& _velocities) + : lost(false) { + positions = _positions; + velocities = _velocities; +} + +FeatureTrajectory::FeatureTrajectory(const int& id, TrajectoryDBAccessList<Point2f>& trajectoryDB, const string& positionsTableName, const string& velocitiesTableName) { + bool success = trajectoryDB.read(positions, id, positionsTableName); + if (!success) + cout << "problem loading positions" << endl; + success = trajectoryDB.read(velocities, id, velocitiesTableName); + if (!success) + cout << "problem loading velocities" << endl; +} + bool FeatureTrajectory::isDisplacementSmall(const unsigned int& nDisplacements, const float& minTotalFeatureDisplacement) const { bool result = false; unsigned int nPositions = positions->size();
--- a/c/feature-based-tracking.cpp Thu Oct 27 13:56:46 2011 -0400 +++ b/c/feature-based-tracking.cpp Sun Oct 30 11:25:51 2011 -0400 @@ -278,9 +278,10 @@ cout << trajectoryIds.size() << " trajectories " << endl; BOOST_FOREACH(int trajectoryId, trajectoryIds) { //cout << trajectoryId << " " << endl; - boost::shared_ptr<Trajectory<cv::Point2f> > trajectory; - success = trajectoryDB->read(trajectory, trajectoryId, "positions"); // velocities - //stringstream ss;ss << *trajectory; cout << ss.str() << endl; + // boost::shared_ptr<Trajectory<cv::Point2f> > trajectory; + // success = trajectoryDB->read(trajectory, trajectoryId, "positions"); // velocities + FeatureTrajectoryPtr ft = FeatureTrajectoryPtr(new FeatureTrajectory(trajectoryId, *trajectoryDB, "positions", "velocities")); + stringstream ss;ss << *ft; cout << ss.str() << endl; } // should the trajectory be loaded one by one? yes
--- a/include/Motion.hpp Thu Oct 27 13:56:46 2011 -0400 +++ b/include/Motion.hpp Sun Oct 30 11:25:51 2011 -0400 @@ -1,5 +1,5 @@ -#ifndef FEATURE_HPP -#define FEATURE_HPP +#ifndef MOTION_HPP +#define MOTION_HPP #include "src/Trajectory.h" @@ -7,6 +7,7 @@ #include <boost/graph/adjacency_list.hpp> template<typename T> class TrajectoryDBAccess; +template<typename T> class TrajectoryDBAccessList; typedef boost::shared_ptr<TrajectoryPoint2f> TrajectoryPoint2fPtr; @@ -17,6 +18,12 @@ public: FeatureTrajectory(const int& frameNum, const cv::Point2f& p, const cv::Mat& homography); + FeatureTrajectory(TrajectoryPoint2fPtr& _positions, TrajectoryPoint2fPtr& _velocities); + + /** loads from database + can be made generic for different list and blob */ + FeatureTrajectory(const int& id, TrajectoryDBAccessList<cv::Point2f>& trajectoryDB, const std::string& positionsTableName, const std::string& velocitiesTableName); + unsigned int length(void) const { return positions->size();} void setId(const unsigned int& id) { positions->setId(id);velocities->setId(id);} @@ -40,6 +47,8 @@ void draw(cv::Mat& img, const cv::Mat& homography, const cv::Scalar& color) const; #endif + friend std::stringstream& operator<<(std::stringstream& out, const FeatureTrajectory& ft); + protected: bool lost; TrajectoryPoint2fPtr positions; @@ -51,11 +60,18 @@ std::vector<float> displacementDistances; void computeMotionData(const int& frameNum); - }; typedef boost::shared_ptr<FeatureTrajectory> FeatureTrajectoryPtr; +// inlined +inline std::stringstream& operator<<(std::stringstream& out, const FeatureTrajectory& ft) { + out << *(ft.positions); + out << "\n"; + out << *(ft.velocities); + return out; +} + // class MovingObject {} // roadUserType, group of features