From b76a7a3d443c12e24c1f7985e54d353cccd911c4 Mon Sep 17 00:00:00 2001 From: Alex Leontiev Date: Thu, 24 Jul 2014 04:36:13 +0900 Subject: [PATCH] vadim 7, 8 --- modules/tracking/src/tld_tracker.cpp | 18 +++++++++--------- modules/tracking/src/tld_tracker.hpp | 17 +++++++++++++---- modules/tracking/src/tld_utils.cpp | 6 +++--- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/modules/tracking/src/tld_tracker.cpp b/modules/tracking/src/tld_tracker.cpp index cb0bd7282..dbf5023a7 100644 --- a/modules/tracking/src/tld_tracker.cpp +++ b/modules/tracking/src/tld_tracker.cpp @@ -191,8 +191,8 @@ class TrackerTLDModel : public TrackerModel{ void setBoudingBox(Rect2d boundingBox){boundingBox_=boundingBox;} double getOriginalVariance(){return originalVariance_;} std::vector* getClassifiers(){return &classifiers;} - double Sr(const Mat_ patch); - double Sc(const Mat_ patch); + double Sr(const Mat_& patch); + double Sc(const Mat_& patch); void integrateRelabeled(Mat& img,Mat& imgBlurred,const std::vector& box,const std::vector& isPositive, const std::vector& alsoIntoModel); void integrateAdditional(const std::vector >& eForModel,const std::vector >& eForEnsemble,bool isPositive); @@ -588,14 +588,14 @@ double TLDDetector::ensembleClassifierNum(const uchar* data,int rowstep){ return p; } -double TrackerTLDModel::Sr(const Mat_ patch){ +double TrackerTLDModel::Sr(const Mat_& patch){ double splus=0.0; for(int i=0;i<(int)positiveExamples.size();i++){ - splus=MAX(splus,0.5*(NCC(positiveExamples[i],patch)+1.0)); + splus=std::max(splus,0.5*(NCC(positiveExamples[i],patch)+1.0)); } double sminus=0.0; for(int i=0;i<(int)negativeExamples.size();i++){ - sminus=MAX(sminus,0.5*(NCC(negativeExamples[i],patch)+1.0)); + sminus=std::max(sminus,0.5*(NCC(negativeExamples[i],patch)+1.0)); } if(splus+sminus==0.0){ return 0.0; @@ -603,17 +603,17 @@ double TrackerTLDModel::Sr(const Mat_ patch){ return splus/(sminus+splus); } -double TrackerTLDModel::Sc(const Mat_ patch){ +double TrackerTLDModel::Sc(const Mat_& patch){ double splus=0.0; int med=getMedian(timeStampsPositive); for(int i=0;i<(int)positiveExamples.size();i++){ if((int)timeStampsPositive[i]<=med){ - splus=MAX(splus,0.5*(NCC(positiveExamples[i],patch)+1.0)); + splus=std::max(splus,0.5*(NCC(positiveExamples[i],patch)+1.0)); } } double sminus=0.0; for(int i=0;i<(int)negativeExamples.size();i++){ - sminus=MAX(sminus,0.5*(NCC(negativeExamples[i],patch)+1.0)); + sminus=std::max(sminus,0.5*(NCC(negativeExamples[i],patch)+1.0)); } if(splus+sminus==0.0){ return 0.0; @@ -753,7 +753,7 @@ bool Nexpert::operator()(Rect2d box){ } Data::Data(Rect2d initBox){ - double minDim=MIN(initBox.width,initBox.height); + double minDim=std::min(initBox.width,initBox.height); scale = 20.0/minDim; minSize.width=(int)(initBox.width*20.0/minDim); minSize.height=(int)(initBox.height*20.0/minDim); diff --git a/modules/tracking/src/tld_tracker.hpp b/modules/tracking/src/tld_tracker.hpp index c2c96272a..c575105ef 100644 --- a/modules/tracking/src/tld_tracker.hpp +++ b/modules/tracking/src/tld_tracker.hpp @@ -73,14 +73,23 @@ void drawWithRects(const Mat& img,std::vector& blackOnes,Rect2d whiteOne void drawWithRects(const Mat& img,std::vector& blackOnes,std::vector& whiteOnes); //aux functions and variables -//#define CLIP(x,a,b) MIN(MAX((x),(a)),(b)) -template inline T CLIP(T x,T a,T b){return MIN(MAX(x,a),b);} +//#define CLIP(x,a,b) std::min(std::max((x),(a)),(b)) +template inline T CLIP(T x,T a,T b){return std::min(std::max(x,a),b);} +/** Computes overlap between the two given rectangles. Overlap is computed as ratio of rectangles' intersection to that + * of their union.*/ double overlap(const Rect2d& r1,const Rect2d& r2); +/** Resamples the area surrounded by r2 in img so it matches the size of samples, where it is written.*/ void resample(const Mat& img,const RotatedRect& r2,Mat_& samples); +/** Specialization of resample() for rectangles without retation for better performance and simplicity.*/ void resample(const Mat& img,const Rect2d& r2,Mat_& samples); +/** Computes the variance of single given image.*/ double variance(const Mat& img); +/** Computes the variance of subimage given by box, with the help of two integral + * images intImgP and intImgP2 (sum of squares), which should be also provided.*/ double variance(Mat_& intImgP,Mat_& intImgP2,Rect box); -double NCC(Mat_ patch1,Mat_ patch2); +/** Computes normalized corellation coefficient between the two patches (they should be + * of the same size).*/ +double NCC(const Mat_& patch1,const Mat_& patch2); void getClosestN(std::vector& scanGrid,Rect2d bBox,int n,std::vector& res); double scaleAndBlur(const Mat& originalImg,int scale,Mat& scaledImg,Mat& blurredImg,Size GaussBlurKernelSize); unsigned int getMedian(const std::vector& values, int size=-1); @@ -88,7 +97,7 @@ unsigned int getMedian(const std::vector& values, int size=-1); class TLDEnsembleClassifier{ public: TLDEnsembleClassifier(int ordinal,Size size,int measurePerClassifier); - void integrate(Mat_ patch,bool isPositive); + void integrate(const Mat_& patch,bool isPositive); double posteriorProbability(const uchar* data,int rowstep)const; static int getMaxOrdinal(); private: diff --git a/modules/tracking/src/tld_utils.cpp b/modules/tracking/src/tld_utils.cpp index d52eb76b0..d7948ab07 100644 --- a/modules/tracking/src/tld_utils.cpp +++ b/modules/tracking/src/tld_utils.cpp @@ -199,7 +199,7 @@ double variance(Mat_& intImgP,Mat_& intImgP2,Rect box){ return p2-p*p; } -double NCC(Mat_ patch1,Mat_ patch2){ +double NCC(const Mat_& patch1,const Mat_& patch2){ CV_Assert(patch1.rows==patch2.rows); CV_Assert(patch1.cols==patch2.cols); @@ -207,7 +207,7 @@ double NCC(Mat_ patch1,Mat_ patch2){ double s1=sum(patch1)(0),s2=sum(patch2)(0); double n1=norm(patch1),n2=norm(patch2); double prod=patch1.dot(patch2); - double sq1=sqrt(MAX(0.0,n1*n1-s1*s1/N)),sq2=sqrt(MAX(0.0,n2*n2-s2*s2/N)); + double sq1=sqrt(std::max(0.0,n1*n1-s1*s1/N)),sq2=sqrt(std::max(0.0,n2*n2-s2*s2/N)); double ares=(sq2==0)?sq1/abs(sq1):(prod-s1*s2/N)/sq1/sq2; return ares; } @@ -300,7 +300,7 @@ TLDEnsembleClassifier::TLDEnsembleClassifier(int ordinal,Size size,int measurePe pos=std::vector(posSize,0); neg=std::vector(posSize,0); } -void TLDEnsembleClassifier::integrate(Mat_ patch,bool isPositive){ +void TLDEnsembleClassifier::integrate(const Mat_& patch,bool isPositive){ unsigned short int position=code(patch.data,(int)patch.step[0]); if(isPositive){ pos[position]++;