Mercurial Hosting > traffic-intelligence
comparison c/feature-based-tracking.cpp @ 230:bc4ea09b1743
compatibility modifications for visual studio compilation
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 29 Jun 2012 16:15:13 -0400 |
parents | 48f83ff769fd |
children | 249d65ff6c35 |
comparison
equal
deleted
inserted
replaced
207:48f83ff769fd | 230:bc4ea09b1743 |
---|---|
74 | 74 |
75 float minTotalFeatureDisplacement = params.nDisplacements*params.minFeatureDisplacement; | 75 float minTotalFeatureDisplacement = params.nDisplacements*params.minFeatureDisplacement; |
76 Size window = Size(params.windowSize, params.windowSize); | 76 Size window = Size(params.windowSize, params.windowSize); |
77 | 77 |
78 // BruteForceMatcher<Hamming> descMatcher; | 78 // BruteForceMatcher<Hamming> descMatcher; |
79 // vector<DMatch> matches; | 79 // std::vector<DMatch> matches; |
80 Size videoSize; | 80 Size videoSize; |
81 | 81 |
82 // if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) // if no parameter or number parameter | 82 // if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) // if no parameter or number parameter |
83 // capture.open(argc == 2 ? argv[1][0] - '0' : 0); | 83 // capture.open(argc == 2 ? argv[1][0] - '0' : 0); |
84 // else if( argc >= 2 ) | 84 // else if( argc >= 2 ) |
128 trajectoryDB->connect(params.databaseFilename.c_str()); | 128 trajectoryDB->connect(params.databaseFilename.c_str()); |
129 trajectoryDB->createTable("positions"); | 129 trajectoryDB->createTable("positions"); |
130 trajectoryDB->createTable("velocities"); | 130 trajectoryDB->createTable("velocities"); |
131 trajectoryDB->beginTransaction(); | 131 trajectoryDB->beginTransaction(); |
132 | 132 |
133 vector<KeyPoint> prevKpts, currKpts; | 133 std::vector<KeyPoint> prevKpts, currKpts; |
134 vector<Point2f> prevPts, currPts, newPts; | 134 std::vector<Point2f> prevPts, currPts, newPts; |
135 vector<uchar> status; | 135 std::vector<uchar> status; |
136 vector<float> errors; | 136 std::vector<float> errors; |
137 Mat prevDesc, currDesc; | 137 Mat prevDesc, currDesc; |
138 | 138 |
139 vector<FeatureTrajectoryPtr> lostFeatures; | 139 std::vector<FeatureTrajectoryPtr> lostFeatures; |
140 vector<FeaturePointMatch> featurePointMatches; | 140 std::vector<FeaturePointMatch> featurePointMatches; |
141 | 141 |
142 HOGDescriptor hog; | 142 HOGDescriptor hog; |
143 hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); | 143 hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); |
144 | 144 |
145 int key = '?'; | 145 int key = '?'; |
156 if (emptyFrameNum>=3000) | 156 if (emptyFrameNum>=3000) |
157 exit(0); | 157 exit(0); |
158 } | 158 } |
159 | 159 |
160 cvtColor(frame, currentFrameBW, CV_RGB2GRAY); | 160 cvtColor(frame, currentFrameBW, CV_RGB2GRAY); |
161 | |
162 // "normal" feature detectors: detect features here | 161 // "normal" feature detectors: detect features here |
163 // detector.detect(currentFrameBW, currKpts); // see video_homography c++ sample | 162 // detector.detect(currentFrameBW, currKpts); // see video_homography c++ sample |
164 | 163 |
165 if (!prevPts.empty()) { | 164 if (!prevPts.empty()) { |
166 //::keyPoints2Points(prevKpts, prevPts); | 165 //::keyPoints2Points(prevKpts, prevPts); |
167 currPts.clear(); | 166 currPts.clear(); |
168 calcOpticalFlowPyrLK(previousFrameBW, currentFrameBW, prevPts, currPts, status, errors, window, params.pyramidLevel, TermCriteria(3 /*static_cast<int>(TermCriteria::COUNT)+static_cast<int>(TermCriteria::EPS)*/, params.maxNumberTrackingIterations, params.minTrackingError), 0.5 /* unused */, 0); // OPTFLOW_USE_INITIAL_FLOW | 167 calcOpticalFlowPyrLK(previousFrameBW, currentFrameBW, prevPts, currPts, status, errors, window, params.pyramidLevel, TermCriteria(3 /*static_cast<int>(TermCriteria::COUNT)+static_cast<int>(TermCriteria::EPS)*/, params.maxNumberTrackingIterations, params.minTrackingError), 0.5 /* unused */, 0); // OPTFLOW_USE_INITIAL_FLOW |
169 /// \todo try calcOpticalFlowFarneback | 168 /// \todo try calcOpticalFlowFarneback |
170 | 169 |
171 vector<Point2f> trackedPts; | 170 std::vector<Point2f> trackedPts; |
172 vector<FeaturePointMatch>::iterator iter = featurePointMatches.begin(); | 171 std::vector<FeaturePointMatch>::iterator iter = featurePointMatches.begin(); |
173 while (iter != featurePointMatches.end()) { | 172 while (iter != featurePointMatches.end()) { |
174 bool deleteFeature = false; | 173 bool deleteFeature = false; |
175 | 174 |
176 if (status[iter->pointNum]) { | 175 if (status[iter->pointNum]) { |
177 iter->feature->addPoint(frameNum, currPts[iter->pointNum], homography); | 176 iter->feature->addPoint(frameNum, currPts[iter->pointNum], homography); |
282 FeatureGraph featureGraph(params.mmConnectionDistance, params.mmSegmentationDistance, params.minFeatureTime, params.minNFeaturesPerGroup); | 281 FeatureGraph featureGraph(params.mmConnectionDistance, params.mmSegmentationDistance, params.minFeatureTime, params.minNFeaturesPerGroup); |
283 | 282 |
284 // main loop | 283 // main loop |
285 // TODO version that can be interrupted? | 284 // TODO version that can be interrupted? |
286 for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)); frameNum++) { | 285 for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)); frameNum++) { |
287 vector<int> trajectoryIds; | 286 std::vector<int> trajectoryIds; |
288 success = trajectoryDB->trajectoryIdEndingAt(trajectoryIds, frameNum); // ending | 287 success = trajectoryDB->trajectoryIdEndingAt(trajectoryIds, frameNum); // ending |
289 cout << "frame " << frameNum << " " << success << endl; | 288 cout << "frame " << frameNum << " " << success << endl; |
290 cout << trajectoryIds.size() << " trajectories " << endl; | 289 cout << trajectoryIds.size() << " trajectories " << endl; |
291 BOOST_FOREACH(int trajectoryId, trajectoryIds) { | 290 BOOST_FOREACH(int trajectoryId, trajectoryIds) { |
292 //cout << trajectoryId << " " << endl; | 291 //cout << trajectoryId << " " << endl; |
300 | 299 |
301 // check for connected components that are old enough (no chance to match with trajectories to be added later | 300 // check for connected components that are old enough (no chance to match with trajectories to be added later |
302 // we could check only when some features are getting old enough? | 301 // we could check only when some features are getting old enough? |
303 if (frameNum%10 == 0) { | 302 if (frameNum%10 == 0) { |
304 featureGraph.connectedComponents(frameNum-maxTrajectoryLength+params.minFeatureTime); | 303 featureGraph.connectedComponents(frameNum-maxTrajectoryLength+params.minFeatureTime); |
305 vector<vector<unsigned int> > featureGroups = featureGraph.getFeatureGroups(); | 304 std::vector<vector<unsigned int> > featureGroups = featureGraph.getFeatureGroups(); |
306 for (unsigned int i=0; i<featureGroups.size(); ++i) { | 305 for (unsigned int i=0; i<featureGroups.size(); ++i) { |
307 trajectoryDB->writeObject(savedObjectId, featureGroups[i], -1, 1, string("objects"), string("objects_features")); | 306 trajectoryDB->writeObject(savedObjectId, featureGroups[i], -1, 1, string("objects"), string("objects_features")); |
308 savedObjectId++; | 307 savedObjectId++; |
309 } | 308 } |
310 } | 309 } |
317 } | 316 } |
318 | 317 |
319 int main(int argc, char *argv[]) { | 318 int main(int argc, char *argv[]) { |
320 KLTFeatureTrackingParameters params(argc, argv); | 319 KLTFeatureTrackingParameters params(argc, argv); |
321 cout << params.parameterDescription << endl; | 320 cout << params.parameterDescription << endl; |
322 | 321 params.trackFeatures = true; |
323 if (params.trackFeatures) | 322 if (params.trackFeatures) |
324 trackFeatures(params); | 323 trackFeatures(params); |
325 else if (params.groupFeatures) | 324 else if (params.groupFeatures) |
326 groupFeatures(params); | 325 groupFeatures(params); |
327 | 326 |