From efc0322ec88c388fbb187fe344c9955a96d07b17 Mon Sep 17 00:00:00 2001 From: Kurnianggoro Date: Tue, 2 Jun 2015 14:39:46 +0900 Subject: [PATCH] Add a framework for choosing the descriptor --- .../include/opencv2/tracking/tracker.hpp | 4 ++- modules/tracking/src/trackerKCF.cpp | 30 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/modules/tracking/include/opencv2/tracking/tracker.hpp b/modules/tracking/include/opencv2/tracking/tracker.hpp index 3e8280157..2435b6510 100644 --- a/modules/tracking/include/opencv2/tracking/tracker.hpp +++ b/modules/tracking/include/opencv2/tracking/tracker.hpp @@ -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 diff --git a/modules/tracking/src/trackerKCF.cpp b/modules/tracking/src/trackerKCF.cpp index 08358defa..0fdc1661f 100644 --- a/modules/tracking/src/trackerKCF.cpp +++ b/modules/tracking/src/trackerKCF.cpp @@ -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(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 >(i,j)[_k]=cn[index][_k]; + temp.at >(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*/ ){