comparison c/feature-based-tracking.cpp @ 225:d4d3b1e8a9f1

added code to process only needed frames based on saved features
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 26 Jun 2012 03:37:19 -0400
parents 426321b46e44
children b7612c6d5702
comparison
equal deleted inserted replaced
224:37a434fb848e 225:d4d3b1e8a9f1
269 // success = trajectoryDB->read(trajectory, i, "positions"); 269 // success = trajectoryDB->read(trajectory, i, "positions");
270 // } 270 // }
271 // c_end = std::clock(); 271 // c_end = std::clock();
272 // cout << "Loaded " << trajectories.size() << " trajectories one by one in " << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " CPU seconds" << endl; 272 // cout << "Loaded " << trajectories.size() << " trajectories one by one in " << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " CPU seconds" << endl;
273 273
274 trajectoryDB->createViewInstants("table"); 274 trajectoryDB->createInstants("table");
275 275
276 unsigned int maxTrajectoryLength; 276 unsigned int maxTrajectoryLength = 0;
277 trajectoryDB->maxTrajectoryLength(maxTrajectoryLength); 277 success = trajectoryDB->maxTrajectoryLength(maxTrajectoryLength);
278 if (!success || maxTrajectoryLength == 0) {
279 cout << "problem with trajectory length " << success << endl;
280 exit(0);
281 }
278 cout << "Longest trajectory: " << maxTrajectoryLength << endl; 282 cout << "Longest trajectory: " << maxTrajectoryLength << endl;
279 283
280 // alternative: read and load features in batches directly select * from positions where trajectory_id in select trajectory_id from positions where frame_number <100 and frame_number > 50 group by trajectory_id 284 // alternative: read and load features in batches directly select * from positions where trajectory_id in select trajectory_id from positions where frame_number <100 and frame_number > 50 group by trajectory_id
281 int queryIntervalLength = 10; 285 int queryIntervalLength = 10;
282 286
283 FeatureGraph featureGraph(params.mmConnectionDistance, params.mmSegmentationDistance, params.minFeatureTime, params.minNFeaturesPerGroup); 287 FeatureGraph featureGraph(params.mmConnectionDistance, params.mmSegmentationDistance, params.minFeatureTime, params.minNFeaturesPerGroup);
284 288
285 // main loop 289 // main loop
286 for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)); frameNum ++) { // frameNum += queryIntervalLength // interval = frameNum, min(frameNum+queryIntervalLength, frameNum+params.nFrames) // stop if no trajectory available ? problem if nothing moves, timeout, get max of trajectory frame numbers 290 int frameNum;
291 unsigned int firstFrameNum, lastFrameNum;
292 trajectoryDB->firstLastInstants(firstFrameNum, lastFrameNum);
293 firstFrameNum = MAX(firstFrameNum, params.frame1);
294 if (params.nFrames>0)
295 lastFrameNum = MIN(lastFrameNum,params.frame1+params.nFrames);
296 for (frameNum = firstFrameNum; frameNum<lastFrameNum; frameNum ++) {
287 vector<int> trajectoryIds; 297 vector<int> trajectoryIds;
288 success = trajectoryDB->trajectoryIdEndingAt(trajectoryIds, frameNum); // ending 298 success = trajectoryDB->trajectoryIdEndingAt(trajectoryIds, frameNum); // ending
289 cout << "frame " << frameNum << endl; 299 if (frameNum%100 ==0)
300 cout << "frame " << frameNum << endl;
290 //success = trajectoryDB->trajectoryIdInInterval(trajectoryIds, frameNum, min(frameNum+queryIntervalLength-1, frameNum+params.nFrames)); // ending 301 //success = trajectoryDB->trajectoryIdInInterval(trajectoryIds, frameNum, min(frameNum+queryIntervalLength-1, frameNum+params.nFrames)); // ending
291 #if DEBUG 302 #if DEBUG
292 cout << trajectoryIds.size() << " trajectories " << endl; 303 cout << trajectoryIds.size() << " trajectories " << endl;
293 #endif 304 #endif
294 // vector<TrajectoryPoint2fPtr> positions, velocities; 305 // vector<TrajectoryPoint2fPtr> positions, velocities;
305 // cout << ft->getFirstInstant() << " " << ft->getLastInstant() << endl; 316 // cout << ft->getFirstInstant() << " " << ft->getLastInstant() << endl;
306 featureGraph.addFeature(ft); 317 featureGraph.addFeature(ft);
307 } 318 }
308 319
309 // check for connected components 320 // check for connected components
310 featureGraph.connectedComponents(frameNum+params.minFeatureTime); 321 int lastInstant = frameNum+params.minFeatureTime-maxTrajectoryLength;
311 vector<vector<unsigned int> > featureGroups = featureGraph.getFeatureGroups(); 322 if (lastInstant > 0) {
312 for (unsigned int i=0; i<featureGroups.size(); ++i) { 323 featureGraph.connectedComponents(lastInstant);
313 trajectoryDB->writeObject(savedObjectId, featureGroups[i], -1, 1, string("objects"), string("objects_features")); 324 vector<vector<unsigned int> > featureGroups = featureGraph.getFeatureGroups();
314 savedObjectId++; 325 for (unsigned int i=0; i<featureGroups.size(); ++i) {
326 trajectoryDB->writeObject(savedObjectId, featureGroups[i], -1, 1, string("objects"), string("objects_features"));
327 savedObjectId++;
328 }
315 } 329 }
316 330
317 cout << featureGraph.informationString() << endl; 331 if (frameNum%100 ==0)
332 cout << featureGraph.informationString() << endl;
333 }
334
335 // save remaining objects
336 featureGraph.connectedComponents(frameNum+maxTrajectoryLength+1);
337 vector<vector<unsigned int> > featureGroups = featureGraph.getFeatureGroups();
338 for (unsigned int i=0; i<featureGroups.size(); ++i) {
339 trajectoryDB->writeObject(savedObjectId, featureGroups[i], -1, 1, string("objects"), string("objects_features"));
340 savedObjectId++;
318 } 341 }
319 342
320 trajectoryDB->endTransaction(); 343 trajectoryDB->endTransaction();
321 trajectoryDB->disconnect(); 344 trajectoryDB->disconnect();
322 } 345 }