comparison c/feature-based-tracking.cpp @ 142:a3532db00c28

added code to write velocities
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 24 Aug 2011 02:12:06 -0400
parents 6f10a227486c
children b32947b002da
comparison
equal deleted inserted replaced
141:6f10a227486c 142:a3532db00c28
50 50
51 FeaturePointMatch(FeatureTrajectoryPtr _feature, const int& _pointNum): 51 FeaturePointMatch(FeatureTrajectoryPtr _feature, const int& _pointNum):
52 feature(_feature), pointNum(_pointNum) {} 52 feature(_feature), pointNum(_pointNum) {}
53 }; 53 };
54 54
55 inline void saveFeatures(vector<FeatureTrajectoryPtr>& features, TrajectoryDBAccess<Point2f>& db, const unsigned int& minNFeatures = 0) { 55 inline void saveFeatures(vector<FeatureTrajectoryPtr>& features, TrajectoryDBAccess<Point2f>& db, const string& positionsTableName, const string& velocitiesTableName, const unsigned int& minNFeatures = 0) {
56 if (features.size() >= minNFeatures) { 56 if (features.size() >= minNFeatures) {
57 BOOST_FOREACH(FeatureTrajectoryPtr f, features) f->write(db); 57 BOOST_FOREACH(FeatureTrajectoryPtr f, features) f->write(db, positionsTableName, velocitiesTableName);
58 features.clear(); 58 features.clear();
59 } 59 }
60 } 60 }
61 61
62 int main(int argc, char *argv[]) { 62 int main(int argc, char *argv[]) {
118 118
119 // database 119 // database
120 boost::shared_ptr<TrajectoryDBAccess<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccess<Point2f> >(new TrajectoryDBAccessList<Point2f>()); 120 boost::shared_ptr<TrajectoryDBAccess<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccess<Point2f> >(new TrajectoryDBAccessList<Point2f>());
121 //TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>(); 121 //TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>();
122 trajectoryDB->connect(params.databaseFilename.c_str()); 122 trajectoryDB->connect(params.databaseFilename.c_str());
123 trajectoryDB->createTable(); 123 trajectoryDB->createTable("positions");
124 trajectoryDB->createTable("velocities");
125 trajectoryDB->beginTransaction();
124 126
125 vector<KeyPoint> prevKpts, currKpts; 127 vector<KeyPoint> prevKpts, currKpts;
126 vector<Point2f> prevPts, currPts, newPts; 128 vector<Point2f> prevPts, currPts, newPts;
127 vector<uchar> status; 129 vector<uchar> status;
128 vector<float> errors; 130 vector<float> errors;
179 iter++; 181 iter++;
180 } 182 }
181 } 183 }
182 currPts = trackedPts; 184 currPts = trackedPts;
183 assert(currPts.size() == featurePointMatches.size()); 185 assert(currPts.size() == featurePointMatches.size());
184 saveFeatures(lostFeatures, *trajectoryDB); 186 saveFeatures(lostFeatures, *trajectoryDB, "positions", "velocities");
185 187
186 if (params.display) { 188 if (params.display) {
187 BOOST_FOREACH(FeaturePointMatch fp, featurePointMatches) 189 BOOST_FOREACH(FeaturePointMatch fp, featurePointMatches)
188 fp.feature->draw(frame, Colors::red()); 190 fp.feature->draw(frame, Colors::red());
189 } 191 }
221 prevPts = currPts; 223 prevPts = currPts;
222 //prevKpts = currKpts; 224 //prevKpts = currKpts;
223 //currDesc.copyTo(prevDesc); 225 //currDesc.copyTo(prevDesc);
224 } 226 }
225 227
228 trajectoryDB->endTransaction();
226 trajectoryDB->disconnect(); 229 trajectoryDB->disconnect();
227 return 0; 230 return 0;
228 } 231 }
229 232
230 233