Commit efc0322e authored by Kurnianggoro's avatar Kurnianggoro

Add a framework for choosing the descriptor

parent e7466085
......@@ -1198,6 +1198,7 @@ class CV_EXPORTS_W TrackerTLD : public Tracker
class CV_EXPORTS_W TrackerKCF : public Tracker
{
public:
enum MODE {GRAY, CN, CN2};
struct CV_EXPORTS Params
{
Params();
......@@ -1209,7 +1210,8 @@ class CV_EXPORTS_W TrackerKCF : public Tracker
double interp_factor; // linear interpolation factor for adaptation
double output_sigma_factor; // spatial bandwidth (proportional to target)
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
......
......@@ -169,6 +169,10 @@ namespace cv{
// initialize the hann window filter
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
y=Mat::zeros(roi.height,roi.width,CV_64F);
......@@ -197,12 +201,9 @@ namespace cv{
double minVal, maxVal; // min-max response
Point minLoc,maxLoc; // min-max location
Mat img;
Mat img=image.clone();
// check the channels of the input image, grayscale is preferred
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
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);
// 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=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);
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 j=0;j<_patch.cols;j++){
......@@ -379,10 +394,12 @@ namespace cv{
//copy the values
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;
resize=true;
max_patch_size=80*80;
descriptor=GRAY;
}
void TrackerKCF::Params::read( const cv::FileNode& /*fn*/ ){
......
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