Mercurial Hosting > traffic-intelligence
comparison c/feature-based-tracking.cpp @ 401:b829ebdc18e6
simplified input of directories of video frames (simply use the video filename parameter to point at the directory)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 29 Jul 2013 18:58:05 -0400 |
parents | 7ef1071e3cc3 |
children | 31604ef1cad4 |
comparison
equal
deleted
inserted
replaced
400:7ef1071e3cc3 | 401:b829ebdc18e6 |
---|---|
14 #include "opencv2/highgui/highgui.hpp" | 14 #include "opencv2/highgui/highgui.hpp" |
15 #include "opencv2/objdetect/objdetect.hpp" | 15 #include "opencv2/objdetect/objdetect.hpp" |
16 | 16 |
17 #include <boost/shared_ptr.hpp> | 17 #include <boost/shared_ptr.hpp> |
18 #include <boost/foreach.hpp> | 18 #include <boost/foreach.hpp> |
19 #include <boost/filesystem.hpp> | |
19 | 20 |
20 #include "InputVideoFileModule.h" | 21 #include "InputVideoFileModule.h" |
21 #include "InputFrameListModule.h" | 22 #include "InputFrameListModule.h" |
22 | |
23 | 23 |
24 #include <iostream> | 24 #include <iostream> |
25 #include <vector> | 25 #include <vector> |
26 #include <ctime> | 26 #include <ctime> |
27 | 27 |
28 using namespace std; | 28 using namespace std; |
29 using namespace cv; | 29 using namespace cv; |
30 namespace fs = boost::filesystem; | |
30 | 31 |
31 void drawMatchesRelative(const vector<KeyPoint>& train, const vector<KeyPoint>& query, std::vector<cv::DMatch>& matches, Mat& img) { | 32 void drawMatchesRelative(const vector<KeyPoint>& train, const vector<KeyPoint>& query, std::vector<cv::DMatch>& matches, Mat& img) { |
32 for (int i = 0; i < (int)matches.size(); i++) | 33 for (int i = 0; i < (int)matches.size(); i++) |
33 { | 34 { |
34 Point2f pt_new = query[matches[i].queryIdx].pt; | 35 Point2f pt_new = query[matches[i].queryIdx].pt; |
80 Size window = Size(params.windowSize, params.windowSize); | 81 Size window = Size(params.windowSize, params.windowSize); |
81 | 82 |
82 // BruteForceMatcher<Hamming> descMatcher; | 83 // BruteForceMatcher<Hamming> descMatcher; |
83 // vector<DMatch> matches; | 84 // vector<DMatch> matches; |
84 | 85 |
85 InputFrameProviderIface* capture = 0; | 86 boost::shared_ptr<InputFrameProviderIface> capture; |
86 if(!params.listFilename.empty() && !params.folderData.empty()) | 87 if (fs::is_directory(fs::path(params.videoFilename))) |
87 capture = new InputFrameListModule(params.folderData, params.listFilename); | 88 capture = boost::shared_ptr<InputFrameListModule>(new InputFrameListModule(params.videoFilename)); |
88 else if(!params.videoFilename.empty()) | 89 else if(!params.videoFilename.empty()) |
89 capture = new InputVideoFileModule(params.videoFilename); | 90 capture = boost::shared_ptr<InputVideoFileModule>(new InputVideoFileModule(params.videoFilename)); |
90 else | 91 else |
91 cout << "No valid input parameters"; | 92 cout << "No valid input parameters" << endl; |
92 | 93 |
93 if(!capture->isOpen()) { | 94 if(!capture->isOpen()) { |
94 cout << "Video filename " << params.videoFilename << " could not be opened. Exiting." << endl; | 95 cout << "Video filename " << params.videoFilename << " could not be opened. Exiting." << endl; |
95 exit(0); | 96 exit(0); |
96 } | 97 } |
122 Mat prevDesc, currDesc; | 123 Mat prevDesc, currDesc; |
123 | 124 |
124 std::vector<FeatureTrajectoryPtr> lostFeatures; | 125 std::vector<FeatureTrajectoryPtr> lostFeatures; |
125 std::vector<FeaturePointMatch> featurePointMatches; | 126 std::vector<FeaturePointMatch> featurePointMatches; |
126 | 127 |
127 HOGDescriptor hog; | 128 //HOGDescriptor hog; |
128 hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); | 129 //hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); |
129 | 130 |
130 int key = '?'; | 131 int key = '?'; |
131 unsigned int savedFeatureId=0; | 132 unsigned int savedFeatureId=0; |
132 Mat frame = Mat::zeros(1, 1, CV_8UC1), currentFrameBW, previousFrameBW; | 133 Mat frame = Mat::zeros(1, 1, CV_8UC1), currentFrameBW, previousFrameBW; |
133 | 134 |
231 //::keyPoints2Points(currKpts, currPts, false); | 232 //::keyPoints2Points(currKpts, currPts, false); |
232 | 233 |
233 //brief.compute(currentFrameBW, currKpts, currDesc); //Compute brief descriptors at each keypoint location | 234 //brief.compute(currentFrameBW, currKpts, currDesc); //Compute brief descriptors at each keypoint location |
234 | 235 |
235 if (params.display) { | 236 if (params.display) { |
237 imshow("mask", featureMask*256); | |
236 imshow("frame", frame); | 238 imshow("frame", frame); |
237 imshow("mask", featureMask*256); | |
238 key = waitKey(2); | 239 key = waitKey(2); |
239 } | 240 } |
240 previousFrameBW = currentFrameBW.clone(); | 241 previousFrameBW = currentFrameBW.clone(); |
241 prevPts = currPts; | 242 prevPts = currPts; |
242 //prevKpts = currKpts; | 243 //prevKpts = currKpts; |
243 //currDesc.copyTo(prevDesc); | 244 //currDesc.copyTo(prevDesc); |
244 } | 245 } |
245 | 246 |
246 trajectoryDB->endTransaction(); | 247 trajectoryDB->endTransaction(); |
247 trajectoryDB->disconnect(); | 248 trajectoryDB->disconnect(); |
248 delete capture; | |
249 | |
250 } | 249 } |
251 | 250 |
252 void groupFeatures(const KLTFeatureTrackingParameters& params) { | 251 void groupFeatures(const KLTFeatureTrackingParameters& params) { |
253 boost::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>()); | 252 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>(); | 253 //TODO write generic methods for blob and list versions TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>(); |