From 244b7926beddb710b253f9b7dcfe4b45c2e40c3f Mon Sep 17 00:00:00 2001 From: Kurnianggoro Date: Sat, 20 Jun 2015 04:57:20 +0900 Subject: [PATCH] Fixing alignments --- modules/tracking/src/trackerKCF.cpp | 107 +++++++++++++--------------- 1 file changed, 51 insertions(+), 56 deletions(-) diff --git a/modules/tracking/src/trackerKCF.cpp b/modules/tracking/src/trackerKCF.cpp index f2887d03b..0765ffb12 100644 --- a/modules/tracking/src/trackerKCF.cpp +++ b/modules/tracking/src/trackerKCF.cpp @@ -144,7 +144,7 @@ namespace cv{ params.read( fn ); } - void TrackerKCFImpl::write( cv::FileStorage& fs ) const{ + void TrackerKCFImpl::write( cv::FileStorage& fs ) const { params.write( fs ); } @@ -189,7 +189,7 @@ namespace cv{ y=Mat::zeros((int)roi.height,(int)roi.width,CV_64F); for(unsigned i=0;i(i,j)=(i-roi.height/2+1)*(i-roi.height/2+1)+(j-roi.width/2+1)*(j-roi.width/2+1); + y.at(i,j)=(i-roi.height/2+1)*(i-roi.height/2+1)+(j-roi.width/2+1)*(j-roi.width/2+1); } } @@ -283,11 +283,11 @@ namespace cv{ mulSpectrums(kf,kf_lambda,new_alphaf_den,0); }else{ for(int i=0;i(yf.at(i,j)[0],yf.at(i,j)[1])/(std::complex(kf_lambda.at(i,j)[0],kf_lambda.at(i,j)[1])/*+std::complex(0.0000000001,0.0000000001)*/); - new_alphaf.at(i,j)[0]=temp.real(); - new_alphaf.at(i,j)[1]=temp.imag(); - } + for(int j=0;j(yf.at(i,j)[0],yf.at(i,j)[1])/(std::complex(kf_lambda.at(i,j)[0],kf_lambda.at(i,j)[1])/*+std::complex(0.0000000001,0.0000000001)*/); + new_alphaf.at(i,j)[0]=temp.real(); + new_alphaf.at(i,j)[1]=temp.imag(); + } } } @@ -312,7 +312,7 @@ namespace cv{ /* * 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 ); _dst.create(winSize, type); @@ -325,27 +325,22 @@ namespace cv{ double coeff0 = 2.0 * CV_PI / (double)(cols - 1), coeff1 = 2.0f * CV_PI / (double)(rows - 1); for(int j = 0; j < cols; j++) - wc[j] = 0.5 * (1.0 - cos(coeff0 * j)); - - if(dst.depth() == CV_32F) - { - for(int i = 0; i < rows; i++) - { - float* dstData = dst.ptr(i); - double wr = 0.5 * (1.0 - cos(coeff1 * i)); - for(int j = 0; j < cols; j++) - dstData[j] = (float)(wr * wc[j]); - } - } - else - { - for(int i = 0; i < rows; i++) - { - double* dstData = dst.ptr(i); - double wr = 0.5 * (1.0 - cos(coeff1 * i)); - for(int j = 0; j < cols; j++) - dstData[j] = wr * wc[j]; - } + wc[j] = 0.5 * (1.0 - cos(coeff0 * j)); + + if(dst.depth() == CV_32F){ + for(int i = 0; i < rows; i++){ + float* dstData = dst.ptr(i); + double wr = 0.5 * (1.0 - cos(coeff1 * i)); + for(int j = 0; j < cols; j++) + dstData[j] = (float)(wr * wc[j]); + } + }else{ + for(int i = 0; i < rows; i++){ + double* dstData = dst.ptr(i); + double wr = 0.5 * (1.0 - cos(coeff1 * i)); + for(int j = 0; j < cols; j++) + dstData[j] = wr * wc[j]; + } } // perform batch sqrt for SSE performance gains @@ -355,7 +350,7 @@ namespace cv{ /* * 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 layers(src.channels()); std::vector outputs(src.channels()); @@ -368,7 +363,7 @@ namespace cv{ merge(outputs,dest); } - void inline TrackerKCFImpl::fft2(const Mat src, std::vector & dest) const{ + void inline TrackerKCFImpl::fft2(const Mat src, std::vector & dest) const { std::vector layers(src.channels()); dest.clear(); dest.resize(src.channels()); @@ -383,14 +378,14 @@ namespace cv{ /* * 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); } /* * Point-wise multiplication of two Multichannel Mat data */ - void inline TrackerKCFImpl::pixelWiseMult(const std::vector src1, const std::vector src2, std::vector & dest, const int flags, const bool conjB) const{ + void inline TrackerKCFImpl::pixelWiseMult(const std::vector src1, const std::vector src2, std::vector & dest, const int flags, const bool conjB) const { dest.clear(); dest.resize(src1.size()); @@ -402,7 +397,7 @@ namespace cv{ /* * Combines all channels in a multi-channels Mat data into a single channel */ - void inline TrackerKCFImpl::sumChannels(std::vector src, Mat & dest) const{ + void inline TrackerKCFImpl::sumChannels(std::vector src, Mat & dest) const { dest=src[0].clone(); for(unsigned i=1;i1)cvtColor(patch,patch, CV_BGR2GRAY); - patch.convertTo(patch,CV_64F); - patch=patch/255.0-0.5; // normalize to range -0.5 .. 0.5 - break; + if(img.channels()>1)cvtColor(patch,patch, CV_BGR2GRAY); + patch.convertTo(patch,CV_64F); + patch=patch/255.0-0.5; // normalize to range -0.5 .. 0.5 + break; case CN: - CV_Assert(img.channels() == 3); - extractCN(patch,patch); - break; + CV_Assert(img.channels() == 3); + extractCN(patch,patch); + break; case CN2: - if(patch.channels()>1)cvtColor(patch,patch, CV_BGR2GRAY); - break; + if(patch.channels()>1)cvtColor(patch,patch, CV_BGR2GRAY); + break; } patch=patch.mul(hann); // hann window filter @@ -523,13 +518,13 @@ namespace cv{ for(int i=0;i<_patch.rows;i++){ for(int j=0;j<_patch.cols;j++){ - pixel=_patch.at(i,j); - index=(unsigned)(floor(pixel[2]/8)+32*floor(pixel[1]/8)+32*32*floor(pixel[0]/8)); - - //copy the values - for(int _k=0;_k<10;_k++){ - temp.at >(i,j)[_k]=ColorNames[index][_k]; - } + pixel=_patch.at(i,j); + index=(unsigned)(floor(pixel[2]/8)+32*floor(pixel[1]/8)+32*32*floor(pixel[0]/8)); + + //copy the values + for(int _k=0;_k<10;_k++){ + temp.at >(i,j)[_k]=ColorNames[index][_k]; + } } } @@ -539,7 +534,7 @@ namespace cv{ /* * 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 _xf,_yf,xyf_v; Mat xy,xyf; double normX, normY; @@ -641,7 +636,7 @@ namespace cv{ /* * 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; Mat _kf; fft2(_k,_kf); @@ -653,7 +648,7 @@ namespace cv{ /* * 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; fft2(_k,_kf); Mat spec;