changeset 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 319a04ba9033
children a234a5e818f3
files c/feature-based-tracking.cpp
diffstat 1 files changed, 27 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/c/feature-based-tracking.cpp	Wed Oct 26 15:04:38 2011 -0400
+++ b/c/feature-based-tracking.cpp	Wed Oct 26 17:46:11 2011 -0400
@@ -18,6 +18,7 @@
 
 #include <iostream>
 #include <vector>
+#include <ctime>
 
 using namespace std;
 using namespace cv;
@@ -61,6 +62,10 @@
 }
 
 void trackFeatures(const KLTFeatureTrackingParameters& params) {
+  // BriefDescriptorExtractor brief(32);
+  // const int DESIRED_FTRS = 500;
+  // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4);
+
   Mat homography = ::loadMat(params.homographyFilename, " ");
   Mat invHomography;
   if (params.display && !homography.empty())
@@ -245,13 +250,18 @@
   bool success = trajectoryDB->connect(params.databaseFilename.c_str());
   vector<boost::shared_ptr<Trajectory<Point2f> > > trajectories;
   cout << trajectories.size() << endl;
-  success = trajectoryDB->read(trajectories, "positions"); // TODO load velocities as well in a FeatureTrajectory object // attention, velocities lack the first instant
-  cout << "Loaded " << trajectories.size() << " trajectories" << endl;
-  // for (int i=0; i<5; ++i) {
-  //   stringstream ss;
-  //   ss << *trajectories[i];
-  //   cout << ss.str() << endl;
+  // std::clock_t c_start = std::clock();
+  // success = trajectoryDB->read(trajectories, "positions"); // TODO load velocities as well in a FeatureTrajectory object // attention, velocities lack the first instant
+  // std::clock_t c_end = std::clock();
+  // cout << "Loaded " << trajectories.size() << " trajectories in " << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " CPU seconds" << endl;
+
+  // boost::shared_ptr<Trajectory<cv::Point2f> > trajectory;
+  // c_start = std::clock();
+  // for (unsigned int i = 0; i<trajectories.size(); ++i) {
+  //   success = trajectoryDB->read(trajectory, i, "positions");
   // }
+  // c_end = std::clock();
+  // cout << "Loaded " << trajectories.size() << " trajectories one by one in " << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " CPU seconds" << endl;
 
   trajectoryDB->createViewInstants("first");
   trajectoryDB->createViewInstants("last");
@@ -259,26 +269,26 @@
   // main loop
   // TODO version que l'on peut interrompre ?
   for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)); frameNum++) {
-    vector<int> ids;
-    cout << "frame " << frameNum << " " << trajectoryDB->trajectoryIdStartingAt(ids, frameNum) << endl;
-    cout << ids.size() << ": ";
-    BOOST_FOREACH(int i, ids)
-      cout << i << " ";
-    cout << endl;
+    vector<int> trajectoryIds;
+    success  = trajectoryDB->trajectoryIdStartingAt(trajectoryIds, frameNum);
+    cout << "frame " << frameNum << " " << success << endl;
+    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;
+    }
 
     // should the trajectory be loaded one by one? yes
 
-  }
+    }
 
   trajectoryDB->endTransaction();
   trajectoryDB->disconnect();
  }
 
 int main(int argc, char *argv[]) {
-  // BriefDescriptorExtractor brief(32);
-  // const int DESIRED_FTRS = 500;
-  // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4);
-
   KLTFeatureTrackingParameters params(argc, argv);
   cout << params.parameterDescription << endl;