changeset 188:1435965d8181

work on connected components
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 01 Dec 2011 19:18:32 -0500
parents aa1061fb9695
children 1116f0a1ff31
files c/Motion.cpp c/feature-based-tracking.cpp include/Motion.hpp
diffstat 3 files changed, 30 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/c/Motion.cpp	Thu Dec 01 18:13:10 2011 -0500
+++ b/c/Motion.cpp	Thu Dec 01 19:18:32 2011 -0500
@@ -1,10 +1,18 @@
 #include "Motion.hpp"
 #include "cvutils.hpp"
 
+#include "src/TrajectoryDBAccessList.h"
+
 #include "opencv2/core/core.hpp"
 #include "opencv2/highgui/highgui.hpp"
 
-#include "src/TrajectoryDBAccessList.h"
+#include <boost/graph/connected_components.hpp>
+#include <boost/config.hpp>
+
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include <utility>
 
 using namespace std;
 using namespace cv;
@@ -157,6 +165,18 @@
   }
 }
 
+void FeatureGraph::connectedComponents(const int& lastInstant) {
+  vector<int> component(num_vertices(graph));
+  // int num = connected_components(graph, &component[0]);
+  // todo change the type of the component map http://www.boost.org/doc/libs/1_48_0/libs/graph/doc/connected_components.html
+
+  // cout << "Total number of components: " << num << endl;
+
+  for (unsigned int i = 0; i < component.size(); ++i)
+      cout << "Vertex " << i <<" is in component " << component[i] << endl;
+  cout << endl;
+}
+
 string FeatureGraph::informationString(void) {
   stringstream ss;
   ss << num_vertices(graph) << " vertices, " << num_edges(graph) << " edges";
--- a/c/feature-based-tracking.cpp	Thu Dec 01 18:13:10 2011 -0500
+++ b/c/feature-based-tracking.cpp	Thu Dec 01 19:18:32 2011 -0500
@@ -246,8 +246,8 @@
   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>();
   bool success = trajectoryDB->connect(params.databaseFilename.c_str());
-  vector<boost::shared_ptr<Trajectory<Point2f> > > trajectories;
-  cout << trajectories.size() << endl;
+  // 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();
@@ -262,7 +262,6 @@
   // cout << "Loaded " << trajectories.size() << " trajectories one by one in " << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " CPU seconds" << endl;
 
   trajectoryDB->createViewInstants();
-  //trajectoryDB->createViewInstants("last");
   int maxTrajectoryLength;
   trajectoryDB->maxTrajectoryLength(maxTrajectoryLength);
   cout << "max trajectory length " << maxTrajectoryLength << endl;
@@ -286,7 +285,10 @@
       featureGraph.addFeature(ft);
     }
 
-    // should the trajectory be loaded one by one? yes
+    // check for connected components that are old enough (no chance to match with trajectories to be added later
+    if (frameNum%10 == 0) {
+      
+    }
 
     cout << featureGraph.informationString() << endl;
   }
--- a/include/Motion.hpp	Thu Dec 01 18:13:10 2011 -0500
+++ b/include/Motion.hpp	Thu Dec 01 19:18:32 2011 -0500
@@ -101,6 +101,9 @@
   // add vertex, includes adding links to current vertices
   // find connected components, check if old enough, if so, remove
 
+  /// Computes the connected components: features have to be older than lastInstant
+  void connectedComponents(const int& lastInstant);
+
   std::string informationString(void);
 
 protected: