Mercurial Hosting > traffic-intelligence
changeset 140:8de5e8256224
added function to save vectors of features
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 23 Aug 2011 19:04:41 -0400 |
parents | 47329bd16cc0 |
children | 6f10a227486c |
files | c/feature-based-tracking.cpp |
diffstat | 1 files changed, 12 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/c/feature-based-tracking.cpp Tue Aug 23 13:14:47 2011 -0400 +++ b/c/feature-based-tracking.cpp Tue Aug 23 19:04:41 2011 -0400 @@ -52,6 +52,13 @@ feature(_feature), pointNum(_pointNum) {} }; +inline void saveFeatures(vector<FeatureTrajectoryPtr>& features, TrajectoryDBAccess<Point2f>& db, const unsigned int& minNFeatures = 0) { + if (features.size() >= minNFeatures) { + BOOST_FOREACH(FeatureTrajectoryPtr f, features) f->write(db); + features.clear(); + } +} + int main(int argc, char *argv[]) { // BriefDescriptorExtractor brief(32); // const int DESIRED_FTRS = 500; @@ -110,7 +117,7 @@ // } // database - TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessList<Point2f>(); + boost::shared_ptr<TrajectoryDBAccess<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccess<Point2f> >(new TrajectoryDBAccessList<Point2f>()); //TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>(); trajectoryDB->connect(params.databaseFilename.c_str()); trajectoryDB->createTable(); @@ -121,7 +128,7 @@ vector<float> errors; Mat prevDesc, currDesc; - vector<FeatureTrajectoryPtr> features; + vector<FeatureTrajectoryPtr> lostFeatures; vector<FeaturePointMatch> featurePointMatches; int key = '?'; @@ -162,7 +169,8 @@ iter->feature->setId(savedFeatureId); savedFeatureId++; /// \todo smoothing - iter->feature->write(*trajectoryDB); + //iter->feature->write(*trajectoryDB); + lostFeatures.push_back(iter->feature); } iter = featurePointMatches.erase(iter); } else { @@ -173,6 +181,7 @@ } currPts = trackedPts; assert(currPts.size() == featurePointMatches.size()); + saveFeatures(lostFeatures, *trajectoryDB); if (params.display) { BOOST_FOREACH(FeaturePointMatch fp, featurePointMatches) @@ -195,7 +204,6 @@ goodFeaturesToTrack(currentFrameBW, newPts, params.maxNFeatures, params.featureQuality, params.minFeatureDistanceKLT, featureMask, params.windowSize, params.useHarrisDetector, params.k); BOOST_FOREACH(Point2f p, newPts) { //for (unsigned int i=0; i<newPts.size(); i++) { FeatureTrajectoryPtr f = FeatureTrajectoryPtr(new FeatureTrajectory(frameNum, p)); - //features.push_back(f); featurePointMatches.push_back(FeaturePointMatch(f, currPts.size())); currPts.push_back(p); }