Mercurial Hosting > traffic-intelligence
comparison c/feature-based-tracking.cpp @ 174:ec9734015d53
tested loading trajectory by id numbers
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 26 Oct 2011 17:46:11 -0400 |
parents | e508bb0cbb64 |
children | a234a5e818f3 |
comparison
equal
deleted
inserted
replaced
173:319a04ba9033 | 174:ec9734015d53 |
---|---|
16 #include <boost/shared_ptr.hpp> | 16 #include <boost/shared_ptr.hpp> |
17 #include <boost/foreach.hpp> | 17 #include <boost/foreach.hpp> |
18 | 18 |
19 #include <iostream> | 19 #include <iostream> |
20 #include <vector> | 20 #include <vector> |
21 #include <ctime> | |
21 | 22 |
22 using namespace std; | 23 using namespace std; |
23 using namespace cv; | 24 using namespace cv; |
24 | 25 |
25 void drawMatchesRelative(const vector<KeyPoint>& train, const vector<KeyPoint>& query, std::vector<cv::DMatch>& matches, Mat& img) { | 26 void drawMatchesRelative(const vector<KeyPoint>& train, const vector<KeyPoint>& query, std::vector<cv::DMatch>& matches, Mat& img) { |
59 features.clear(); | 60 features.clear(); |
60 } | 61 } |
61 } | 62 } |
62 | 63 |
63 void trackFeatures(const KLTFeatureTrackingParameters& params) { | 64 void trackFeatures(const KLTFeatureTrackingParameters& params) { |
65 // BriefDescriptorExtractor brief(32); | |
66 // const int DESIRED_FTRS = 500; | |
67 // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); | |
68 | |
64 Mat homography = ::loadMat(params.homographyFilename, " "); | 69 Mat homography = ::loadMat(params.homographyFilename, " "); |
65 Mat invHomography; | 70 Mat invHomography; |
66 if (params.display && !homography.empty()) | 71 if (params.display && !homography.empty()) |
67 invHomography = homography.inv(); | 72 invHomography = homography.inv(); |
68 | 73 |
243 boost::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>()); | 248 boost::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>()); |
244 //TODO write generic methods for blob and list versions TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>(); | 249 //TODO write generic methods for blob and list versions TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>(); |
245 bool success = trajectoryDB->connect(params.databaseFilename.c_str()); | 250 bool success = trajectoryDB->connect(params.databaseFilename.c_str()); |
246 vector<boost::shared_ptr<Trajectory<Point2f> > > trajectories; | 251 vector<boost::shared_ptr<Trajectory<Point2f> > > trajectories; |
247 cout << trajectories.size() << endl; | 252 cout << trajectories.size() << endl; |
248 success = trajectoryDB->read(trajectories, "positions"); // TODO load velocities as well in a FeatureTrajectory object // attention, velocities lack the first instant | 253 // std::clock_t c_start = std::clock(); |
249 cout << "Loaded " << trajectories.size() << " trajectories" << endl; | 254 // success = trajectoryDB->read(trajectories, "positions"); // TODO load velocities as well in a FeatureTrajectory object // attention, velocities lack the first instant |
250 // for (int i=0; i<5; ++i) { | 255 // std::clock_t c_end = std::clock(); |
251 // stringstream ss; | 256 // cout << "Loaded " << trajectories.size() << " trajectories in " << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " CPU seconds" << endl; |
252 // ss << *trajectories[i]; | 257 |
253 // cout << ss.str() << endl; | 258 // boost::shared_ptr<Trajectory<cv::Point2f> > trajectory; |
259 // c_start = std::clock(); | |
260 // for (unsigned int i = 0; i<trajectories.size(); ++i) { | |
261 // success = trajectoryDB->read(trajectory, i, "positions"); | |
254 // } | 262 // } |
263 // c_end = std::clock(); | |
264 // cout << "Loaded " << trajectories.size() << " trajectories one by one in " << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " CPU seconds" << endl; | |
255 | 265 |
256 trajectoryDB->createViewInstants("first"); | 266 trajectoryDB->createViewInstants("first"); |
257 trajectoryDB->createViewInstants("last"); | 267 trajectoryDB->createViewInstants("last"); |
258 | 268 |
259 // main loop | 269 // main loop |
260 // TODO version que l'on peut interrompre ? | 270 // TODO version que l'on peut interrompre ? |
261 for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)); frameNum++) { | 271 for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)); frameNum++) { |
262 vector<int> ids; | 272 vector<int> trajectoryIds; |
263 cout << "frame " << frameNum << " " << trajectoryDB->trajectoryIdStartingAt(ids, frameNum) << endl; | 273 success = trajectoryDB->trajectoryIdStartingAt(trajectoryIds, frameNum); |
264 cout << ids.size() << ": "; | 274 cout << "frame " << frameNum << " " << success << endl; |
265 BOOST_FOREACH(int i, ids) | 275 cout << trajectoryIds.size() << " trajectories " << endl; |
266 cout << i << " "; | 276 BOOST_FOREACH(int trajectoryId, trajectoryIds) { |
267 cout << endl; | 277 //cout << trajectoryId << " " << endl; |
278 boost::shared_ptr<Trajectory<cv::Point2f> > trajectory; | |
279 success = trajectoryDB->read(trajectory, trajectoryId, "positions"); // velocities | |
280 stringstream ss;ss << *trajectory; cout << ss.str() << endl; | |
281 } | |
268 | 282 |
269 // should the trajectory be loaded one by one? yes | 283 // should the trajectory be loaded one by one? yes |
270 | 284 |
271 } | 285 } |
272 | 286 |
273 trajectoryDB->endTransaction(); | 287 trajectoryDB->endTransaction(); |
274 trajectoryDB->disconnect(); | 288 trajectoryDB->disconnect(); |
275 } | 289 } |
276 | 290 |
277 int main(int argc, char *argv[]) { | 291 int main(int argc, char *argv[]) { |
278 // BriefDescriptorExtractor brief(32); | |
279 // const int DESIRED_FTRS = 500; | |
280 // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); | |
281 | |
282 KLTFeatureTrackingParameters params(argc, argv); | 292 KLTFeatureTrackingParameters params(argc, argv); |
283 cout << params.parameterDescription << endl; | 293 cout << params.parameterDescription << endl; |
284 | 294 |
285 if (params.trackFeatures) | 295 if (params.trackFeatures) |
286 trackFeatures(params); | 296 trackFeatures(params); |