Commit 1aeeee00 authored by Maksim Shabunin's avatar Maksim Shabunin

Merge pull request #1015 from sovrasov:kcf_update

parents 34b82ff0 bf8363a8
......@@ -1219,9 +1219,9 @@ public:
- "CN" -- Color-names feature
*/
enum MODE {
GRAY = (1u << 0),
CN = (1u << 1),
CUSTOM = (1u << 2)
GRAY = (1 << 0),
CN = (1 << 1),
CUSTOM = (1 << 2)
};
struct CV_EXPORTS Params
......@@ -1252,8 +1252,8 @@ public:
bool compress_feature; //!< activate the pca method to compress the features
int max_patch_size; //!< threshold for the ROI size
int compressed_size; //!< feature size after compression
unsigned int desc_pca; //!< compressed descriptors of TrackerKCF::MODE
unsigned int desc_npca; //!< non-compressed descriptors of TrackerKCF::MODE
int desc_pca; //!< compressed descriptors of TrackerKCF::MODE
int desc_npca; //!< non-compressed descriptors of TrackerKCF::MODE
};
virtual void setFeatureExtractor(void(*)(const Mat, const Rect, Mat&), bool pca_func = false);
......
......@@ -188,7 +188,7 @@ namespace cv{
* - creating a gaussian response for the training ground-truth
* - perform FFT to the gaussian response
*/
bool TrackerKCFImpl::initImpl( const Mat& /*image*/, const Rect2d& boundingBox ){
bool TrackerKCFImpl::initImpl( const Mat& image, const Rect2d& boundingBox ){
frame=0;
roi = boundingBox;
......@@ -256,7 +256,11 @@ namespace cv{
|| use_custom_extractor_npca
);
// TODO: return true only if roi inside the image
//return true only if roi has intersection with the image
if((roi & Rect2d(0,0, resizeImage ? image.cols / 2 : image.cols,
resizeImage ? image.rows / 2 : image.rows)) == Rect2d())
return false;
return true;
}
......@@ -576,11 +580,8 @@ namespace cv{
Rect region=_roi;
// return false if roi is outside the image
if((_roi.x+_roi.width<0)
||(_roi.y+_roi.height<0)
||(_roi.x>=img.cols)
||(_roi.y>=img.rows)
)return false;
if((roi & Rect2d(0,0, img.cols, img.rows)) == Rect2d() )
return false;
// extract patch inside the image
if(_roi.x<0){region.x=0;region.width+=_roi.x;}
......@@ -834,9 +835,65 @@ namespace cv{
pca_learning_rate=0.15;
}
void TrackerKCF::Params::read( const cv::FileNode& /*fn*/ ){}
void TrackerKCF::Params::read( const cv::FileNode& fn ){
*this = TrackerKCF::Params();
if (!fn["sigma"].empty())
fn["sigma"] >> sigma;
if (!fn["lambda"].empty())
fn["lambda"] >> lambda;
if (!fn["interp_factor"].empty())
fn["interp_factor"] >> interp_factor;
if (!fn["output_sigma_factor"].empty())
fn["output_sigma_factor"] >> output_sigma_factor;
if (!fn["resize"].empty())
fn["resize"] >> resize;
void TrackerKCF::Params::write( cv::FileStorage& /*fs*/ ) const{}
if (!fn["max_patch_size"].empty())
fn["max_patch_size"] >> max_patch_size;
if (!fn["split_coeff"].empty())
fn["split_coeff"] >> split_coeff;
if (!fn["wrap_kernel"].empty())
fn["wrap_kernel"] >> wrap_kernel;
if (!fn["desc_npca"].empty())
fn["desc_npca"] >> desc_npca;
if (!fn["desc_pca"].empty())
fn["desc_pca"] >> desc_pca;
if (!fn["compress_feature"].empty())
fn["compress_feature"] >> compress_feature;
if (!fn["compressed_size"].empty())
fn["compressed_size"] >> compressed_size;
if (!fn["pca_learning_rate"].empty())
fn["pca_learning_rate"] >> pca_learning_rate;
}
void TrackerKCF::Params::write( cv::FileStorage& fs ) const{
fs << "sigma" << sigma;
fs << "lambda" << lambda;
fs << "interp_factor" << interp_factor;
fs << "output_sigma_factor" << output_sigma_factor;
fs << "resize" << resize;
fs << "max_patch_size" << max_patch_size;
fs << "split_coeff" << split_coeff;
fs << "wrap_kernel" << wrap_kernel;
fs << "desc_npca" << desc_npca;
fs << "desc_pca" << desc_pca;
fs << "compress_feature" << compress_feature;
fs << "compressed_size" << compressed_size;
fs << "pca_learning_rate" << pca_learning_rate;
}
void TrackerKCF::setFeatureExtractor(void (*)(const Mat, const Rect, Mat&), bool ){};
......
......@@ -7,7 +7,7 @@
using namespace cv;
TEST(MEDIAN_FLOW_Parameters_IO, MEDIAN_FLOW)
TEST(MEDIAN_FLOW_Parameters, IO)
{
TrackerMedianFlow::Params parameters;
......@@ -40,7 +40,7 @@ TEST(MEDIAN_FLOW_Parameters_IO, MEDIAN_FLOW)
}
TEST(MEDIAN_FLOW_Parameters_IO_Default_Value_If_Absent, MEDIAN_FLOW)
TEST(MEDIAN_FLOW_Parameters, Default_Value_If_Absent)
{
TrackerMedianFlow::Params defaultParameters;
......@@ -58,3 +58,70 @@ TEST(MEDIAN_FLOW_Parameters_IO_Default_Value_If_Absent, MEDIAN_FLOW)
ASSERT_EQ(defaultParameters.termCriteria.epsilon, readParameters.termCriteria.epsilon);
ASSERT_EQ(defaultParameters.termCriteria.maxCount, readParameters.termCriteria.maxCount);
}
TEST(KCF_Parameters, IO)
{
TrackerKCF::Params parameters;
parameters.sigma = 0.3;
parameters.lambda = 0.02;
parameters.interp_factor = 0.08;
parameters.output_sigma_factor = 1.0/ 32.0;
parameters.resize=false;
parameters.max_patch_size=90*90;
parameters.split_coeff=false;
parameters.wrap_kernel=true;
parameters.desc_npca = TrackerKCF::CN;
parameters.desc_pca = TrackerKCF::GRAY;
parameters.compress_feature=false;
parameters.compressed_size=3;
parameters.pca_learning_rate=0.2;
FileStorage fsWriter("parameters.xml", FileStorage::WRITE + FileStorage::MEMORY);
parameters.write(fsWriter);
String serializedParameters = fsWriter.releaseAndGetString();
FileStorage fsReader(serializedParameters, FileStorage::READ + FileStorage::MEMORY);
TrackerKCF::Params readParameters;
readParameters.read(fsReader.root());
ASSERT_DOUBLE_EQ(parameters.sigma, readParameters.sigma);
ASSERT_DOUBLE_EQ(parameters.lambda, readParameters.lambda);
ASSERT_DOUBLE_EQ(parameters.interp_factor, readParameters.interp_factor);
ASSERT_DOUBLE_EQ(parameters.output_sigma_factor, readParameters.output_sigma_factor);
ASSERT_EQ(parameters.resize, readParameters.resize);
ASSERT_EQ(parameters.max_patch_size, readParameters.max_patch_size);
ASSERT_EQ(parameters.split_coeff, readParameters.split_coeff);
ASSERT_EQ(parameters.wrap_kernel, readParameters.wrap_kernel);
ASSERT_EQ(parameters.desc_npca, readParameters.desc_npca);
ASSERT_EQ(parameters.desc_pca, readParameters.desc_pca);
ASSERT_EQ(parameters.compress_feature, readParameters.compress_feature);
ASSERT_EQ(parameters.compressed_size, readParameters.compressed_size);
ASSERT_DOUBLE_EQ(parameters.pca_learning_rate, readParameters.pca_learning_rate);
}
TEST(KCF_Parameters, Default_Value_If_Absent)
{
TrackerKCF::Params defaultParameters;
FileStorage fsReader(String("%YAML 1.0"), FileStorage::READ + FileStorage::MEMORY);
TrackerKCF::Params readParameters;
readParameters.read(fsReader.root());
ASSERT_DOUBLE_EQ(defaultParameters.sigma, readParameters.sigma);
ASSERT_DOUBLE_EQ(defaultParameters.lambda, readParameters.lambda);
ASSERT_DOUBLE_EQ(defaultParameters.interp_factor, readParameters.interp_factor);
ASSERT_DOUBLE_EQ(defaultParameters.output_sigma_factor, readParameters.output_sigma_factor);
ASSERT_EQ(defaultParameters.resize, readParameters.resize);
ASSERT_EQ(defaultParameters.max_patch_size, readParameters.max_patch_size);
ASSERT_EQ(defaultParameters.split_coeff, readParameters.split_coeff);
ASSERT_EQ(defaultParameters.wrap_kernel, readParameters.wrap_kernel);
ASSERT_EQ(defaultParameters.desc_npca, readParameters.desc_npca);
ASSERT_EQ(defaultParameters.desc_pca, readParameters.desc_pca);
ASSERT_EQ(defaultParameters.compress_feature, readParameters.compress_feature);
ASSERT_EQ(defaultParameters.compressed_size, readParameters.compressed_size);
ASSERT_DOUBLE_EQ(defaultParameters.pca_learning_rate, readParameters.pca_learning_rate);
}
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