Commit 2848831c authored by Alex Leontiev's avatar Alex Leontiev

vadim 12, 20, 22

parent 449eb346
This diff is collapsed.
......@@ -99,8 +99,8 @@ public:
private:
TLDEnsembleClassifier(std::vector<Vec4b> meas,int beg,int end);
static void stepPrefSuff(std::vector<Vec4b>& arr,int pos,int len,int gridSize);
unsigned short int code(const uchar* data,int rowstep)const;
std::vector<unsigned int> pos,neg;
int code(const uchar* data,int rowstep)const;
std::vector<Point2i> posAndNeg;
std::vector<Vec4b> measurements;
};
......
......@@ -136,7 +136,8 @@ void getClosestN(std::vector<Rect2d>& scanGrid,Rect2d bBox,int n,std::vector<Rec
res.assign(scanGrid.begin(),scanGrid.end());
return;
}
std::vector<double> overlaps(n,0.0);
std::vector<double> overlaps;
overlaps.assign(n,0.0);
res.assign(scanGrid.begin(),scanGrid.begin()+n);
for(int i=0;i<n;i++){
overlaps[i]=overlap(res[i],bBox);
......@@ -183,10 +184,16 @@ double NCC(const Mat_<uchar>& patch1,const Mat_<uchar>& patch2){
CV_Assert(patch1.cols==patch2.cols);
int N=patch1.rows*patch1.cols;
double s1=sum(patch1)(0),s2=sum(patch2)(0);
double n1=norm(patch1),n2=norm(patch2);
double prod=patch1.dot(patch2);
double sq1=sqrt(std::max(0.0,n1*n1-s1*s1/N)),sq2=sqrt(std::max(0.0,n2*n2-s2*s2/N));
int s1=0,s2=0,n1=0,n2=0,prod=0;
for(int i=0;i<patch1.rows;i++){
for(int j=0;j<patch1.cols;j++){
int p1=patch1(i,j), p2=patch2(i,j);
s1+=p1; s2+=p2;
n1+=(p1*p1); n2+=(p2*p2);
prod+=(p1*p2);
}
}
double sq1=sqrt(std::max(0.0,n1-1.0*s1*s1/N)),sq2=sqrt(std::max(0.0,n2-1.0*s2*s2/N));
double ares=(sq2==0)?sq1/abs(sq1):(prod-s1*s2/N)/sq1/sq2;
return ares;
}
......@@ -264,29 +271,28 @@ void TLDEnsembleClassifier::stepPrefSuff(std::vector<Vec4b>& arr,int pos,int len
TLDEnsembleClassifier::TLDEnsembleClassifier(std::vector<Vec4b> meas,int beg,int end){
int posSize=1;
for(int i=0,mpc=end-beg;i<mpc;i++)posSize*=2;
pos=std::vector<unsigned int>(posSize,0);
neg=std::vector<unsigned int>(posSize,0);
posAndNeg.assign(posSize,Point2i(0,0));
measurements.assign(meas.begin()+beg,meas.begin()+end);
}
void TLDEnsembleClassifier::integrate(const Mat_<uchar>& patch,bool isPositive){
unsigned short int position=code(patch.data,(int)patch.step[0]);
int position=code(patch.data,(int)patch.step[0]);
if(isPositive){
pos[position]++;
posAndNeg[position].x++;
}else{
neg[position]++;
posAndNeg[position].y++;
}
}
double TLDEnsembleClassifier::posteriorProbability(const uchar* data,int rowstep)const{
unsigned short int position=code(data,rowstep);
double posNum=(double)pos[position], negNum=(double)neg[position];
int position=code(data,rowstep);
double posNum=(double)posAndNeg[position].x, negNum=(double)posAndNeg[position].y;
if(posNum==0.0 && negNum==0.0){
return 0.0;
}else{
return posNum/(posNum+negNum);
}
}
unsigned short int TLDEnsembleClassifier::code(const uchar* data,int rowstep)const{
unsigned short int position=0;//TODO: this --> encapsule
int TLDEnsembleClassifier::code(const uchar* data,int rowstep)const{
unsigned short int position=0;
for(int i=0;i<(int)measurements.size();i++){
position=position<<1;
if(*(data+rowstep*measurements[i].val[0]+measurements[i].val[1])<*(data+rowstep*measurements[i].val[2]+measurements[i].val[3])){
......
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