Commit 449eb346 authored by Alex Leontiev's avatar Alex Leontiev

vadim 18, 19

parent b564f1b6
...@@ -80,19 +80,21 @@ using namespace tld; ...@@ -80,19 +80,21 @@ using namespace tld;
* ||video(0.5<->0.6) --> debug if box size is less than 20 * ||video(0.5<->0.6) --> debug if box size is less than 20
* perfect PN * perfect PN
* *
* vadim: * vadim:
* ?3. comment each function/method * ?3. comment each function/method
* 5. empty lines to separate logical... * 5. empty lines to separate logical...
* 6. comment logical sections * 6. comment logical sections
* ?10. all in one class * 11. group decls logically, order of statements
* 11. group decls logically, order of statements *
* 12. not v=vector(n), but assign(n,0) * ?10. all in one class
* 16. loops limits *
* 17. inner scope loops * 16. loops limits
* 19. var checker * 17. inner scope loops
* 20. NCC using plain loops *
* 21. precompute offset * 12. not v=vector(n), but assign(n,0)
* 22. vec of structs (detect and beyond) * 20. NCC using plain loops
* 21. precompute offset
* 22. vec of structs (detect and beyond)
* *
*/ */
...@@ -146,8 +148,7 @@ protected: ...@@ -146,8 +148,7 @@ protected:
Ptr<TrackerModel> model; Ptr<TrackerModel> model;
void computeIntegralImages(const Mat& img,Mat_<double>& intImgP,Mat_<double>& intImgP2){integral(img,intImgP,intImgP2,CV_64F);} void computeIntegralImages(const Mat& img,Mat_<double>& intImgP,Mat_<double>& intImgP2){integral(img,intImgP,intImgP2,CV_64F);}
inline bool patchVariance(Mat_<double>& intImgP,Mat_<double>& intImgP2,double originalVariance,Point pt,Size size); inline bool patchVariance(Mat_<double>& intImgP,Mat_<double>& intImgP2,double originalVariance,Point pt,Size size);
bool ensembleClassifier(const uchar* data,int rowstep){return ensembleClassifierNum(data,rowstep)>ENSEMBLE_THRESHOLD;} inline bool ensembleClassifier(const uchar* data,int rowstep);
double ensembleClassifierNum(const uchar* data,int rowstep);
TrackerTLD::Params params_; TrackerTLD::Params params_;
}; };
...@@ -203,7 +204,7 @@ class TrackerTLDModel : public TrackerModel{ ...@@ -203,7 +204,7 @@ class TrackerTLDModel : public TrackerModel{
Rect2d getBoundingBox(){return boundingBox_;} Rect2d getBoundingBox(){return boundingBox_;}
void setBoudingBox(Rect2d boundingBox){boundingBox_=boundingBox;} void setBoudingBox(Rect2d boundingBox){boundingBox_=boundingBox;}
double getOriginalVariance(){return originalVariance_;} double getOriginalVariance(){return originalVariance_;}
std::vector<TLDEnsembleClassifier>* getClassifiers(){return &classifiers;} inline double ensembleClassifierNum(const uchar* data,int rowstep);
double Sr(const Mat_<uchar>& patch); double Sr(const Mat_<uchar>& patch);
double Sc(const Mat_<uchar>& patch); double Sc(const Mat_<uchar>& patch);
void integrateRelabeled(Mat& img,Mat& imgBlurred,const std::vector<Rect2d>& box,const std::vector<bool>& isPositive, void integrateRelabeled(Mat& img,Mat& imgBlurred,const std::vector<Rect2d>& box,const std::vector<bool>& isPositive,
...@@ -584,18 +585,36 @@ bool TLDDetector::detect(const Mat& img,const Mat& imgBlurred,Rect2d& res,std::v ...@@ -584,18 +585,36 @@ bool TLDDetector::detect(const Mat& img,const Mat& imgBlurred,Rect2d& res,std::v
return true; return true;
} }
/** 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.*/
bool TLDDetector::patchVariance(Mat_<double>& intImgP,Mat_<double>& intImgP2,double originalVariance,Point pt,Size size){ bool TLDDetector::patchVariance(Mat_<double>& intImgP,Mat_<double>& intImgP2,double originalVariance,Point pt,Size size){
return variance(intImgP,intImgP2,Rect(pt.x,pt.y,size.width,size.height)) >= VARIANCE_THRESHOLD*originalVariance; int x=(pt.x),y=(pt.y),width=(size.width),height=(size.height);
CV_Assert(0<=x && (x+width)<intImgP.cols && (x+width)<intImgP2.cols);
CV_Assert(0<=y && (y+height)<intImgP.rows && (y+height)<intImgP2.rows);
double p=0,p2=0;
double A,B,C,D;
A=intImgP(y,x);
B=intImgP(y,x+width);
C=intImgP(y+height,x);
D=intImgP(y+height,x+width);
p=(0.0+A+D-B-C)/(width*height);
A=intImgP2(y,x);
B=intImgP2(y,x+width);
C=intImgP2(y+height,x);
D=intImgP2(y+height,x+width);
p2=(0.0+(D-B)-(C-A))/(width*height);
return p2-p*p;
} }
double TLDDetector::ensembleClassifierNum(const uchar* data,int rowstep){ double TrackerTLDModel::ensembleClassifierNum(const uchar* data,int rowstep){
TrackerTLDModel* tldModel=((TrackerTLDModel*)static_cast<TrackerModel*>(model));
std::vector<TLDEnsembleClassifier>* classifiers=tldModel->getClassifiers();
double p=0; double p=0;
for(int k=0;k<(int)classifiers->size();k++){ for(int k=0;k<(int)classifiers.size();k++){
p+=(*classifiers)[k].posteriorProbability(data,rowstep); p+=classifiers[k].posteriorProbability(data,rowstep);
} }
p/=classifiers->size(); p/=classifiers.size();
return p; return p;
} }
...@@ -808,7 +827,7 @@ void MyMouseCallbackDEBUG::onMouse( int event, int x, int y){ ...@@ -808,7 +827,7 @@ void MyMouseCallbackDEBUG::onMouse( int event, int x, int y){
i=(int)(x/scale/dx), j=(int)(y/scale/dy); i=(int)(x/scale/dx), j=(int)(y/scale/dy);
dfprintf((stderr,"patchVariance=%s\n",(detector_->patchVariance(intImgP,intImgP2,originalVariance,Point(dx*i,dy*j),initSize))?"true":"false")); dfprintf((stderr,"patchVariance=%s\n",(detector_->patchVariance(intImgP,intImgP2,originalVariance,Point(dx*i,dy*j),initSize))?"true":"false"));
dfprintf((stderr,"p=%f\n",(detector_->ensembleClassifierNum(&blurred_img.at<uchar>(dy*j,dx*i),(int)blurred_img.step[0])))); dfprintf((stderr,"p=%f\n",(tldModel->ensembleClassifierNum(&blurred_img.at<uchar>(dy*j,dx*i),(int)blurred_img.step[0]))));
fprintf(stderr,"ensembleClassifier=%s\n", fprintf(stderr,"ensembleClassifier=%s\n",
(detector_->ensembleClassifier(&blurred_img.at<uchar>(dy*j,dx*i),(int)blurred_img.step[0]))?"true":"false"); (detector_->ensembleClassifier(&blurred_img.at<uchar>(dy*j,dx*i),(int)blurred_img.step[0]))?"true":"false");
...@@ -847,5 +866,8 @@ void TrackerTLDModel::pushIntoModel(const Mat_<uchar>& example,bool positive){ ...@@ -847,5 +866,8 @@ void TrackerTLDModel::pushIntoModel(const Mat_<uchar>& example,bool positive){
} }
(*proxyN)++; (*proxyN)++;
} }
bool TLDDetector::ensembleClassifier(const uchar* data,int rowstep){
return (((TrackerTLDModel*)static_cast<TrackerModel*>(model))->ensembleClassifierNum(data,rowstep))>ENSEMBLE_THRESHOLD;
}
} /* namespace cv */ } /* namespace cv */
...@@ -84,9 +84,6 @@ void resample(const Mat& img,const RotatedRect& r2,Mat_<uchar>& samples); ...@@ -84,9 +84,6 @@ void resample(const Mat& img,const RotatedRect& r2,Mat_<uchar>& samples);
void resample(const Mat& img,const Rect2d& r2,Mat_<uchar>& samples); void resample(const Mat& img,const Rect2d& r2,Mat_<uchar>& samples);
/** Computes the variance of single given image.*/ /** Computes the variance of single given image.*/
double variance(const Mat& img); 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_<double>& intImgP,Mat_<double>& intImgP2,Rect box);
/** Computes normalized corellation coefficient between the two patches (they should be /** Computes normalized corellation coefficient between the two patches (they should be
* of the same size).*/ * of the same size).*/
double NCC(const Mat_<uchar>& patch1,const Mat_<uchar>& patch2); double NCC(const Mat_<uchar>& patch1,const Mat_<uchar>& patch2);
......
...@@ -177,27 +177,6 @@ double variance(const Mat& img){ ...@@ -177,27 +177,6 @@ double variance(const Mat& img){
p2/=(img.cols*img.rows); p2/=(img.cols*img.rows);
return p2-p*p; return p2-p*p;
} }
double variance(Mat_<double>& intImgP,Mat_<double>& intImgP2,Rect box){
int x=(box.x),y=(box.y),width=(box.width),height=(box.height);
CV_Assert(0<=x && (x+width)<intImgP.cols && (x+width)<intImgP2.cols);
CV_Assert(0<=y && (y+height)<intImgP.rows && (y+height)<intImgP2.rows);
double p=0,p2=0;
double A,B,C,D;
A=intImgP(y,x);
B=intImgP(y,x+width);
C=intImgP(y+height,x);
D=intImgP(y+height,x+width);
p=(0.0+A+D-B-C)/(width*height);
A=intImgP2(y,x);
B=intImgP2(y,x+width);
C=intImgP2(y+height,x);
D=intImgP2(y+height,x+width);
p2=(0.0+(D-B)-(C-A))/(width*height);
return p2-p*p;
}
double NCC(const Mat_<uchar>& patch1,const Mat_<uchar>& patch2){ double NCC(const Mat_<uchar>& patch1,const Mat_<uchar>& patch2){
CV_Assert(patch1.rows==patch2.rows); CV_Assert(patch1.rows==patch2.rows);
......
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