Mercurial Hosting > traffic-intelligence
comparison c/feature-based-tracking.cpp @ 222:426321b46e44
temporary trajectory instants table
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 26 Jun 2012 02:08:01 -0400 |
parents | bc93e87a2108 |
children | d4d3b1e8a9f1 |
comparison
equal
deleted
inserted
replaced
221:bc93e87a2108 | 222:426321b46e44 |
---|---|
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(); | 274 trajectoryDB->createViewInstants("table"); |
275 | 275 |
276 // unsigned int maxTrajectoryLength; | 276 unsigned int maxTrajectoryLength; |
277 // // trajectoryDB->maxTrajectoryLength(maxTrajectoryLength); | 277 trajectoryDB->maxTrajectoryLength(maxTrajectoryLength); |
278 cout << "Longest trajectory: " << maxTrajectoryLength << endl; | |
278 | 279 |
279 // 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 | 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 |
280 int queryIntervalLength = 100; | 281 int queryIntervalLength = 10; |
281 | 282 |
282 FeatureGraph featureGraph(params.mmConnectionDistance, params.mmSegmentationDistance, params.minFeatureTime, params.minNFeaturesPerGroup); | 283 FeatureGraph featureGraph(params.mmConnectionDistance, params.mmSegmentationDistance, params.minFeatureTime, params.minNFeaturesPerGroup); |
283 | 284 |
284 // main loop | 285 // main loop |
285 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 | 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 |
286 vector<int> trajectoryIds; | 287 vector<int> trajectoryIds; |
287 success = trajectoryDB->trajectoryIdEndingAt(trajectoryIds, frameNum); // ending | 288 success = trajectoryDB->trajectoryIdEndingAt(trajectoryIds, frameNum); // ending |
288 cout << "frame " << frameNum << " " << success << endl; | 289 cout << "frame " << frameNum << endl; |
290 //success = trajectoryDB->trajectoryIdInInterval(trajectoryIds, frameNum, min(frameNum+queryIntervalLength-1, frameNum+params.nFrames)); // ending | |
291 #if DEBUG | |
289 cout << trajectoryIds.size() << " trajectories " << endl; | 292 cout << trajectoryIds.size() << " trajectories " << endl; |
293 #endif | |
294 // vector<TrajectoryPoint2fPtr> positions, velocities; | |
295 // trajectoryDB->read(positions, trajectoryIds, "positions"); | |
296 // trajectoryDB->read(velocities, trajectoryIds, "velocities"); | |
297 // for (unsigned int i=0; i<trajectoryIds.size(); ++i) { | |
298 // FeatureTrajectoryPtr ft = FeatureTrajectoryPtr(new FeatureTrajectory(positions[i], velocities[i])); | |
290 BOOST_FOREACH(int trajectoryId, trajectoryIds) { | 299 BOOST_FOREACH(int trajectoryId, trajectoryIds) { |
291 //cout << trajectoryId << " " << endl; | 300 //cout << trajectoryId << " " << endl; |
292 // boost::shared_ptr<Trajectory<cv::Point2f> > trajectory; | 301 // boost::shared_ptr<Trajectory<cv::Point2f> > trajectory; |
293 // success = trajectoryDB->read(trajectory, trajectoryId, "positions"); // velocities | 302 // success = trajectoryDB->read(trajectory, trajectoryId, "positions"); // velocities |
294 FeatureTrajectoryPtr ft = FeatureTrajectoryPtr(new FeatureTrajectory(trajectoryId, *trajectoryDB, "positions", "velocities")); | 303 FeatureTrajectoryPtr ft = FeatureTrajectoryPtr(new FeatureTrajectory(trajectoryId, *trajectoryDB, "positions", "velocities")); |
295 // stringstream ss;ss << *ft; cout << ss.str() << endl; | 304 // stringstream ss;ss << *ft; cout << ss.str() << endl; |
296 // cout << ft->getFirstInstant() << " " << ft->getLastInstant() << endl; | 305 // cout << ft->getFirstInstant() << " " << ft->getLastInstant() << endl; |
297 featureGraph.addFeature(ft); | 306 featureGraph.addFeature(ft); |
298 } | 307 } |
299 | 308 |
300 // check for connected components that are old enough (no chance to match with trajectories to be added later | 309 // check for connected components |
301 // we could check only when some features are getting old enough? | 310 featureGraph.connectedComponents(frameNum+params.minFeatureTime); |
302 if (frameNum%10 == 0) { | 311 vector<vector<unsigned int> > featureGroups = featureGraph.getFeatureGroups(); |
303 featureGraph.connectedComponents(frameNum+params.minFeatureTime); | 312 for (unsigned int i=0; i<featureGroups.size(); ++i) { |
304 vector<vector<unsigned int> > featureGroups = featureGraph.getFeatureGroups(); | 313 trajectoryDB->writeObject(savedObjectId, featureGroups[i], -1, 1, string("objects"), string("objects_features")); |
305 for (unsigned int i=0; i<featureGroups.size(); ++i) { | 314 savedObjectId++; |
306 trajectoryDB->writeObject(savedObjectId, featureGroups[i], -1, 1, string("objects"), string("objects_features")); | |
307 savedObjectId++; | |
308 } | |
309 } | 315 } |
310 | 316 |
311 cout << featureGraph.informationString() << endl; | 317 cout << featureGraph.informationString() << endl; |
312 } | 318 } |
313 | 319 |
314 trajectoryDB->endTransaction(); | 320 trajectoryDB->endTransaction(); |
315 trajectoryDB->disconnect(); | 321 trajectoryDB->disconnect(); |