Mercurial Hosting > traffic-intelligence
comparison c/feature-based-tracking.cpp @ 1093:05ccd8ef150c
updated to OpenCV4
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sat, 02 Feb 2019 09:33:26 -0500 |
parents | 9fb82fe0156f |
children | 164dab203037 |
comparison
equal
deleted
inserted
replaced
1092:49c0bb6eacc2 | 1093:05ccd8ef150c |
---|---|
5 | 5 |
6 #include "src/Trajectory.h" | 6 #include "src/Trajectory.h" |
7 #include "src/TrajectoryDBAccessList.h" | 7 #include "src/TrajectoryDBAccessList.h" |
8 #include "src/TrajectoryDBAccessBlob.h" | 8 #include "src/TrajectoryDBAccessBlob.h" |
9 | 9 |
10 #include "opencv2/core/core.hpp" | 10 #include "opencv2/core.hpp" |
11 #include "opencv2/imgproc/imgproc.hpp" | 11 #include "opencv2/imgproc.hpp" |
12 #include "opencv2/video/tracking.hpp" | 12 #include "opencv2/video/tracking.hpp" |
13 #include "opencv2/features2d/features2d.hpp" | 13 #include "opencv2/features2d.hpp" |
14 #include "opencv2/highgui/highgui.hpp" | 14 #include "opencv2/highgui.hpp" |
15 #include "opencv2/objdetect/objdetect.hpp" | 15 #include "opencv2/videoio.hpp" |
16 #include "opencv2/calib3d/calib3d.hpp" | 16 #include "opencv2/objdetect.hpp" |
17 #include "opencv2/calib3d.hpp" | |
17 | 18 |
18 #include <boost/foreach.hpp> | 19 #include <boost/foreach.hpp> |
19 #include <boost/filesystem.hpp> | 20 #include <boost/filesystem.hpp> |
20 | 21 |
21 #include <iostream> | 22 #include <iostream> |
99 if(!capture.isOpened()) { | 100 if(!capture.isOpened()) { |
100 cout << "Video filename " << params.videoFilename << " could not be opened. Exiting." << endl; | 101 cout << "Video filename " << params.videoFilename << " could not be opened. Exiting." << endl; |
101 exit(0); | 102 exit(0); |
102 } | 103 } |
103 | 104 |
104 Size videoSize = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT)); | 105 Size videoSize = Size(capture.get(CAP_PROP_FRAME_WIDTH), capture.get(CAP_PROP_FRAME_HEIGHT)); |
105 unsigned int nFrames = capture.get(CV_CAP_PROP_FRAME_COUNT); | 106 unsigned int nFrames = capture.get(CAP_PROP_FRAME_COUNT); |
106 if (nFrames <= 0) { | 107 if (nFrames <= 0) { |
107 cout << "Guessing that the number of frames could not be read: " << nFrames << endl; | 108 cout << "Guessing that the number of frames could not be read: " << nFrames << endl; |
108 nFrames = numeric_limits<int>::max(); | 109 nFrames = numeric_limits<int>::max(); |
109 cout << "Setting arbitrarily high number for testing: " << nFrames << endl; | 110 cout << "Setting arbitrarily high number for testing: " << nFrames << endl; |
110 } | 111 } |
152 | 153 |
153 unsigned int lastFrameNum = nFrames; | 154 unsigned int lastFrameNum = nFrames; |
154 if (params.nFrames > 0) | 155 if (params.nFrames > 0) |
155 lastFrameNum = MIN(params.frame1+static_cast<unsigned int>(params.nFrames), nFrames); | 156 lastFrameNum = MIN(params.frame1+static_cast<unsigned int>(params.nFrames), nFrames); |
156 | 157 |
157 capture.set(CV_CAP_PROP_POS_FRAMES, params.frame1); | 158 capture.set(CAP_PROP_POS_FRAMES, params.frame1); |
158 for (unsigned int frameNum = params.frame1; (frameNum < lastFrameNum) && !::interruptionKey(key); frameNum++) { | 159 for (unsigned int frameNum = params.frame1; (frameNum < lastFrameNum) && !::interruptionKey(key); frameNum++) { |
159 capture >> frame; | 160 capture >> frame; |
160 if (frame.empty()) { | 161 if (frame.empty()) { |
161 cout << "Empty frame " << frameNum << ", breaking (" << frame.empty() << " [" << frame.size().width << "x" << frame.size().height << "])" << endl; | 162 cout << "Empty frame " << frameNum << ", breaking (" << frame.empty() << " [" << frame.size().width << "x" << frame.size().height << "])" << endl; |
162 break; | 163 break; |
163 } else if (!params.quiet && (frameNum%50 ==0)) | 164 } else if (!params.quiet && (frameNum%50 ==0)) |
164 cout << "frame " << frameNum << endl; | 165 cout << "frame " << frameNum << endl; |
165 | 166 |
166 cvtColor(frame, currentFrameBW, CV_RGB2GRAY); | 167 cvtColor(frame, currentFrameBW, COLOR_RGB2GRAY); |
167 | 168 |
168 if (!prevPts.empty()) { | 169 if (!prevPts.empty()) { |
169 currPts.clear(); | 170 currPts.clear(); |
170 calcOpticalFlowPyrLK(previousFrameBW, currentFrameBW, prevPts, currPts, status, errors, window, params.pyramidLevel, TermCriteria(static_cast<int>(TermCriteria::COUNT)+static_cast<int>(TermCriteria::EPS) /* = 3 */, params.maxNumberTrackingIterations, params.minTrackingError), /* int flags = */ 0, params.minFeatureEigThreshold); | 171 calcOpticalFlowPyrLK(previousFrameBW, currentFrameBW, prevPts, currPts, status, errors, window, params.pyramidLevel, TermCriteria(static_cast<int>(TermCriteria::COUNT)+static_cast<int>(TermCriteria::EPS) /* = 3 */, params.maxNumberTrackingIterations, params.minTrackingError), /* int flags = */ 0, params.minFeatureEigThreshold); |
171 /// \todo try calcOpticalFlowFarneback | 172 /// \todo try calcOpticalFlowFarneback |