Mercurial > hg > nsaunier > traffic-intelligence
comparison c/feature-based-tracking.cpp @ 137:445e773c9be3
created the parameter structure to parse parameters (bug remaining)
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 19 Aug 2011 01:35:45 -0400 |
| parents | 0f790de9437e |
| children | c1b260b48d2a |
comparison
equal
deleted
inserted
replaced
| 136:0f790de9437e | 137:445e773c9be3 |
|---|---|
| 58 // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); | 58 // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); |
| 59 | 59 |
| 60 VideoCapture capture; | 60 VideoCapture capture; |
| 61 Mat frame, currentFrameBW, previousFrameBW; | 61 Mat frame, currentFrameBW, previousFrameBW; |
| 62 | 62 |
| 63 KLTFeatureTrackingParameters params; | 63 KLTFeatureTrackingParameters params(argc, argv); |
| 64 params.display = true; | 64 cout << params.parameterDescription << endl; |
| 65 params.frame1 = 0; | 65 // params.display = true; |
| 66 params.nFrames = -1; | 66 // params.frame1 = 0; |
| 67 params.maxNFeatures = 1000; | 67 // params.nFrames = -1; |
| 68 params.featureQuality = 0.1; | 68 // params.maxNFeatures = 1000; |
| 69 params.minFeatureDistanceKLT = 3; | 69 // params.featureQuality = 0.1; |
| 70 params.windowSize = 3; | 70 // params.minFeatureDistanceKLT = 3; |
| 71 params.useHarrisDetector = false; | 71 // params.windowSize = 3; |
| 72 params.k = 0.4; | 72 // params.useHarrisDetector = false; |
| 73 //GoodFeaturesToTrackDetector detector(params.maxNFeatures, params.featureQuality, params.minFeatureDistanceKLT, params.windowSize, params.useHarrisDetector, params.k); | 73 // params.k = 0.4; |
| 74 | 74 // //GoodFeaturesToTrackDetector detector(params.maxNFeatures, params.featureQuality, params.minFeatureDistanceKLT, params.windowSize, params.useHarrisDetector, params.k); |
| 75 params.pyramidLevel = 3; | 75 |
| 76 params.nDisplacements = 3; | 76 // params.pyramidLevel = 3; |
| 77 params.minFeatureDisplacement = 0.05; | 77 // params.nDisplacements = 3; |
| 78 // params.minFeatureDisplacement = 0.05; | |
| 79 | |
| 80 // params.maxNumberTrackingIterations = 20; // 30 | |
| 81 // params.minTrackingError = 0.3; // 0.01 | |
| 82 // params.minFeatureTime = 20; | |
| 83 | |
| 78 float minTotalFeatureDisplacement = params.nDisplacements*params.minFeatureDisplacement; | 84 float minTotalFeatureDisplacement = params.nDisplacements*params.minFeatureDisplacement; |
| 79 | |
| 80 params.maxNumberTrackingIterations = 20; // 30 | |
| 81 params.minTrackingError = 0.3; // 0.01 | |
| 82 params.derivLambda = 0.5; | |
| 83 params.minFeatureTime = 20; | |
| 84 | |
| 85 Size window = Size(params.windowSize, params.windowSize); | 85 Size window = Size(params.windowSize, params.windowSize); |
| 86 | 86 |
| 87 BruteForceMatcher<Hamming> descMatcher; | 87 BruteForceMatcher<Hamming> descMatcher; |
| 88 vector<DMatch> matches; | 88 vector<DMatch> matches; |
| 89 Size videoSize; | 89 Size videoSize; |
| 90 | 90 |
| 91 if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) // if no parameter or number parameter | 91 // if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) // if no parameter or number parameter |
| 92 capture.open(argc == 2 ? argv[1][0] - '0' : 0); | 92 // capture.open(argc == 2 ? argv[1][0] - '0' : 0); |
| 93 else if( argc >= 2 ) | 93 // else if( argc >= 2 ) |
| 94 { | 94 // { |
| 95 capture.open(argv[1]); | 95 // capture.open(argv[1]); |
| 96 if( capture.isOpened() ) | 96 // if( capture.isOpened() ) |
| 97 videoSize = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT)); | 97 // videoSize = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT)); |
| 98 cout << "Video " << argv[1] << | 98 // cout << "Video " << argv[1] << |
| 99 ": width=" << videoSize.width << | 99 // ": width=" << videoSize.width << |
| 100 ", height=" << videoSize.height << | 100 // ", height=" << videoSize.height << |
| 101 ", nframes=" << capture.get(CV_CAP_PROP_FRAME_COUNT) << endl; | 101 // ", nframes=" << capture.get(CV_CAP_PROP_FRAME_COUNT) << endl; |
| 102 if( argc > 2 && isdigit(argv[2][0]) ) // could be used to reach first frame, dumping library messages to log file (2> /tmp/log.txt) | 102 // if( argc > 2 && isdigit(argv[2][0]) ) // could be used to reach first frame, dumping library messages to log file (2> /tmp/log.txt) |
| 103 { | 103 // { |
| 104 sscanf(argv[2], "%d", ¶ms.frame1); | 104 // sscanf(argv[2], "%d", ¶ms.frame1); |
| 105 cout << "seeking to frame #" << params.frame1 << endl; | 105 // cout << "seeking to frame #" << params.frame1 << endl; |
| 106 //cap.set(CV_CAP_PROP_POS_FRAMES, pos); | 106 // //cap.set(CV_CAP_PROP_POS_FRAMES, pos); |
| 107 for (int i=0; i<params.frame1; i++) | 107 // for (int i=0; i<params.frame1; i++) |
| 108 capture >> frame; | 108 // capture >> frame; |
| 109 } | 109 // } |
| 110 } | 110 // } |
| 111 | 111 |
| 112 // capture.open(atoi(argv[1])); | 112 capture.open(params.videoFilename); |
| 113 if (!capture.isOpened()) | 113 if (!capture.isOpened()) |
| 114 { | 114 { |
| 115 //help(argv); | 115 //help(argv); |
| 116 cout << "capture device " << argv[1] << " failed to open!" << endl; | 116 cout << "capture device " << argv[1] << " failed to open!" << endl; |
| 117 return 1; | 117 return 1; |
| 147 // detector.detect(currentFrameBW, currKpts); // see video_homography c++ sample | 147 // detector.detect(currentFrameBW, currKpts); // see video_homography c++ sample |
| 148 | 148 |
| 149 if (!prevPts.empty()) { | 149 if (!prevPts.empty()) { |
| 150 //::keyPoints2Points(prevKpts, prevPts); | 150 //::keyPoints2Points(prevKpts, prevPts); |
| 151 currPts.clear(); | 151 currPts.clear(); |
| 152 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), params.derivLambda, 0); // OPTFLOW_USE_INITIAL_FLOW | 152 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 |
| 153 | 153 |
| 154 vector<Point2f> trackedPts; | 154 vector<Point2f> trackedPts; |
| 155 vector<FeaturePointMatch>::iterator iter = featurePointMatches.begin(); | 155 vector<FeaturePointMatch>::iterator iter = featurePointMatches.begin(); |
| 156 while (iter != featurePointMatches.end()) { | 156 while (iter != featurePointMatches.end()) { |
| 157 bool deleteFeature = false; | 157 bool deleteFeature = false; |
