Mercurial Hosting > traffic-intelligence
comparison c/feature-based-tracking.cpp @ 399:c389fae9689a
Added a class to read list of image instead of video. This is controlled by the use of the database-filename and folder-data parameters in the config file.
author | Jean-Philippe Jodoin <jpjodoin@gmail.com> |
---|---|
date | Mon, 29 Jul 2013 17:12:45 -0400 |
parents | 03dbecd3a887 |
children | 7ef1071e3cc3 |
comparison
equal
deleted
inserted
replaced
398:3399bd48cb40 | 399:c389fae9689a |
---|---|
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 | |
20 #include "InputVideoFileModule.h" | |
21 #include "InputFrameListModule.h" | |
22 | |
19 | 23 |
20 #include <iostream> | 24 #include <iostream> |
21 #include <vector> | 25 #include <vector> |
22 #include <ctime> | 26 #include <ctime> |
23 | 27 |
76 Size window = Size(params.windowSize, params.windowSize); | 80 Size window = Size(params.windowSize, params.windowSize); |
77 | 81 |
78 // BruteForceMatcher<Hamming> descMatcher; | 82 // BruteForceMatcher<Hamming> descMatcher; |
79 // vector<DMatch> matches; | 83 // vector<DMatch> matches; |
80 | 84 |
81 VideoCapture capture; | 85 InputFrameProviderIface* capture = nullptr; |
82 Size videoSize; | 86 if(!params.listFilename.empty() && !params.folderData.empty()) |
83 unsigned int nFrames = 0; | 87 capture = new InputFrameListModule(params.folderData, params.listFilename); |
84 capture.open(params.videoFilename); | 88 else if(!params.videoFilename.empty()) |
85 if(capture.isOpened()) { | 89 capture = new InputVideoFileModule(params.videoFilename); |
86 videoSize = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT)); | 90 else |
87 nFrames = capture.get(CV_CAP_PROP_FRAME_COUNT); | 91 cout << "No valid input parameters"; |
88 cout << "Video " << params.videoFilename << | 92 |
89 ": width=" << videoSize.width << | 93 if(!capture->isOpen()) |
90 ", height=" << videoSize.height << | 94 { |
91 ", nframes=" << nFrames << endl; | 95 cout << "Video filename " << params.videoFilename << " could not be opened. Exiting." << endl; |
92 } else { | 96 exit(0); |
93 cout << "Video filename " << params.videoFilename << " could not be opened. Exiting." << endl; | 97 } |
94 exit(0); | 98 |
95 } | 99 Size videoSize = capture->getSize(); |
96 // if (!capture.isOpened()) | 100 unsigned int nFrames = capture->getNbFrames(); |
97 // { | 101 cout << "Video " << params.videoFilename << |
98 // //help(argv); | 102 ": width=" << videoSize.width << |
99 // cout << "capture device " << argv[1] << " failed to open!" << endl; | 103 ", height=" << videoSize.height << |
100 // return 1; | 104 ", nframes=" << nFrames << endl; |
101 // } | 105 |
102 | |
103 Mat mask = imread(params.maskFilename, 0); | 106 Mat mask = imread(params.maskFilename, 0); |
104 if (mask.empty()) { | 107 if (mask.empty()) { |
105 cout << "Mask filename " << params.maskFilename << " could not be opened." << endl; | 108 cout << "Mask filename " << params.maskFilename << " could not be opened." << endl; |
106 mask = Mat::ones(videoSize, CV_8UC1); | 109 mask = Mat::ones(videoSize, CV_8UC1); |
107 } | 110 } |
133 if (params.nFrames > 0) | 136 if (params.nFrames > 0) |
134 lastFrameNum = MIN(params.frame1+static_cast<unsigned int>(params.nFrames), nFrames); | 137 lastFrameNum = MIN(params.frame1+static_cast<unsigned int>(params.nFrames), nFrames); |
135 | 138 |
136 //capture.set(CV_CAP_PROP_POS_FRAMES, params.frame1); | 139 //capture.set(CV_CAP_PROP_POS_FRAMES, params.frame1); |
137 for (unsigned int frameNum = params.frame1; (frameNum < lastFrameNum) && !::interruptionKey(key); frameNum++) { | 140 for (unsigned int frameNum = params.frame1; (frameNum < lastFrameNum) && !::interruptionKey(key); frameNum++) { |
138 capture >> frame; | 141 bool success = capture->getNextFrame(frame); |
139 | 142 |
140 if (frame.empty() || frame.size() != videoSize) | 143 if (!success || frame.empty() || frame.size() != videoSize) |
141 break; | 144 break; |
142 | 145 |
143 if (frameNum%50 ==0) | 146 if (frameNum%50 ==0) |
144 cout << "frame " << frameNum << endl; | 147 cout << "frame " << frameNum << endl; |
145 | 148 |
241 //currDesc.copyTo(prevDesc); | 244 //currDesc.copyTo(prevDesc); |
242 } | 245 } |
243 | 246 |
244 trajectoryDB->endTransaction(); | 247 trajectoryDB->endTransaction(); |
245 trajectoryDB->disconnect(); | 248 trajectoryDB->disconnect(); |
249 delete capture; | |
250 | |
246 } | 251 } |
247 | 252 |
248 void groupFeatures(const KLTFeatureTrackingParameters& params) { | 253 void groupFeatures(const KLTFeatureTrackingParameters& params) { |
249 boost::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>()); | 254 boost::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>()); |
250 //TODO write generic methods for blob and list versions TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>(); | 255 //TODO write generic methods for blob and list versions TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>(); |