# HG changeset patch # User Nicolas Saunier # Date 1431007787 -7200 # Node ID 045d05cef9d0542dd75b8f1a749b7880e4fb079d # Parent 107f1ad02b697d7b6b087524f4c8f767938c13a1 updating to c++11 capabilities diff -r 107f1ad02b69 -r 045d05cef9d0 c/Motion.cpp --- 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 #include #include +#include using namespace std; using namespace cv; @@ -33,7 +34,7 @@ positions->computeInstants(firstInstant, lastInstant); } -FeatureTrajectory::FeatureTrajectory(const int& id, TrajectoryDBAccessList& trajectoryDB, const string& positionsTableName, const string& velocitiesTableName) { +FeatureTrajectory::FeatureTrajectory(const int& id, TrajectoryDBAccess& trajectoryDB, const string& positionsTableName, const string& velocitiesTableName) { bool success = trajectoryDB.read(positions, id, positionsTableName); if (!success) cout << "problem loading positions" << endl; diff -r 107f1ad02b69 -r 045d05cef9d0 c/Parameters.cpp --- 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(&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; diff -r 107f1ad02b69 -r 045d05cef9d0 c/feature-based-tracking.cpp --- 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 #include #include @@ -24,6 +23,7 @@ #include #include #include +#include using namespace std; using namespace cv; @@ -92,11 +92,11 @@ // BruteForceMatcher descMatcher; // vector matches; - boost::shared_ptr capture; + std::shared_ptr capture; if (fs::is_directory(fs::path(params.videoFilename))) - capture = boost::shared_ptr(new InputFrameListModule(params.videoFilename)); + capture = std::shared_ptr(new InputFrameListModule(params.videoFilename)); else if(!params.videoFilename.empty()) - capture = boost::shared_ptr(new InputVideoFileModule(params.videoFilename)); + capture = std::shared_ptr(new InputVideoFileModule(params.videoFilename)); else cout << "No valid input parameters" << endl; @@ -131,7 +131,7 @@ mask = Mat::ones(videoSize, CV_8UC1); } - boost::shared_ptr > trajectoryDB = boost::shared_ptr >(new TrajectoryDBAccessList()); + std::shared_ptr > trajectoryDB = std::shared_ptr >(new TrajectoryDBAccessList()); //TrajectoryDBAccess* trajectoryDB = new TrajectoryDBAccessBlob(); trajectoryDB->connect(params.databaseFilename.c_str()); trajectoryDB->createTable("positions"); @@ -265,27 +265,11 @@ } void groupFeatures(const KLTFeatureTrackingParameters& params) { - boost::shared_ptr > trajectoryDB = boost::shared_ptr >(new TrajectoryDBAccessList()); - //TODO write generic methods for blob and list versions TrajectoryDBAccess* trajectoryDB = new TrajectoryDBAccessBlob(); + std::shared_ptr > trajectoryDB = std::shared_ptr >(new TrajectoryDBAccessList()); bool success = trajectoryDB->connect(params.databaseFilename.c_str()); trajectoryDB->createObjectTable("objects", "objects_features"); unsigned int savedObjectId=0; - // vector > > 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; - // c_start = std::clock(); - // for (unsigned int i = 0; iread(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; + // std::shared_ptr > 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 > trajectoryDB = std::shared_ptr >(new TrajectoryDBAccessList()); + bool success = trajectoryDB->connect(params.databaseFilename.c_str()); + + vector > > 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; + c_start = std::clock(); + for (unsigned int i = 0; iread(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; } diff -r 107f1ad02b69 -r 045d05cef9d0 include/Motion.hpp --- 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 #include template class TrajectoryDBAccess; -template class TrajectoryDBAccessList; -typedef boost::shared_ptr TrajectoryPoint2fPtr; +typedef std::shared_ptr 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& trajectoryDB, const std::string& positionsTableName, const std::string& velocitiesTableName); + FeatureTrajectory(const int& id, TrajectoryDBAccess& 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 FeatureTrajectoryPtr; +typedef std::shared_ptr FeatureTrajectoryPtr; // inlined inline std::ostream& operator<<(std::ostream& out, const FeatureTrajectory& ft) diff -r 107f1ad02b69 -r 045d05cef9d0 include/Parameters.hpp --- 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; diff -r 107f1ad02b69 -r 045d05cef9d0 include/testutils.hpp --- 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 - -inline boost::shared_ptr 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 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 t = boost::shared_ptr(new FeatureTrajectory(firstInstant, firstPosition, emptyHomography)); + std::shared_ptr t = std::shared_ptr(new FeatureTrajectory(firstInstant, firstPosition, emptyHomography)); cv::Point2f p = firstPosition; for (unsigned int i=firstInstant+1; i<=lastInstant; ++i) { p = p+velocity;