Mercurial > hg > nsaunier > traffic-intelligence
comparison c/feature-based-tracking.cpp @ 164:76610dcf3b8d
added test code to read trajectories
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 28 Sep 2011 13:27:20 -0400 |
| parents | cde87a07eb58 |
| children | 50964af05a80 |
comparison
equal
deleted
inserted
replaced
| 163:cde87a07eb58 | 164:76610dcf3b8d |
|---|---|
| 58 BOOST_FOREACH(FeatureTrajectoryPtr f, features) f->write(db, positionsTableName, velocitiesTableName); | 58 BOOST_FOREACH(FeatureTrajectoryPtr f, features) f->write(db, positionsTableName, velocitiesTableName); |
| 59 features.clear(); | 59 features.clear(); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 int main(int argc, char *argv[]) { | 63 void trackFeatures(const KLTFeatureTrackingParameters& params) { |
| 64 // BriefDescriptorExtractor brief(32); | |
| 65 // const int DESIRED_FTRS = 500; | |
| 66 // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); | |
| 67 | |
| 68 VideoCapture capture; | |
| 69 Mat frame, currentFrameBW, previousFrameBW; | |
| 70 | |
| 71 KLTFeatureTrackingParameters params(argc, argv); | |
| 72 cout << params.parameterDescription << endl; | |
| 73 | |
| 74 Mat homography = ::loadMat(params.homographyFilename, " "); | 64 Mat homography = ::loadMat(params.homographyFilename, " "); |
| 75 Mat invHomography; | 65 Mat invHomography; |
| 76 if (params.display && !homography.empty()) | 66 if (params.display && !homography.empty()) |
| 77 invHomography = homography.inv(); | 67 invHomography = homography.inv(); |
| 78 | 68 |
| 102 // for (int i=0; i<params.frame1; i++) | 92 // for (int i=0; i<params.frame1; i++) |
| 103 // capture >> frame; | 93 // capture >> frame; |
| 104 // } | 94 // } |
| 105 // } | 95 // } |
| 106 | 96 |
| 97 VideoCapture capture; | |
| 107 capture.open(params.videoFilename); | 98 capture.open(params.videoFilename); |
| 108 if(capture.isOpened()) { | 99 if(capture.isOpened()) { |
| 109 videoSize = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT)); | 100 videoSize = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT)); |
| 110 cout << "Video " << params.videoFilename << | 101 cout << "Video " << params.videoFilename << |
| 111 ": width=" << videoSize.width << | 102 ": width=" << videoSize.width << |
| 144 | 135 |
| 145 FeatureGraph graph(params.mmConnectionDistance, params.mmSegmentationDistance); | 136 FeatureGraph graph(params.mmConnectionDistance, params.mmSegmentationDistance); |
| 146 | 137 |
| 147 int key = '?'; | 138 int key = '?'; |
| 148 unsigned int savedFeatureId=0; | 139 unsigned int savedFeatureId=0; |
| 140 Mat frame, currentFrameBW, previousFrameBW; | |
| 149 for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)) && !::interruptionKey(key); frameNum++) { | 141 for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)) && !::interruptionKey(key); frameNum++) { |
| 150 capture >> frame; | 142 capture >> frame; |
| 151 cout << frameNum << " " << capture.get(CV_CAP_PROP_POS_FRAMES) << " " << prevPts.size() << endl; | 143 cout << frameNum << " " << capture.get(CV_CAP_PROP_POS_FRAMES) << " " << prevPts.size() << endl; |
| 152 int emptyFrameNum = 0; | 144 int emptyFrameNum = 0; |
| 153 while (frame.empty()) { | 145 while (frame.empty()) { |
| 241 //currDesc.copyTo(prevDesc); | 233 //currDesc.copyTo(prevDesc); |
| 242 } | 234 } |
| 243 | 235 |
| 244 trajectoryDB->endTransaction(); | 236 trajectoryDB->endTransaction(); |
| 245 trajectoryDB->disconnect(); | 237 trajectoryDB->disconnect(); |
| 238 } | |
| 239 | |
| 240 int main(int argc, char *argv[]) { | |
| 241 // BriefDescriptorExtractor brief(32); | |
| 242 // const int DESIRED_FTRS = 500; | |
| 243 // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); | |
| 244 | |
| 245 KLTFeatureTrackingParameters params(argc, argv); | |
| 246 cout << params.parameterDescription << endl; | |
| 247 | |
| 248 if (params.trackFeatures) | |
| 249 trackFeatures(params); | |
| 250 else if (params.groupFeatures) { | |
| 251 cout << "group" << endl; | |
| 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 cout << trajectories[0]->size() << endl; | |
| 261 //cout << trajectories[0]->getPoint(0) << endl; | |
| 262 trajectoryDB->endTransaction(); | |
| 263 trajectoryDB->disconnect(); | |
| 264 } | |
| 265 | |
| 246 return 0; | 266 return 0; |
| 247 } | 267 } |
| 248 | 268 |
| 249 | |
| 250 /* ------------------ DOCUMENTATION ------------------ */ | 269 /* ------------------ DOCUMENTATION ------------------ */ |
| 251 | 270 |
| 252 | 271 |
| 253 /*! \mainpage | 272 /*! \mainpage |
| 254 | 273 |
