comparison c/Motion.cpp @ 716:85af65b6d531 dev

corrected major bug slowing feature grouping
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sat, 25 Jul 2015 23:28:52 -0400
parents 045d05cef9d0
children 6022350f8173
comparison
equal deleted inserted replaced
715:a05f79c74d6d 716:85af65b6d531
186 #ifdef DEBUG 186 #ifdef DEBUG
187 cout << "last instant threshold " << lastInstant << " Total number of components: " << num << endl; 187 cout << "last instant threshold " << lastInstant << " Total number of components: " << num << endl;
188 #endif 188 #endif
189 189
190 vector<unsigned int> lastInstants(num, 0); // last instant of component with id 190 vector<unsigned int> lastInstants(num, 0); // last instant of component with id
191 vector<vector<vertex_descriptor> > tmpobjects(num), objects; // vector of components (component = vector of vertex descriptors) 191 vector<vector<vertex_descriptor> > tmpobjects(num); // vector of components (component = vector of vertex descriptors)
192 192
193 graph_traits<UndirectedGraph>::vertex_iterator vi, vend; 193 graph_traits<UndirectedGraph>::vertex_iterator vi, vend;
194 for(boost::tuples::tie(vi,vend) = vertices(graph); vi != vend; ++vi) { 194 for(boost::tuples::tie(vi,vend) = vertices(graph); vi != vend; ++vi) {
195 unsigned int id = components[*vi]; 195 unsigned int id = components[*vi];
196 lastInstants[id] = max(lastInstants[id], graph[*vi].feature->getLastInstant()); 196 lastInstants[id] = max(lastInstants[id], graph[*vi].feature->getLastInstant());
213 for (unsigned int i=0; i<objectHypotheses.size(); ++i) { 213 for (unsigned int i=0; i<objectHypotheses.size(); ++i) {
214 // check that there is on average at least minNFeaturesPerGroup features at each frame in the group 214 // check that there is on average at least minNFeaturesPerGroup features at each frame in the group
215 unsigned int totalFeatureTime= graph[objectHypotheses[i][0]].feature->length(); 215 unsigned int totalFeatureTime= graph[objectHypotheses[i][0]].feature->length();
216 unsigned int firstInstant = graph[objectHypotheses[i][0]].feature->getFirstInstant(); 216 unsigned int firstInstant = graph[objectHypotheses[i][0]].feature->getFirstInstant();
217 unsigned int lastInstant = graph[objectHypotheses[i][0]].feature->getLastInstant(); 217 unsigned int lastInstant = graph[objectHypotheses[i][0]].feature->getLastInstant();
218 for (unsigned int j=1; j<objectHypotheses[i].size(); ++j) { 218 for (unsigned int j=1; j<objectHypotheses[i].size(); ++j) {
219 totalFeatureTime += graph[objectHypotheses[i][j]].feature->length(); 219 totalFeatureTime += graph[objectHypotheses[i][j]].feature->length();
220 firstInstant = MIN(firstInstant, graph[objectHypotheses[i][j]].feature->getFirstInstant()); 220 firstInstant = MIN(firstInstant, graph[objectHypotheses[i][j]].feature->getFirstInstant());
221 lastInstant = MAX(lastInstant, graph[objectHypotheses[i][j]].feature->getLastInstant()); 221 lastInstant = MAX(lastInstant, graph[objectHypotheses[i][j]].feature->getLastInstant());
222 } 222 }
223 if (static_cast<float>(totalFeatureTime)/static_cast<float>(lastInstant-firstInstant+1) > minNFeaturesPerGroup) { 223 bool saveFeatureGroup = (static_cast<float>(totalFeatureTime)/static_cast<float>(lastInstant-firstInstant+1) > minNFeaturesPerGroup);
224 #if DEBUG 224 #if DEBUG
225 cout << "save group " << i << " of " << objectHypotheses[i].size() << " features " << endl; 225 cout << "save group " << i << " of " << objectHypotheses[i].size() << " features " << endl;
226 #endif 226 #endif
227 if (saveFeatureGroup)
227 featureGroups.push_back(vector<FeatureTrajectoryPtr>()); 228 featureGroups.push_back(vector<FeatureTrajectoryPtr>());
228 for (unsigned int j=0; j<objectHypotheses[i].size(); ++j) { 229 for (unsigned int j=0; j<objectHypotheses[i].size(); ++j) {
230 if (saveFeatureGroup)
229 featureGroups.back().push_back(graph[objectHypotheses[i][j]].feature); 231 featureGroups.back().push_back(graph[objectHypotheses[i][j]].feature);
230 #if DEBUG 232 #if DEBUG
231 cout << featureGroups.size() << " " << objectHypotheses[i][j] << endl; 233 cout << featureGroups.size() << " " << objectHypotheses[i][j] << endl;
232 #endif 234 #endif
233 clear_vertex(objectHypotheses[i][j], graph); 235 clear_vertex(objectHypotheses[i][j], graph);
234 remove_vertex(objectHypotheses[i][j], graph); 236 remove_vertex(objectHypotheses[i][j], graph);
235 }
236 } 237 }
237 } 238 }
238 } 239 }
239 240
240 string FeatureGraph::informationString(void) const { 241 string FeatureGraph::informationString(void) const {