Mercurial > hg > nsaunier > traffic-intelligence
comparison c/feature-based-tracking.cpp @ 169:5f705809d37a
created groupFeatures function
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Sat, 01 Oct 2011 08:28:13 -0400 |
| parents | 6ec7f6c61daf |
| children | e508bb0cbb64 |
comparison
equal
deleted
inserted
replaced
| 168:6ec7f6c61daf | 169:5f705809d37a |
|---|---|
| 235 | 235 |
| 236 trajectoryDB->endTransaction(); | 236 trajectoryDB->endTransaction(); |
| 237 trajectoryDB->disconnect(); | 237 trajectoryDB->disconnect(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void groupFeatures(const KLTFeatureTrackingParameters& params) { | |
| 241 cout << "group" << endl; | |
| 242 | |
| 243 boost::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>()); | |
| 244 //TODO write generic methods for blob and list versions TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>(); | |
| 245 bool success = trajectoryDB->connect(params.databaseFilename.c_str()); | |
| 246 vector<boost::shared_ptr<Trajectory<Point2f> > > trajectories; | |
| 247 cout << trajectories.size() << endl; | |
| 248 success = trajectoryDB->read(trajectories, "positions"); // TODO load velocities as well | |
| 249 cout << "Loaded " << trajectories.size() << " trajectories" << endl; | |
| 250 // for (int i=0; i<5; ++i) { | |
| 251 // stringstream ss; | |
| 252 // ss << *trajectories[i]; | |
| 253 // cout << ss.str() << endl; | |
| 254 // } | |
| 255 | |
| 256 // create views for first and last instants for each trajectory | |
| 257 // CREATE VIEW IF NOT EXISTS trajectory_first_instants AS select trajectory_id, min(frame_number) as first_instant from positions group by trajectory_id | |
| 258 // CREATE VIEW IF NOT EXISTS trajectory_last_instants AS select trajectory_id, max(frame_number) as last_instant from positions group by trajectory_id | |
| 259 //select trajectory_id from trajectory_first_instants where first_instant = 49 | |
| 260 | |
| 261 trajectoryDB->createViewInstants("first"); | |
| 262 trajectoryDB->createViewInstants("last"); | |
| 263 | |
| 264 // main loop | |
| 265 // TODO version que l'on peut interrompre ? | |
| 266 for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)); frameNum++) { | |
| 267 vector<int> ids; | |
| 268 cout << "frame " << frameNum << " " << trajectoryDB->trajectoryIdStartingAt(ids, frameNum) << endl; | |
| 269 BOOST_FOREACH(int i, ids) | |
| 270 cout << i << " "; | |
| 271 cout << endl; | |
| 272 } | |
| 273 | |
| 274 trajectoryDB->endTransaction(); | |
| 275 trajectoryDB->disconnect(); | |
| 276 } | |
| 277 | |
| 240 int main(int argc, char *argv[]) { | 278 int main(int argc, char *argv[]) { |
| 241 // BriefDescriptorExtractor brief(32); | 279 // BriefDescriptorExtractor brief(32); |
| 242 // const int DESIRED_FTRS = 500; | 280 // const int DESIRED_FTRS = 500; |
| 243 // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); | 281 // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); |
| 244 | 282 |
| 245 KLTFeatureTrackingParameters params(argc, argv); | 283 KLTFeatureTrackingParameters params(argc, argv); |
| 246 cout << params.parameterDescription << endl; | 284 cout << params.parameterDescription << endl; |
| 247 | 285 |
| 248 if (params.trackFeatures) | 286 if (params.trackFeatures) |
| 249 trackFeatures(params); | 287 trackFeatures(params); |
| 250 else if (params.groupFeatures) { | 288 else if (params.groupFeatures) |
| 251 cout << "group" << endl; | 289 groupFeatures(params); |
| 252 | |
| 253 boost::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>()); | |
| 254 //TODO write generic methods for blob and list versions TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>(); | |
| 255 bool success = trajectoryDB->connect(params.databaseFilename.c_str()); | |
| 256 vector<boost::shared_ptr<Trajectory<Point2f> > > trajectories; | |
| 257 cout << trajectories.size() << endl; | |
| 258 success = trajectoryDB->read(trajectories, "positions"); | |
| 259 cout << trajectories.size() << endl; | |
| 260 for (int i=0; i<5; ++i) { | |
| 261 stringstream ss; | |
| 262 ss << *trajectories[i]; | |
| 263 cout << ss.str() << endl; | |
| 264 } | |
| 265 | |
| 266 // create views for first and last instants for each trajectory | |
| 267 // CREATE VIEW IF NOT EXISTS trajectory_first_instants AS select trajectory_id, min(frame_number) as first_instant from positions group by trajectory_id | |
| 268 // CREATE VIEW IF NOT EXISTS trajectory_last_instants AS select trajectory_id, max(frame_number) as last_instant from positions group by trajectory_id | |
| 269 //select trajectory_id from trajectory_first_instants where first_instant = 49 | |
| 270 | |
| 271 trajectoryDB->createViewInstants("first"); | |
| 272 trajectoryDB->createViewInstants("last"); | |
| 273 | |
| 274 // main loop | |
| 275 // TODO version que l'on peut interrompre ? | |
| 276 for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)); frameNum++) { | |
| 277 vector<int> ids; | |
| 278 cout << "frame " << frameNum << " " << trajectoryDB->trajectoryIdStartingAt(ids, frameNum) << endl; | |
| 279 BOOST_FOREACH(int i, ids) | |
| 280 cout << i << " "; | |
| 281 cout << endl; | |
| 282 } | |
| 283 | |
| 284 trajectoryDB->endTransaction(); | |
| 285 trajectoryDB->disconnect(); | |
| 286 } | |
| 287 | 290 |
| 288 return 0; | 291 return 0; |
| 289 } | 292 } |
| 290 | 293 |
| 291 /* ------------------ DOCUMENTATION ------------------ */ | 294 /* ------------------ DOCUMENTATION ------------------ */ |
