diff c/feature-based-tracking.cpp @ 654:045d05cef9d0

updating to c++11 capabilities
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 07 May 2015 16:09:47 +0200
parents a3add9f751ef
children 39fa1c998b29
line wrap: on
line diff
--- a/c/feature-based-tracking.cpp	Thu May 07 13:25:31 2015 +0200
+++ b/c/feature-based-tracking.cpp	Thu May 07 16:09:47 2015 +0200
@@ -16,7 +16,6 @@
 #include "opencv2/highgui/highgui.hpp"
 #include "opencv2/objdetect/objdetect.hpp"
 
-#include <boost/shared_ptr.hpp>
 #include <boost/foreach.hpp>
 #include <boost/filesystem.hpp>
 
@@ -24,6 +23,7 @@
 #include <vector>
 #include <ctime>
 #include <cmath>
+#include <memory>
 
 using namespace std;
 using namespace cv;
@@ -92,11 +92,11 @@
   // BruteForceMatcher<Hamming> descMatcher;
   // vector<DMatch> matches;
 
-  boost::shared_ptr<InputFrameProviderIface> capture;
+  std::shared_ptr<InputFrameProviderIface> capture;
   if (fs::is_directory(fs::path(params.videoFilename)))
-    capture = boost::shared_ptr<InputFrameListModule>(new InputFrameListModule(params.videoFilename));
+    capture = std::shared_ptr<InputFrameListModule>(new InputFrameListModule(params.videoFilename));
   else if(!params.videoFilename.empty())
-    capture = boost::shared_ptr<InputVideoFileModule>(new InputVideoFileModule(params.videoFilename));
+    capture = std::shared_ptr<InputVideoFileModule>(new InputVideoFileModule(params.videoFilename));
   else
     cout << "No valid input parameters" << endl;
   
@@ -131,7 +131,7 @@
     mask = Mat::ones(videoSize, CV_8UC1);
   }
 
-  boost::shared_ptr<TrajectoryDBAccess<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccess<Point2f> >(new TrajectoryDBAccessList<Point2f>());
+  std::shared_ptr<TrajectoryDBAccess<Point2f> > trajectoryDB = std::shared_ptr<TrajectoryDBAccess<Point2f> >(new TrajectoryDBAccessList<Point2f>());
   //TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>();
   trajectoryDB->connect(params.databaseFilename.c_str());
   trajectoryDB->createTable("positions");
@@ -265,27 +265,11 @@
 }
 
 void groupFeatures(const KLTFeatureTrackingParameters& params) {
-  boost::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>());
-  //TODO write generic methods for blob and list versions TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>();
+  std::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = std::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>());
   bool success = trajectoryDB->connect(params.databaseFilename.c_str());
   trajectoryDB->createObjectTable("objects", "objects_features");
   unsigned int savedObjectId=0;
 
-  // vector<boost::shared_ptr<Trajectory<Point2f> > > trajectories;
-  // cout << trajectories.size() << 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->createInstants("table");
 
   unsigned int maxTrajectoryLength = 0;
@@ -321,7 +305,7 @@
     //   FeatureTrajectoryPtr ft = FeatureTrajectoryPtr(new FeatureTrajectory(positions[i], velocities[i]));
     BOOST_FOREACH(int trajectoryId, trajectoryIds) {
       //cout << trajectoryId << " " << endl;
-      // boost::shared_ptr<Trajectory<cv::Point2f> > trajectory;
+      // std::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;
@@ -362,18 +346,46 @@
 
   trajectoryDB->endTransaction();
   trajectoryDB->disconnect();
- }
+}
+
+void loadingTimes(const KLTFeatureTrackingParameters& params) {
+  std::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = std::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>());
+  bool success = trajectoryDB->connect(params.databaseFilename.c_str());
+  
+  vector<std::shared_ptr<Trajectory<Point2f> > > trajectories;
+  //cout << trajectories.size() << endl;
+  std::clock_t c_start = std::clock();
+  success = trajectoryDB->read(trajectories, "positions");
+  std::clock_t c_end = std::clock();
+  if (!success)
+    cout << "Issue with db reading" << endl;
+  cout << "Loaded " << trajectories.size() << " trajectories in " << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " CPU seconds" << endl;
+
+  std::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->endTransaction();
+  trajectoryDB->disconnect();
+}
 
 int main(int argc, char *argv[]) {
   KLTFeatureTrackingParameters params(argc, argv);
   cout << params.parameterDescription << endl;
-
+  
   if (params.trackFeatures) {
     cout << "The program tracks features" << endl;
     trackFeatures(params);
   } else if (params.groupFeatures) {
     cout << "The program groups features" << endl;
     groupFeatures(params);
+  } else if (params.loadingTime) {
+    cout << "The program reports loading times" << endl;
+    loadingTimes(params);
   } else {
     cout << "Main option missing or misspelt" << endl;
   }