mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-20 04:25:42 +08:00
Add a framework for choosing the descriptor
This commit is contained in:
@@ -1198,6 +1198,7 @@ class CV_EXPORTS_W TrackerTLD : public Tracker
|
|||||||
class CV_EXPORTS_W TrackerKCF : public Tracker
|
class CV_EXPORTS_W TrackerKCF : public Tracker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum MODE {GRAY, CN, CN2};
|
||||||
struct CV_EXPORTS Params
|
struct CV_EXPORTS Params
|
||||||
{
|
{
|
||||||
Params();
|
Params();
|
||||||
@@ -1209,7 +1210,8 @@ class CV_EXPORTS_W TrackerKCF : public Tracker
|
|||||||
double interp_factor; // linear interpolation factor for adaptation
|
double interp_factor; // linear interpolation factor for adaptation
|
||||||
double output_sigma_factor; // spatial bandwidth (proportional to target)
|
double output_sigma_factor; // spatial bandwidth (proportional to target)
|
||||||
bool resize; // activate the resize feature to improve the processing speed
|
bool resize; // activate the resize feature to improve the processing speed
|
||||||
int max_patch_size; // threshold for the ROI size
|
int max_patch_size; // threshold for the ROI size
|
||||||
|
MODE descriptor; // descriptor type
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Constructor
|
/** @brief Constructor
|
||||||
|
@@ -169,6 +169,10 @@ namespace cv{
|
|||||||
|
|
||||||
// initialize the hann window filter
|
// initialize the hann window filter
|
||||||
createHanningWindow(hann, roi.size(), CV_64F);
|
createHanningWindow(hann, roi.size(), CV_64F);
|
||||||
|
if(params.descriptor==CN){
|
||||||
|
Mat layers[] = {hann, hann, hann, hann, hann, hann, hann, hann, hann, hann};
|
||||||
|
merge(layers, 10, hann);
|
||||||
|
}
|
||||||
|
|
||||||
// create gaussian response
|
// create gaussian response
|
||||||
y=Mat::zeros(roi.height,roi.width,CV_64F);
|
y=Mat::zeros(roi.height,roi.width,CV_64F);
|
||||||
@@ -197,12 +201,9 @@ namespace cv{
|
|||||||
double minVal, maxVal; // min-max response
|
double minVal, maxVal; // min-max response
|
||||||
Point minLoc,maxLoc; // min-max location
|
Point minLoc,maxLoc; // min-max location
|
||||||
|
|
||||||
Mat img;
|
Mat img=image.clone();
|
||||||
// check the channels of the input image, grayscale is preferred
|
// check the channels of the input image, grayscale is preferred
|
||||||
CV_Assert(image.channels() == 1 || image.channels() == 3);
|
CV_Assert(image.channels() == 1 || image.channels() == 3);
|
||||||
if(image.channels()>1){
|
|
||||||
cvtColor(image,img, CV_BGR2GRAY);
|
|
||||||
}else img=image;
|
|
||||||
|
|
||||||
// resize the image whenever needed
|
// resize the image whenever needed
|
||||||
if(resizeImage)resize(img,img,Size(img.cols/2,img.rows/2));
|
if(resizeImage)resize(img,img,Size(img.cols/2,img.rows/2));
|
||||||
@@ -355,6 +356,20 @@ namespace cv{
|
|||||||
|
|
||||||
copyMakeBorder(patch,patch,addTop,addBottom,addLeft,addRight,BORDER_REPLICATE);
|
copyMakeBorder(patch,patch,addTop,addBottom,addLeft,addRight,BORDER_REPLICATE);
|
||||||
|
|
||||||
|
// extract the desired descriptors
|
||||||
|
switch(params.descriptor){
|
||||||
|
case GRAY:
|
||||||
|
if(img.channels()>1)cvtColor(patch,patch, CV_BGR2GRAY);
|
||||||
|
break;
|
||||||
|
case CN:
|
||||||
|
CV_Assert(img.channels() == 3);
|
||||||
|
extractCN(patch,patch);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if(patch.channels()>1)cvtColor(patch,patch, CV_BGR2GRAY);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
patch.convertTo(patch,CV_64F);
|
patch.convertTo(patch,CV_64F);
|
||||||
|
|
||||||
patch=patch/255.0-0.5; // normalize to range -0.5 .. 0.5
|
patch=patch/255.0-0.5; // normalize to range -0.5 .. 0.5
|
||||||
@@ -370,7 +385,7 @@ namespace cv{
|
|||||||
Vec3b & pixel = _patch.at<Vec3b>(0,0);
|
Vec3b & pixel = _patch.at<Vec3b>(0,0);
|
||||||
unsigned index;
|
unsigned index;
|
||||||
|
|
||||||
cnFeatures = Mat::zeros(roi.height,roi.width,CV_64FC(10));
|
Mat temp = Mat::zeros(_patch.rows,_patch.cols,CV_64FC(10));
|
||||||
|
|
||||||
for(int i=0;i<_patch.rows;i++){
|
for(int i=0;i<_patch.rows;i++){
|
||||||
for(int j=0;j<_patch.cols;j++){
|
for(int j=0;j<_patch.cols;j++){
|
||||||
@@ -379,10 +394,12 @@ namespace cv{
|
|||||||
|
|
||||||
//copy the values
|
//copy the values
|
||||||
for(int _k=0;_k<10;_k++){
|
for(int _k=0;_k<10;_k++){
|
||||||
cnFeatures.at<Vec<double,10> >(i,j)[_k]=cn[index][_k];
|
temp.at<Vec<double,10> >(i,j)[_k]=cn[index][_k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cnFeatures=temp.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -506,6 +523,7 @@ namespace cv{
|
|||||||
output_sigma_factor=1.0/16.0;
|
output_sigma_factor=1.0/16.0;
|
||||||
resize=true;
|
resize=true;
|
||||||
max_patch_size=80*80;
|
max_patch_size=80*80;
|
||||||
|
descriptor=GRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackerKCF::Params::read( const cv::FileNode& /*fn*/ ){
|
void TrackerKCF::Params::read( const cv::FileNode& /*fn*/ ){
|
||||||
|
Reference in New Issue
Block a user