Mercurial > hg > nsaunier > traffic-intelligence
comparison c/Motion.cpp @ 231:249d65ff6c35
merged modifications for windows
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 02 Jul 2012 23:49:39 -0400 |
| parents | bc4ea09b1743 d4d3b1e8a9f1 |
| children | 04355e51d895 |
comparison
equal
deleted
inserted
replaced
| 230:bc4ea09b1743 | 231:249d65ff6c35 |
|---|---|
| 156 graph[newVertex].feature = ft; | 156 graph[newVertex].feature = ft; |
| 157 for (graph_traits<UndirectedGraph>::vertex_iterator vi = vertices(graph).first; | 157 for (graph_traits<UndirectedGraph>::vertex_iterator vi = vertices(graph).first; |
| 158 vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor | 158 vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor |
| 159 FeatureTrajectoryPtr ft2 = graph[*vi].feature; | 159 FeatureTrajectoryPtr ft2 = graph[*vi].feature; |
| 160 if (newVertex != *vi) { | 160 if (newVertex != *vi) { |
| 161 int lastInstant = static_cast<int>(min(ft->getLastInstant(), ft2->getLastInstant())); | 161 int lastInstant = static_cast<int>(MIN(ft->getLastInstant(), ft2->getLastInstant())); |
| 162 int firstInstant = static_cast<int>(max(ft->getFirstInstant(), ft2->getFirstInstant())); | 162 int firstInstant = static_cast<int>(MAX(ft->getFirstInstant(), ft2->getFirstInstant())); |
| 163 if (lastInstant-firstInstant > static_cast<int>(minFeatureTime)) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime | 163 if (lastInstant-firstInstant > static_cast<int>(minFeatureTime)) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime |
| 164 if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) { | 164 if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) { |
| 165 UndirectedGraph::edge_descriptor e; | 165 UndirectedGraph::edge_descriptor e; |
| 166 bool unused; | 166 bool unused; |
| 167 std::tr1::tie(e, unused) = add_edge(newVertex, *vi, graph); | 167 tr1::tie(e, unused) = add_edge(newVertex, *vi, graph); |
| 168 // no need to add measures to graph[e] (edge properties) | 168 // no need to add measures to graph[e] (edge properties) |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 void FeatureGraph::connectedComponents(const int& lastInstant) { | 175 void FeatureGraph::connectedComponents(const unsigned int& lastInstant) { |
| 176 computeVertexIndex(); | 176 computeVertexIndex(); |
| 177 property_map<UndirectedGraph, int VertexInformation::*>::type components = get(&VertexInformation::index, graph); | 177 property_map<UndirectedGraph, int VertexInformation::*>::type components = get(&VertexInformation::index, graph); |
| 178 | 178 |
| 179 int num = connected_components(graph, components, vertex_index_map(get(&VertexInformation::index, graph))); | 179 int num = connected_components(graph, components, vertex_index_map(get(&VertexInformation::index, graph))); |
| 180 #ifdef DEBUG | |
| 180 cout << "last instant threshold " << lastInstant << " Total number of components: " << num << endl; | 181 cout << "last instant threshold " << lastInstant << " Total number of components: " << num << endl; |
| 181 | 182 #endif |
| 182 std::vector<unsigned int> lastInstants(num, 0); // last instant of component with id | 183 |
| 183 std::vector<std::vector<vertex_descriptor> > tmpobjects(num), objects; // vector of components (component = vector of vertex descriptors) | 184 vector<unsigned int> lastInstants(num, 0); // last instant of component with id |
| 185 vector<vector<vertex_descriptor> > tmpobjects(num), objects; // vector of components (component = vector of vertex descriptors) | |
| 184 | 186 |
| 185 graph_traits<UndirectedGraph>::vertex_iterator vi, vend; | 187 graph_traits<UndirectedGraph>::vertex_iterator vi, vend; |
| 186 for(std::tr1::tie(vi,vend) = vertices(graph); vi != vend; ++vi) { | 188 for(tr1::tie(vi,vend) = vertices(graph); vi != vend; ++vi) { |
| 187 //for (int i = 0; i < nVertices; ++i) { | |
| 188 unsigned int id = components[*vi]; | 189 unsigned int id = components[*vi]; |
| 189 //cout << "Vertex " << *vi << " is in component " << id << endl;// "(last " << graph[i].feature->getLastInstant() << " " << lastInstants[components[i]] << " " << (lastInstants[components[i]] < graph[i].feature->getLastInstant()) << ")" << endl; | 190 lastInstants[id] = max(lastInstants[id], graph[*vi].feature->getLastInstant()); |
| 190 if (lastInstants[id] < graph[*vi].feature->getLastInstant()) | |
| 191 lastInstants[id] = graph[*vi].feature->getLastInstant(); | |
| 192 tmpobjects[id].push_back(*vi); | 191 tmpobjects[id].push_back(*vi); |
| 193 } | 192 } |
| 194 | 193 |
| 195 objectHypotheses.clear(); | 194 objectHypotheses.clear(); |
| 196 for (int i = 0; i < num; ++i) { | 195 for (int i = 0; i < num; ++i) { |
| 196 #ifdef DEBUG | |
| 197 cout << i << " " << lastInstants[i] << endl; | 197 cout << i << " " << lastInstants[i] << endl; |
| 198 #endif | |
| 198 if (static_cast<int>(lastInstants[i]) < lastInstant) | 199 if (static_cast<int>(lastInstants[i]) < lastInstant) |
| 199 objectHypotheses.push_back(tmpobjects[i]); | 200 objectHypotheses.push_back(tmpobjects[i]); |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 | 203 |
| 203 std::vector<std::vector<unsigned int> > FeatureGraph::getFeatureGroups(void) { | 204 vector<vector<unsigned int> > FeatureGraph::getFeatureGroups(void) { |
| 204 std::vector<std::vector<unsigned int> > featureGroups; | 205 vector<vector<unsigned int> > featureGroups; |
| 205 | 206 |
| 206 for (unsigned int i=0; i<objectHypotheses.size(); ++i) { | 207 for (unsigned int i=0; i<objectHypotheses.size(); ++i) { |
| 207 // check that there is on average at least minNFeaturesPerGroup features at each frame in the group | 208 // check that there is on average at least minNFeaturesPerGroup features at each frame in the group |
| 208 float totalFeatureTime=0; | 209 unsigned int totalFeatureTime= graph[objectHypotheses[i][0]].feature->length(); |
| 209 for (unsigned int j=0; j<objectHypotheses[i].size(); ++j) | 210 unsigned int firstInstant = graph[objectHypotheses[i][0]].feature->getFirstInstant(); |
| 210 totalFeatureTime += static_cast<float>(graph[objectHypotheses[i][j]].feature->length()); | 211 unsigned int lastInstant = graph[objectHypotheses[i][0]].feature->getLastInstant(); |
| 211 cout << i << endl; | 212 for (unsigned int j=1; j<objectHypotheses[i].size(); ++j) { |
| 212 if (totalFeatureTime/static_cast<float>(objectHypotheses[i].size()) > minNFeaturesPerGroup) { | 213 totalFeatureTime += graph[objectHypotheses[i][j]].feature->length(); |
| 213 cout << "save group " << objectHypotheses[i].size() << " " << totalFeatureTime/static_cast<float>(objectHypotheses[i].size()) << endl; | 214 firstInstant = MIN(firstInstant, graph[objectHypotheses[i][j]].feature->getFirstInstant()); |
| 214 featureGroups.push_back(std::vector<unsigned int>()); | 215 lastInstant = MAX(lastInstant, graph[objectHypotheses[i][j]].feature->getLastInstant()); |
| 216 } | |
| 217 if (static_cast<float>(totalFeatureTime)/static_cast<float>(lastInstant-firstInstant+1) > minNFeaturesPerGroup) { | |
| 218 #if DEBUG | |
| 219 cout << "save group " << i << " of " << objectHypotheses[i].size() << " features " << endl; | |
| 220 #endif | |
| 221 featureGroups.push_back(vector<unsigned int>()); | |
| 215 for (unsigned int j=0; j<objectHypotheses[i].size(); ++j) { | 222 for (unsigned int j=0; j<objectHypotheses[i].size(); ++j) { |
| 216 featureGroups.back().push_back(graph[objectHypotheses[i][j]].feature->getId());cout << featureGroups.size() << " " << objectHypotheses[i][j] << endl; | 223 featureGroups.back().push_back(graph[objectHypotheses[i][j]].feature->getId()); |
| 217 clear_vertex(objectHypotheses[i][j], graph);cout << "cleared "<< objectHypotheses[i][j] << endl; | 224 #if DEBUG |
| 218 remove_vertex(objectHypotheses[i][j], graph);cout << "removed "<< objectHypotheses[i][j] << endl; | 225 cout << featureGroups.size() << " " << objectHypotheses[i][j] << endl; |
| 226 #endif | |
| 227 clear_vertex(objectHypotheses[i][j], graph); | |
| 228 remove_vertex(objectHypotheses[i][j], graph); | |
| 219 } | 229 } |
| 220 } | 230 } |
| 221 } | 231 } |
| 222 | 232 |
| 223 return featureGroups; | 233 return featureGroups; |
| 234 int FeatureGraph::getNEdges(void) const { return num_edges(graph);} | 244 int FeatureGraph::getNEdges(void) const { return num_edges(graph);} |
| 235 | 245 |
| 236 void FeatureGraph::computeVertexIndex(void) { | 246 void FeatureGraph::computeVertexIndex(void) { |
| 237 graph_traits<FeatureGraph::UndirectedGraph>::vertex_iterator vi, vend; | 247 graph_traits<FeatureGraph::UndirectedGraph>::vertex_iterator vi, vend; |
| 238 graph_traits<FeatureGraph::UndirectedGraph>::vertices_size_type cnt = 0; | 248 graph_traits<FeatureGraph::UndirectedGraph>::vertices_size_type cnt = 0; |
| 239 for(std::tr1::tie(vi,vend) = vertices(graph); vi != vend; ++vi) | 249 for(tr1::tie(vi,vend) = vertices(graph); vi != vend; ++vi) |
| 240 graph[*vi].index = cnt++; | 250 graph[*vi].index = cnt++; |
| 241 } | 251 } |
