Commit f2c324a2 authored by Vladislav Sovrasov's avatar Vladislav Sovrasov Committed by Vadim Pisarevsky

Median flow tracker update (#952)

* Fix several issues in TrackerMedianFlow implementation

Particularly, add possibility to tune optical flow parameters for a median
flow tracker.

* Improve code of TrackerMedianFlow

Replace a lot of calls of std::vector::erase by one call of
std::remove_if.

* Delete unused code, use norm from OpenCV

* medianFlow:turn getMedian method into function, small code cleanup

* TrackerMedianFlow:fixes in parameters I/O, add test for them

* TrackerMedianFlow:replace double with float in temp buffers

* Fix indentation

* TrackerMedianFlow:add absent parameter case handling in read()

* TrackerMedianFlow:use ROI instead of copy when getting a patch

* TrackerMedianFlow:don't calc image pyramids 2 times

* MedianFlowTracker: use cvIsNan()

* MedianFlow: refactor vector filtration code

* MedianFlow: change if statements layout in filterPointsInVectors
parent 7e5ca520
......@@ -1156,9 +1156,16 @@ class CV_EXPORTS TrackerMedianFlow : public Tracker
public:
struct CV_EXPORTS Params
{
Params();
int pointsInGrid; //!<square root of number of keypoints used; increase it to trade
//!<accurateness for speed; default value is sensible and recommended
Params(); //!<default constructor
//!<note that the default values of parameters are recommended for most of use cases
int pointsInGrid; //!<square root of number of keypoints used; increase it to trade
//!<accurateness for speed
cv::Size winSize; //!<window size parameter for Lucas-Kanade optical flow
int maxLevel; //!<maximal pyramid level number for Lucas-Kanade optical flow
TermCriteria termCriteria; //!<termination criteria for Lucas-Kanade optical flow
cv::Size winSizeNCC; //!<window size around a point for normalized cross-correlation check
double maxMedianLengthOfDisplacementDifference; //!<criterion for loosing the tracked object
void read( const FileNode& /*fn*/ );
void write( FileStorage& /*fs*/ ) const;
};
......
This diff is collapsed.
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
#include "opencv2/tracking.hpp"
using namespace cv;
TEST(MEDIAN_FLOW_Parameters_IO, MEDIAN_FLOW)
{
TrackerMedianFlow::Params parameters;
parameters.maxLevel = 10;
parameters.maxMedianLengthOfDisplacementDifference = 11;
parameters.pointsInGrid = 12;
parameters.winSize = Size(6, 5);
parameters.winSizeNCC = Size(41, 40);
parameters.termCriteria.maxCount = 100;
parameters.termCriteria.epsilon = 0.1;
FileStorage fsWriter("parameters.xml", FileStorage::WRITE + FileStorage::MEMORY);
parameters.write(fsWriter);
String serializedParameters = fsWriter.releaseAndGetString();
FileStorage fsReader(serializedParameters, FileStorage::READ + FileStorage::MEMORY);
TrackerMedianFlow::Params readParameters;
readParameters.read(fsReader.root());
ASSERT_EQ(parameters.maxLevel, readParameters.maxLevel);
ASSERT_EQ(parameters.maxMedianLengthOfDisplacementDifference,
readParameters.maxMedianLengthOfDisplacementDifference);
ASSERT_EQ(parameters.pointsInGrid, readParameters.pointsInGrid);
ASSERT_EQ(parameters.winSize, readParameters.winSize);
ASSERT_EQ(parameters.winSizeNCC, readParameters.winSizeNCC);
ASSERT_EQ(parameters.termCriteria.epsilon, readParameters.termCriteria.epsilon);
ASSERT_EQ(parameters.termCriteria.maxCount, readParameters.termCriteria.maxCount);
}
TEST(MEDIAN_FLOW_Parameters_IO_Default_Value_If_Absent, MEDIAN_FLOW)
{
TrackerMedianFlow::Params defaultParameters;
FileStorage fsReader(String("%YAML 1.0"), FileStorage::READ + FileStorage::MEMORY);
TrackerMedianFlow::Params readParameters;
readParameters.read(fsReader.root());
ASSERT_EQ(defaultParameters.maxLevel, readParameters.maxLevel);
ASSERT_EQ(defaultParameters.maxMedianLengthOfDisplacementDifference,
readParameters.maxMedianLengthOfDisplacementDifference);
ASSERT_EQ(defaultParameters.pointsInGrid, readParameters.pointsInGrid);
ASSERT_EQ(defaultParameters.winSize, readParameters.winSize);
ASSERT_EQ(defaultParameters.winSizeNCC, readParameters.winSizeNCC);
ASSERT_EQ(defaultParameters.termCriteria.epsilon, readParameters.termCriteria.epsilon);
ASSERT_EQ(defaultParameters.termCriteria.maxCount, readParameters.termCriteria.maxCount);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment