Mercurial Hosting > traffic-intelligence
changeset 194:09c7881073f3
connected commponents works, but issue with removing the vertices
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 12 Dec 2011 18:32:10 -0500 |
parents | a728fce85881 |
children | 1247e26a8b5e |
files | c/Motion.cpp c/feature-based-tracking.cpp include/Motion.hpp |
diffstat | 3 files changed, 20 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/c/Motion.cpp Mon Dec 12 15:44:54 2011 -0500 +++ b/c/Motion.cpp Mon Dec 12 18:32:10 2011 -0500 @@ -7,7 +7,6 @@ #include "opencv2/highgui/highgui.hpp" #include <boost/graph/connected_components.hpp> -#include <boost/property_map/property_map.hpp> #include <iostream> #include <vector> @@ -167,7 +166,7 @@ } } -vector<vector<FeatureGraph::vertex_descriptor> > FeatureGraph::connectedComponents(const int& lastInstant) { +void FeatureGraph::connectedComponents(const int& lastInstant) { computeVertexIndex(); property_map<UndirectedGraph, int VertexInformation::*>::type components = get(&VertexInformation::index, graph); @@ -181,37 +180,38 @@ for(tie(vi,vend) = vertices(graph); vi != vend; ++vi) { //for (int i = 0; i < nVertices; ++i) { unsigned int id = components[*vi]; - cout << "Vertex " << *vi << " is in component " << id << endl;// "(last " << graph[i].feature->getLastInstant() << " " << lastInstants[components[i]] << " " << (lastInstants[components[i]] < graph[i].feature->getLastInstant()) << ")" << endl; + //cout << "Vertex " << *vi << " is in component " << id << endl;// "(last " << graph[i].feature->getLastInstant() << " " << lastInstants[components[i]] << " " << (lastInstants[components[i]] < graph[i].feature->getLastInstant()) << ")" << endl; if (lastInstants[id] < graph[*vi].feature->getLastInstant()) lastInstants[id] = graph[*vi].feature->getLastInstant(); tmpobjects[id].push_back(*vi); } + objectHypotheses.clear(); for (int i = 0; i < num; ++i) { cout << i << " " << lastInstants[i] << endl; if (static_cast<int>(lastInstants[i]) < lastInstant) - objects.push_back(tmpobjects[i]); + objectHypotheses.push_back(tmpobjects[i]); } - - return objects; } -vector<vector<unsigned int> > FeatureGraph::getFeatureGroups(const vector<vector<FeatureGraph::vertex_descriptor> >& objectHypotheses) { +vector<vector<unsigned int> > FeatureGraph::getFeatureGroups(void) { vector<vector<unsigned int> > featureGroups; for (unsigned int i=0; i<objectHypotheses.size(); ++i) { // check that there is on average at least minNFeaturesPerGroup features at each frame in the group float totalFeatureTime=0; - for (unsigned int j=0; j<objectHypotheses.size(); ++j) + for (unsigned int j=0; j<objectHypotheses[i].size(); ++j) totalFeatureTime += static_cast<float>(graph[objectHypotheses[i][j]].feature->length()); - - if (totalFeatureTime/static_cast<float>(objectHypotheses.size()) > minNFeaturesPerGroup) { - cout << "save group" << endl; + cout << i << endl; + if (totalFeatureTime/static_cast<float>(objectHypotheses[i].size()) > minNFeaturesPerGroup) { + cout << "save group " << objectHypotheses[i].size() << " " << totalFeatureTime/static_cast<float>(objectHypotheses[i].size()) << endl; featureGroups.push_back(vector<unsigned int>()); - for (unsigned int j=0; j<objectHypotheses.size(); ++j) - featureGroups.back().push_back(graph[objectHypotheses[i][j]].feature->getId()); + for (unsigned int j=0; j<objectHypotheses[i].size(); ++j) { + featureGroups.back().push_back(graph[objectHypotheses[i][j]].feature->getId());cout << featureGroups.size() << " " << objectHypotheses[i][j] << endl; + clear_vertex(objectHypotheses[i][j], graph);cout << "cleared "<< objectHypotheses[i][j] << endl; + remove_vertex(objectHypotheses[i][j], graph);cout << "removed "<< objectHypotheses[i][j] << endl; + } } - // remove vertices: todo using listS } return featureGroups;
--- a/c/feature-based-tracking.cpp Mon Dec 12 15:44:54 2011 -0500 +++ b/c/feature-based-tracking.cpp Mon Dec 12 18:32:10 2011 -0500 @@ -298,12 +298,8 @@ // check for connected components that are old enough (no chance to match with trajectories to be added later // we could check only when some features are getting old enough? if (frameNum%10 == 0) { - vector<vector<FeatureGraph::vertex_descriptor> > objects = featureGraph.connectedComponents(frameNum-maxTrajectoryLength+params.minFeatureTime); - cout << objects.size() << " objects" << endl; - - if (!objects.empty()) { - vector<vector<unsigned int> > featureGroups = featureGraph.getFeatureGroups(objects); - } + featureGraph.connectedComponents(frameNum-maxTrajectoryLength+params.minFeatureTime); + vector<vector<unsigned int> > featureGroups = featureGraph.getFeatureGroups(); } cout << featureGraph.informationString() << endl;
--- a/include/Motion.hpp Mon Dec 12 15:44:54 2011 -0500 +++ b/include/Motion.hpp Mon Dec 12 18:32:10 2011 -0500 @@ -117,12 +117,12 @@ // find connected components, check if old enough, if so, remove /// Computes the connected components: features have to be older than lastInstant - std::vector<std::vector<vertex_descriptor> > connectedComponents(const int& lastInstant); + void connectedComponents(const int& lastInstant); /** Performs some checks on groups of features and return their lists of ids if correct Removes the vertices from the graph */ - std::vector<std::vector<unsigned int> > getFeatureGroups(const std::vector<std::vector<vertex_descriptor> >& objectHypotheses); + std::vector<std::vector<unsigned int> > getFeatureGroups(void); std::string informationString(void); @@ -136,6 +136,8 @@ UndirectedGraph graph; + std::vector<std::vector<vertex_descriptor> > objectHypotheses; + void computeVertexIndex(void); //std::vector<UndirectedGraph::vertex_descriptor> currentVertices, lostVertices;