changeset 654:045d05cef9d0

updating to c++11 capabilities
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 07 May 2015 16:09:47 +0200
parents 107f1ad02b69
children 39fa1c998b29
files c/Motion.cpp c/Parameters.cpp c/feature-based-tracking.cpp include/Motion.hpp include/Parameters.hpp include/testutils.hpp
diffstat 6 files changed, 47 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/c/Motion.cpp	Thu May 07 13:25:31 2015 +0200
+++ b/c/Motion.cpp	Thu May 07 16:09:47 2015 +0200
@@ -13,6 +13,7 @@
 #include <map>
 #include <algorithm>
 #include <utility>
+#include <memory>
 
 using namespace std;
 using namespace cv;
@@ -33,7 +34,7 @@
   positions->computeInstants(firstInstant, lastInstant);
 }
 
-FeatureTrajectory::FeatureTrajectory(const int& id, TrajectoryDBAccessList<Point2f>& trajectoryDB, const string& positionsTableName, const string& velocitiesTableName) {
+FeatureTrajectory::FeatureTrajectory(const int& id, TrajectoryDBAccess<Point2f>& trajectoryDB, const string& positionsTableName, const string& velocitiesTableName) {
   bool success = trajectoryDB.read(positions, id, positionsTableName);
   if (!success)
     cout << "problem loading positions" << endl;
--- a/c/Parameters.cpp	Thu May 07 13:25:31 2015 +0200
+++ b/c/Parameters.cpp	Thu May 07 16:09:47 2015 +0200
@@ -18,6 +18,7 @@
     ("help,h", "displays this help message")
     ("tf", "tracks features")
     ("gf", "groups features")
+    ("loading-time", "report feature and object loading times")
     ("config-file", po::value<string>(&configurationFilename), "configuration file")
     ;
 
@@ -102,6 +103,7 @@
 
     trackFeatures = vm.count("tf")>0;
     groupFeatures = vm.count("gf")>0;
+    loadingTime = vm.count("loading-time")>0;
 
     if (vm.count("help")) {
       cout << cmdLine << endl;
--- 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;
   }
--- a/include/Motion.hpp	Thu May 07 13:25:31 2015 +0200
+++ b/include/Motion.hpp	Thu May 07 16:09:47 2015 +0200
@@ -2,14 +2,12 @@
 #define MOTION_HPP
 
 #include "src/Trajectory.h"
-#include <boost/shared_ptr.hpp>
 #include <boost/graph/adjacency_list.hpp>
 
 
 template<typename T> class TrajectoryDBAccess;
-template<typename T> class TrajectoryDBAccessList;
 
-typedef boost::shared_ptr<TrajectoryPoint2f> TrajectoryPoint2fPtr;
+typedef std::shared_ptr<TrajectoryPoint2f> TrajectoryPoint2fPtr;
 
 /** Class for feature data
     positions, velocities and other statistics to evaluate their quality
@@ -23,7 +21,7 @@
 
   /** loads from database
    can be made generic for different list and blob */
-  FeatureTrajectory(const int& id, TrajectoryDBAccessList<cv::Point2f>& trajectoryDB, const std::string& positionsTableName, const std::string& velocitiesTableName);
+  FeatureTrajectory(const int& id, TrajectoryDBAccess<cv::Point2f>& trajectoryDB, const std::string& positionsTableName, const std::string& velocitiesTableName);
 
   unsigned int length(void) const { return positions->size();} // cautious if not continuous: max-min+1
 
@@ -76,7 +74,7 @@
   void computeMotionData(const int& frameNum);
 };
 
-typedef boost::shared_ptr<FeatureTrajectory> FeatureTrajectoryPtr;
+typedef std::shared_ptr<FeatureTrajectory> FeatureTrajectoryPtr;
 
 // inlined
 inline std::ostream& operator<<(std::ostream& out, const FeatureTrajectory& ft) 
--- a/include/Parameters.hpp	Thu May 07 13:25:31 2015 +0200
+++ b/include/Parameters.hpp	Thu May 07 16:09:47 2015 +0200
@@ -16,6 +16,7 @@
 struct KLTFeatureTrackingParameters {
   bool trackFeatures;
   bool groupFeatures;
+  bool loadingTime;
 
   std::string videoFilename;
   std::string databaseFilename;
--- a/include/testutils.hpp	Thu May 07 13:25:31 2015 +0200
+++ b/include/testutils.hpp	Thu May 07 16:09:47 2015 +0200
@@ -5,11 +5,9 @@
 
 #include "opencv2/core/core.hpp"
 
-#include <boost/shared_ptr.hpp>
-
-inline boost::shared_ptr<FeatureTrajectory> createFeatureTrajectory(const unsigned int& id, const unsigned int& firstInstant, const unsigned int& lastInstant, const cv::Point2f& firstPosition, const cv::Point2f& velocity) {
+inline std::shared_ptr<FeatureTrajectory> createFeatureTrajectory(const unsigned int& id, const unsigned int& firstInstant, const unsigned int& lastInstant, const cv::Point2f& firstPosition, const cv::Point2f& velocity) {
   cv::Mat emptyHomography;
-  boost::shared_ptr<FeatureTrajectory> t = boost::shared_ptr<FeatureTrajectory>(new FeatureTrajectory(firstInstant, firstPosition, emptyHomography));
+  std::shared_ptr<FeatureTrajectory> t = std::shared_ptr<FeatureTrajectory>(new FeatureTrajectory(firstInstant, firstPosition, emptyHomography));
   cv::Point2f p = firstPosition;
   for (unsigned int i=firstInstant+1; i<=lastInstant; ++i) {
     p = p+velocity;