|
|
@ -144,7 +144,7 @@ namespace cv{ |
|
|
|
params.read( fn ); |
|
|
|
params.read( fn ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerKCFImpl::write( cv::FileStorage& fs ) const{ |
|
|
|
void TrackerKCFImpl::write( cv::FileStorage& fs ) const { |
|
|
|
params.write( fs ); |
|
|
|
params.write( fs ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -312,7 +312,7 @@ namespace cv{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* hann window filter |
|
|
|
* hann window filter |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void TrackerKCFImpl::createHanningWindow(OutputArray _dst, const cv::Size winSize, const int type)const{ |
|
|
|
void TrackerKCFImpl::createHanningWindow(OutputArray _dst, const cv::Size winSize, const int type) const { |
|
|
|
CV_Assert( type == CV_32FC1 || type == CV_64FC1 ); |
|
|
|
CV_Assert( type == CV_32FC1 || type == CV_64FC1 ); |
|
|
|
|
|
|
|
|
|
|
|
_dst.create(winSize, type); |
|
|
|
_dst.create(winSize, type); |
|
|
@ -327,20 +327,15 @@ namespace cv{ |
|
|
|
for(int j = 0; j < cols; j++) |
|
|
|
for(int j = 0; j < cols; j++) |
|
|
|
wc[j] = 0.5 * (1.0 - cos(coeff0 * j)); |
|
|
|
wc[j] = 0.5 * (1.0 - cos(coeff0 * j)); |
|
|
|
|
|
|
|
|
|
|
|
if(dst.depth() == CV_32F) |
|
|
|
if(dst.depth() == CV_32F){ |
|
|
|
{ |
|
|
|
for(int i = 0; i < rows; i++){ |
|
|
|
for(int i = 0; i < rows; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
float* dstData = dst.ptr<float>(i); |
|
|
|
float* dstData = dst.ptr<float>(i); |
|
|
|
double wr = 0.5 * (1.0 - cos(coeff1 * i)); |
|
|
|
double wr = 0.5 * (1.0 - cos(coeff1 * i)); |
|
|
|
for(int j = 0; j < cols; j++) |
|
|
|
for(int j = 0; j < cols; j++) |
|
|
|
dstData[j] = (float)(wr * wc[j]); |
|
|
|
dstData[j] = (float)(wr * wc[j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
else |
|
|
|
for(int i = 0; i < rows; i++){ |
|
|
|
{ |
|
|
|
|
|
|
|
for(int i = 0; i < rows; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
double* dstData = dst.ptr<double>(i); |
|
|
|
double* dstData = dst.ptr<double>(i); |
|
|
|
double wr = 0.5 * (1.0 - cos(coeff1 * i)); |
|
|
|
double wr = 0.5 * (1.0 - cos(coeff1 * i)); |
|
|
|
for(int j = 0; j < cols; j++) |
|
|
|
for(int j = 0; j < cols; j++) |
|
|
@ -355,7 +350,7 @@ namespace cv{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* simplification of fourier transform function in opencv |
|
|
|
* simplification of fourier transform function in opencv |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void inline TrackerKCFImpl::fft2(const Mat src, Mat & dest)const { |
|
|
|
void inline TrackerKCFImpl::fft2(const Mat src, Mat & dest) const { |
|
|
|
std::vector<Mat> layers(src.channels()); |
|
|
|
std::vector<Mat> layers(src.channels()); |
|
|
|
std::vector<Mat> outputs(src.channels()); |
|
|
|
std::vector<Mat> outputs(src.channels()); |
|
|
|
|
|
|
|
|
|
|
@ -368,7 +363,7 @@ namespace cv{ |
|
|
|
merge(outputs,dest); |
|
|
|
merge(outputs,dest); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void inline TrackerKCFImpl::fft2(const Mat src, std::vector<Mat> & dest) const{ |
|
|
|
void inline TrackerKCFImpl::fft2(const Mat src, std::vector<Mat> & dest) const { |
|
|
|
std::vector<Mat> layers(src.channels()); |
|
|
|
std::vector<Mat> layers(src.channels()); |
|
|
|
dest.clear(); |
|
|
|
dest.clear(); |
|
|
|
dest.resize(src.channels()); |
|
|
|
dest.resize(src.channels()); |
|
|
@ -383,14 +378,14 @@ namespace cv{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* simplification of inverse fourier transform function in opencv |
|
|
|
* simplification of inverse fourier transform function in opencv |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void inline TrackerKCFImpl::ifft2(const Mat src, Mat & dest)const { |
|
|
|
void inline TrackerKCFImpl::ifft2(const Mat src, Mat & dest) const { |
|
|
|
idft(src,dest,DFT_SCALE+DFT_REAL_OUTPUT); |
|
|
|
idft(src,dest,DFT_SCALE+DFT_REAL_OUTPUT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Point-wise multiplication of two Multichannel Mat data |
|
|
|
* Point-wise multiplication of two Multichannel Mat data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void inline TrackerKCFImpl::pixelWiseMult(const std::vector<Mat> src1, const std::vector<Mat> src2, std::vector<Mat> & dest, const int flags, const bool conjB) const{ |
|
|
|
void inline TrackerKCFImpl::pixelWiseMult(const std::vector<Mat> src1, const std::vector<Mat> src2, std::vector<Mat> & dest, const int flags, const bool conjB) const { |
|
|
|
dest.clear(); |
|
|
|
dest.clear(); |
|
|
|
dest.resize(src1.size()); |
|
|
|
dest.resize(src1.size()); |
|
|
|
|
|
|
|
|
|
|
@ -402,7 +397,7 @@ namespace cv{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Combines all channels in a multi-channels Mat data into a single channel |
|
|
|
* Combines all channels in a multi-channels Mat data into a single channel |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void inline TrackerKCFImpl::sumChannels(std::vector<Mat> src, Mat & dest) const{ |
|
|
|
void inline TrackerKCFImpl::sumChannels(std::vector<Mat> src, Mat & dest) const { |
|
|
|
dest=src[0].clone(); |
|
|
|
dest=src[0].clone(); |
|
|
|
for(unsigned i=1;i<src.size();i++){ |
|
|
|
for(unsigned i=1;i<src.size();i++){ |
|
|
|
dest+=src[i]; |
|
|
|
dest+=src[i]; |
|
|
@ -412,7 +407,7 @@ namespace cv{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* obtains the projection matrix using PCA |
|
|
|
* obtains the projection matrix using PCA |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void inline TrackerKCFImpl::updateProjectionMatrix(const Mat src, Mat & old_cov,Mat & _proj_mtx, double pca_rate, int compressed_sz)const{ |
|
|
|
void inline TrackerKCFImpl::updateProjectionMatrix(const Mat src, Mat & old_cov,Mat & _proj_mtx, double pca_rate, int compressed_sz) const { |
|
|
|
CV_Assert(compressed_sz<=src.channels()); |
|
|
|
CV_Assert(compressed_sz<=src.channels()); |
|
|
|
|
|
|
|
|
|
|
|
// compute average
|
|
|
|
// compute average
|
|
|
@ -451,7 +446,7 @@ namespace cv{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* compress the features |
|
|
|
* compress the features |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void inline TrackerKCFImpl::compress(const Mat _proj_mtx, const Mat src, Mat & dest)const{ |
|
|
|
void inline TrackerKCFImpl::compress(const Mat _proj_mtx, const Mat src, Mat & dest) const { |
|
|
|
Mat data=src.reshape(1,src.rows*src.cols); |
|
|
|
Mat data=src.reshape(1,src.rows*src.cols); |
|
|
|
Mat compressed=data*_proj_mtx; |
|
|
|
Mat compressed=data*_proj_mtx; |
|
|
|
dest=compressed.reshape(_proj_mtx.cols,src.rows).clone(); |
|
|
|
dest=compressed.reshape(_proj_mtx.cols,src.rows).clone(); |
|
|
@ -460,7 +455,7 @@ namespace cv{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* obtain the patch and apply hann window filter to it |
|
|
|
* obtain the patch and apply hann window filter to it |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
bool TrackerKCFImpl::getSubWindow(const Mat img, const Rect _roi, Mat& patch) const{ |
|
|
|
bool TrackerKCFImpl::getSubWindow(const Mat img, const Rect _roi, Mat& patch) const { |
|
|
|
|
|
|
|
|
|
|
|
Rect region=_roi; |
|
|
|
Rect region=_roi; |
|
|
|
|
|
|
|
|
|
|
@ -539,7 +534,7 @@ namespace cv{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* dense gauss kernel function |
|
|
|
* dense gauss kernel function |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void TrackerKCFImpl::denseGaussKernel(const double sigma, const Mat _x, const Mat _y, Mat & _k)const{ |
|
|
|
void TrackerKCFImpl::denseGaussKernel(const double sigma, const Mat _x, const Mat _y, Mat & _k) const { |
|
|
|
std::vector<Mat> _xf,_yf,xyf_v; |
|
|
|
std::vector<Mat> _xf,_yf,xyf_v; |
|
|
|
Mat xy,xyf; |
|
|
|
Mat xy,xyf; |
|
|
|
double normX, normY; |
|
|
|
double normX, normY; |
|
|
@ -641,7 +636,7 @@ namespace cv{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* calculate the detection response |
|
|
|
* calculate the detection response |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void TrackerKCFImpl::calcResponse(const Mat _alphaf, const Mat _k, Mat & _response)const { |
|
|
|
void TrackerKCFImpl::calcResponse(const Mat _alphaf, const Mat _k, Mat & _response) const { |
|
|
|
//alpha f--> 2channels ; k --> 1 channel;
|
|
|
|
//alpha f--> 2channels ; k --> 1 channel;
|
|
|
|
Mat _kf; |
|
|
|
Mat _kf; |
|
|
|
fft2(_k,_kf); |
|
|
|
fft2(_k,_kf); |
|
|
@ -653,7 +648,7 @@ namespace cv{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* calculate the detection response for splitted form |
|
|
|
* calculate the detection response for splitted form |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void TrackerKCFImpl::calcResponse(const Mat _alphaf, const Mat _alphaf_den, const Mat _k, Mat & _response)const { |
|
|
|
void TrackerKCFImpl::calcResponse(const Mat _alphaf, const Mat _alphaf_den, const Mat _k, Mat & _response) const { |
|
|
|
Mat _kf; |
|
|
|
Mat _kf; |
|
|
|
fft2(_k,_kf); |
|
|
|
fft2(_k,_kf); |
|
|
|
Mat spec; |
|
|
|
Mat spec; |
|
|
|