|
|
|
@ -57,6 +57,7 @@ |
|
|
|
|
#define SCALE_STEP 1.2 |
|
|
|
|
#define ENSEMBLE_THRESHOLD 0.5 |
|
|
|
|
#define VARIANCE_THRESHOLD 0.5 |
|
|
|
|
#define NEXPERT_THRESHOLD 0.2 |
|
|
|
|
#define GRIDSIZE 15 |
|
|
|
|
#define DOWNSCALE_MODE INTER_LINEAR |
|
|
|
|
#define BLUR_AS_VADIM |
|
|
|
@ -86,8 +87,19 @@ using namespace tld; |
|
|
|
|
* 6. comment logical sections |
|
|
|
|
* 11. group decls logically, order of statements |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* ?10. all in one class
|
|
|
|
|
* todo: initializer lists |
|
|
|
|
* |
|
|
|
|
* format: if,while,for, , Assert |
|
|
|
|
* format: methods |
|
|
|
|
* --> compile |
|
|
|
|
* ; , |
|
|
|
|
* --> compile |
|
|
|
|
* -->commit-push -->notify |
|
|
|
|
* |
|
|
|
|
* ?( ) |
|
|
|
|
* |
|
|
|
|
* ?vadim: for{1command} can omit {}; if( a != (b + c) ) vs ( a != ( b + c ) ) |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/* design decisions:
|
|
|
|
@ -177,7 +189,7 @@ class TrackerTLDModel : public TrackerModel{ |
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
Size minSize_; |
|
|
|
|
unsigned int timeStampPositiveNext,timeStampNegativeNext; |
|
|
|
|
int timeStampPositiveNext,timeStampNegativeNext; |
|
|
|
|
TrackerTLD::Params params_; |
|
|
|
|
void pushIntoModel(const Mat_<uchar>& example,bool positive); |
|
|
|
|
void modelEstimationImpl( const std::vector<Mat>& /*responses*/ ){} |
|
|
|
@ -185,7 +197,7 @@ class TrackerTLDModel : public TrackerModel{ |
|
|
|
|
Rect2d boundingBox_; |
|
|
|
|
double originalVariance_; |
|
|
|
|
std::vector<Mat_<uchar> > positiveExamples,negativeExamples; |
|
|
|
|
std::vector<unsigned int> timeStampsPositive,timeStampsNegative; |
|
|
|
|
std::vector<int> timeStampsPositive,timeStampsNegative; |
|
|
|
|
RNG rng; |
|
|
|
|
std::vector<TLDEnsembleClassifier> classifiers; |
|
|
|
|
}; |
|
|
|
@ -249,8 +261,8 @@ Ptr<TrackerTLD> TrackerTLD::createTracker(const TrackerTLD::Params ¶meters){ |
|
|
|
|
TrackerTLDImpl::TrackerTLDImpl(const TrackerTLD::Params ¶meters) : |
|
|
|
|
params( parameters ){ |
|
|
|
|
isInit = false; |
|
|
|
|
trackerProxy=Ptr<TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params> >( |
|
|
|
|
new TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params>()); |
|
|
|
|
trackerProxy = Ptr<TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params> > |
|
|
|
|
(new TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params>()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TrackerTLDImpl::read( const cv::FileNode& fn ) |
|
|
|
@ -270,7 +282,8 @@ bool TrackerTLDImpl::initImpl(const Mat& image, const Rect2d& boundingBox ){ |
|
|
|
|
data = Ptr<Data>(new Data(boundingBox)); |
|
|
|
|
double scale = data->getScale(); |
|
|
|
|
Rect2d myBoundingBox = boundingBox; |
|
|
|
|
if(scale>1.0){ |
|
|
|
|
if(scale > 1.0) |
|
|
|
|
{ |
|
|
|
|
Mat image_proxy; |
|
|
|
|
resize(image_gray,image_proxy,Size(cvRound(image.cols * scale),cvRound(image.rows * scale)),0,0,DOWNSCALE_MODE); |
|
|
|
|
image_proxy.copyTo(image_gray); |
|
|
|
@ -306,7 +319,8 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox){ |
|
|
|
|
std::vector<Rect2d> candidates; |
|
|
|
|
std::vector<double> candidatesRes; |
|
|
|
|
bool trackerNeedsReInit = false; |
|
|
|
|
for(int i=0;i<2;i++){ |
|
|
|
|
for( int i = 0; i < 2; i++ ) |
|
|
|
|
{ |
|
|
|
|
Rect2d tmpCandid = boundingBox; |
|
|
|
|
if(((i == 0)&& !(data->failedLastTime)&& trackerProxy->update(image,tmpCandid)) ||
|
|
|
|
|
((i == 1)&& (detector->detect(imageForDetector,image_blurred,tmpCandid,detectorResults)))){ |
|
|
|
@ -345,7 +359,8 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!false && it!=candidatesRes.end()){ |
|
|
|
|
#if 1 |
|
|
|
|
if(it != candidatesRes.end()){ |
|
|
|
|
resample(imageForDetector,candidates[it - candidatesRes.begin()],standardPatch); |
|
|
|
|
dfprintf((stderr,"%d %f %f\n",data->frameNum,tldModel->Sc(standardPatch),tldModel->Sr(standardPatch))); |
|
|
|
|
if(candidatesRes.size() == 2 && it == (candidatesRes.begin() + 1)) |
|
|
|
@ -353,6 +368,7 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox){ |
|
|
|
|
}else{ |
|
|
|
|
dfprintf((stderr,"%d x x\n",data->frameNum)); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if(*it > CORE_THRESHOLD){ |
|
|
|
|
data->confident = true; |
|
|
|
@ -398,7 +414,8 @@ timeStampPositiveNext(0),timeStampNegativeNext(0),params_(params),boundingBox_(b |
|
|
|
|
std::vector<Rect2d> closest,scanGrid; |
|
|
|
|
Mat scaledImg,blurredImg,image_blurred; |
|
|
|
|
|
|
|
|
|
double scale=scaleAndBlur(image,cvRound(log(1.0*boundingBox.width/(minSize.width))/log(SCALE_STEP)),scaledImg,blurredImg,GaussBlurKernelSize); |
|
|
|
|
double scale = scaleAndBlur(image,cvRound(log(1.0 * boundingBox.width / (minSize.width)) / log(SCALE_STEP)), |
|
|
|
|
scaledImg,blurredImg,GaussBlurKernelSize,SCALE_STEP); |
|
|
|
|
GaussianBlur(image,image_blurred,GaussBlurKernelSize,0.0); |
|
|
|
|
TLDDetector::generateScanGrid(image.rows,image.cols,minSize,scanGrid); |
|
|
|
|
getClosestN(scanGrid,Rect2d(boundingBox.x / scale,boundingBox.y / scale,boundingBox.width / scale,boundingBox.height / scale),10,closest); |
|
|
|
@ -464,22 +481,29 @@ void TLDDetector::generateScanGrid(int rows,int cols,Size initBox,std::vector<Re |
|
|
|
|
res.clear(); |
|
|
|
|
//scales step: SCALE_STEP; hor step: 10% of width; verstep: 10% of height; minsize: 20pix
|
|
|
|
|
for(double h = initBox.height, w = initBox.width;h < cols && w < rows;){ |
|
|
|
|
for(double x=0;(x+w+1.0)<=cols;x+=(0.1*w)){ |
|
|
|
|
for(double y=0;(y+h+1.0)<=rows;y+=(0.1*h)){ |
|
|
|
|
for( double x = 0; (x + w + 1.0) <= cols; x += (0.1 * w)) |
|
|
|
|
{ |
|
|
|
|
for(double y = 0; (y + h + 1.0) <= rows; y += (0.1 * h)) |
|
|
|
|
res.push_back(Rect2d(x,y,w,h)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(withScaling){ |
|
|
|
|
if(h<=initBox.height){ |
|
|
|
|
if( withScaling ) |
|
|
|
|
{ |
|
|
|
|
if( h <= initBox.height ) |
|
|
|
|
{ |
|
|
|
|
h /= SCALE_STEP; w /= SCALE_STEP; |
|
|
|
|
if(h<20 || w<20){ |
|
|
|
|
if( h < 20 || w < 20 ) |
|
|
|
|
{ |
|
|
|
|
h = initBox.height * SCALE_STEP; w = initBox.width * SCALE_STEP; |
|
|
|
|
CV_Assert(h > initBox.height || w > initBox.width); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
h *= SCALE_STEP; w *= SCALE_STEP; |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -505,7 +529,8 @@ bool TLDDetector::detect(const Mat& img,const Mat& imgBlurred,Rect2d& res,std::v |
|
|
|
|
Rect2d maxScRect; |
|
|
|
|
|
|
|
|
|
START_TICK("detector"); |
|
|
|
|
do{ |
|
|
|
|
do |
|
|
|
|
{ |
|
|
|
|
Mat_<double> intImgP,intImgP2; |
|
|
|
|
computeIntegralImages(resized_img,intImgP,intImgP2); |
|
|
|
|
|
|
|
|
@ -548,7 +573,8 @@ bool TLDDetector::detect(const Mat& img,const Mat& imgBlurred,Rect2d& res,std::v |
|
|
|
|
scale *= SCALE_STEP; |
|
|
|
|
resize(img,resized_img,size,0,0,DOWNSCALE_MODE); |
|
|
|
|
GaussianBlur(resized_img,blurred_img,GaussBlurKernelSize,0.0f); |
|
|
|
|
}while(size.width>=initSize.width && size.height>=initSize.height); |
|
|
|
|
} |
|
|
|
|
while( size.width >= initSize.width && size.height >= initSize.height ); |
|
|
|
|
END_TICK("detector"); |
|
|
|
|
|
|
|
|
|
dfprintf((stdout,"after NCC: nneg = %d npos = %d\n",nneg,npos)); |
|
|
|
@ -586,84 +612,88 @@ bool TLDDetector::patchVariance(Mat_<double>& intImgP,Mat_<double>& intImgP2,dou |
|
|
|
|
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); |
|
|
|
|
p = (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); |
|
|
|
|
p2 = (A + D - B - C) / (width * height); |
|
|
|
|
|
|
|
|
|
return ((p2 - p * p) > VARIANCE_THRESHOLD * originalVariance); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double TrackerTLDModel::ensembleClassifierNum(const uchar* data){ |
|
|
|
|
double TrackerTLDModel::ensembleClassifierNum(const uchar* data) |
|
|
|
|
{ |
|
|
|
|
double p = 0; |
|
|
|
|
for(int k=0;k<(int)classifiers.size();k++){ |
|
|
|
|
for( int k = 0; k < (int)classifiers.size(); k++ ) |
|
|
|
|
p += classifiers[k].posteriorProbabilityFast(data); |
|
|
|
|
} |
|
|
|
|
p /= classifiers.size(); |
|
|
|
|
return p; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double TrackerTLDModel::Sr(const Mat_<uchar>& patch){ |
|
|
|
|
double TrackerTLDModel::Sr(const Mat_<uchar>& patch) |
|
|
|
|
{ |
|
|
|
|
double splus = 0.0, sminus = 0.0; |
|
|
|
|
for(int i=0;i<(int)positiveExamples.size();i++){ |
|
|
|
|
for( int i = 0; i < (int)positiveExamples.size(); i++ ) |
|
|
|
|
splus = std::max(splus, 0.5 * (NCC(positiveExamples[i],patch) + 1.0)); |
|
|
|
|
} |
|
|
|
|
for(int i=0;i<(int)negativeExamples.size();i++){ |
|
|
|
|
for( int i = 0; i < (int)negativeExamples.size(); i++ ) |
|
|
|
|
sminus = std::max(sminus, 0.5 * (NCC(negativeExamples[i],patch) + 1.0)); |
|
|
|
|
} |
|
|
|
|
if(splus+sminus==0.0){ |
|
|
|
|
if( splus + sminus == 0.0) |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
return splus / (sminus + splus); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double TrackerTLDModel::Sc(const Mat_<uchar>& patch){ |
|
|
|
|
double TrackerTLDModel::Sc(const Mat_<uchar>& patch) |
|
|
|
|
{ |
|
|
|
|
double splus = 0.0,sminus = 0.0; |
|
|
|
|
int med = getMedian(timeStampsPositive); |
|
|
|
|
for(int i=0;i<(int)positiveExamples.size();i++){ |
|
|
|
|
if((int)timeStampsPositive[i]<=med){ |
|
|
|
|
for( int i = 0; i < (int)positiveExamples.size(); i++ ) |
|
|
|
|
{ |
|
|
|
|
if( (int)timeStampsPositive[i] <= med ) |
|
|
|
|
splus = std::max(splus, 0.5 * (NCC(positiveExamples[i],patch) + 1.0)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for(int i=0;i<(int)negativeExamples.size();i++){ |
|
|
|
|
for( int i = 0; i < (int)negativeExamples.size(); i++ ) |
|
|
|
|
sminus = std::max(sminus, 0.5 * (NCC(negativeExamples[i],patch) + 1.0)); |
|
|
|
|
} |
|
|
|
|
if(splus+sminus==0.0){ |
|
|
|
|
if( splus + sminus == 0.0 ) |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
return splus / (sminus + splus); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TrackerTLDModel::integrateRelabeled(Mat& img,Mat& imgBlurred,const std::vector<TLDDetector::LabeledPatch>& patches){ |
|
|
|
|
void TrackerTLDModel::integrateRelabeled(Mat& img,Mat& imgBlurred,const std::vector<TLDDetector::LabeledPatch>& patches) |
|
|
|
|
{ |
|
|
|
|
Mat_<uchar> standardPatch(STANDARD_PATCH_SIZE,STANDARD_PATCH_SIZE),blurredPatch(minSize_); |
|
|
|
|
int positiveIntoModel = 0,negativeIntoModel = 0,positiveIntoEnsemble = 0,negativeIntoEnsemble = 0; |
|
|
|
|
for(int k=0;k<(int)patches.size();k++){ |
|
|
|
|
if(patches[k].shouldBeIntegrated){ |
|
|
|
|
for( int k = 0; k < (int)patches.size(); k++ ) |
|
|
|
|
{ |
|
|
|
|
if( patches[k].shouldBeIntegrated ) |
|
|
|
|
{ |
|
|
|
|
resample(img,patches[k].rect,standardPatch); |
|
|
|
|
if(patches[k].isObject){ |
|
|
|
|
if( patches[k].isObject ) |
|
|
|
|
{ |
|
|
|
|
positiveIntoModel++; |
|
|
|
|
pushIntoModel(standardPatch,true); |
|
|
|
|
}else{ |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
negativeIntoModel++; |
|
|
|
|
pushIntoModel(standardPatch,false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef CLOSED_LOOP |
|
|
|
|
if(patches[k].shouldBeIntegrated || (patches[k].isPositive==false)){ |
|
|
|
|
if( patches[k].shouldBeIntegrated || ( patches[k].isPositive == false ) ) |
|
|
|
|
#else |
|
|
|
|
if(patches[k].shouldBeIntegrated){ |
|
|
|
|
if( patches[k].shouldBeIntegrated ) |
|
|
|
|
#endif |
|
|
|
|
{ |
|
|
|
|
resample(imgBlurred,patches[k].rect,blurredPatch); |
|
|
|
|
if(patches[k].isObject){ |
|
|
|
|
if( patches[k].isObject ) |
|
|
|
|
positiveIntoEnsemble++; |
|
|
|
|
}else{ |
|
|
|
|
else |
|
|
|
|
negativeIntoEnsemble++; |
|
|
|
|
} |
|
|
|
|
for(int i=0;i<(int)classifiers.size();i++){ |
|
|
|
|
for( int i = 0; i < (int)classifiers.size(); i++ ) |
|
|
|
|
{ |
|
|
|
|
classifiers[i].integrate(blurredPatch,patches[k].isObject); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -679,35 +709,39 @@ void TrackerTLDModel::integrateRelabeled(Mat& img,Mat& imgBlurred,const std::vec |
|
|
|
|
dfprintf((stdout,"\n")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TrackerTLDModel::integrateAdditional(const std::vector<Mat_<uchar> >& eForModel,const std::vector<Mat_<uchar> >& eForEnsemble,bool isPositive){ |
|
|
|
|
void TrackerTLDModel::integrateAdditional(const std::vector<Mat_<uchar> >& eForModel,const std::vector<Mat_<uchar> >& eForEnsemble,bool isPositive) |
|
|
|
|
{ |
|
|
|
|
int positiveIntoModel = 0,negativeIntoModel = 0,positiveIntoEnsemble = 0,negativeIntoEnsemble = 0; |
|
|
|
|
for(int k=0;k<(int)eForModel.size();k++){ |
|
|
|
|
for( int k = 0; k < (int)eForModel.size(); k++ ) |
|
|
|
|
{ |
|
|
|
|
double sr = Sr(eForModel[k]); |
|
|
|
|
if((sr>THETA_NN)!=isPositive){ |
|
|
|
|
if(isPositive){ |
|
|
|
|
if( ( sr > THETA_NN ) != isPositive ) |
|
|
|
|
{ |
|
|
|
|
if( isPositive ) |
|
|
|
|
{ |
|
|
|
|
positiveIntoModel++; |
|
|
|
|
pushIntoModel(eForModel[k],true); |
|
|
|
|
}else{ |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
negativeIntoModel++; |
|
|
|
|
pushIntoModel(eForModel[k],false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
double p = 0; |
|
|
|
|
for(int i=0;i<(int)classifiers.size();i++){ |
|
|
|
|
for( int i = 0; i < (int)classifiers.size(); i++ ) |
|
|
|
|
p += classifiers[i].posteriorProbability(eForEnsemble[k].data,(int)eForEnsemble[k].step[0]); |
|
|
|
|
} |
|
|
|
|
p /= classifiers.size(); |
|
|
|
|
if((p>ENSEMBLE_THRESHOLD)!=isPositive){ |
|
|
|
|
if(isPositive){ |
|
|
|
|
if( (p > ENSEMBLE_THRESHOLD) != isPositive ) |
|
|
|
|
{ |
|
|
|
|
if( isPositive ) |
|
|
|
|
positiveIntoEnsemble++; |
|
|
|
|
}else{ |
|
|
|
|
else |
|
|
|
|
negativeIntoEnsemble++; |
|
|
|
|
} |
|
|
|
|
for(int i=0;i<(int)classifiers.size();i++){ |
|
|
|
|
for( int i = 0; i < (int)classifiers.size(); i++ ) |
|
|
|
|
classifiers[i].integrate(eForEnsemble[k],isPositive); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if( negativeIntoModel > 0 ) |
|
|
|
|
dfprintf((stdout,"negativeIntoModel = %d ",negativeIntoModel)); |
|
|
|
|
if( positiveIntoModel > 0 ) |
|
|
|
@ -719,19 +753,23 @@ void TrackerTLDModel::integrateAdditional(const std::vector<Mat_<uchar> >& eForM |
|
|
|
|
dfprintf((stdout,"\n")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int TrackerTLDImpl::Pexpert::additionalExamples(std::vector<Mat_<uchar> >& examplesForModel,std::vector<Mat_<uchar> >& examplesForEnsemble){ |
|
|
|
|
int TrackerTLDImpl::Pexpert::additionalExamples(std::vector<Mat_<uchar > >& examplesForModel,std::vector<Mat_<uchar > >& examplesForEnsemble) |
|
|
|
|
{ |
|
|
|
|
examplesForModel.clear();examplesForEnsemble.clear(); |
|
|
|
|
examplesForModel.reserve(100);examplesForEnsemble.reserve(100); |
|
|
|
|
|
|
|
|
|
std::vector<Rect2d> closest,scanGrid; |
|
|
|
|
Mat scaledImg,blurredImg; |
|
|
|
|
|
|
|
|
|
double scale=scaleAndBlur(img_,cvRound(log(1.0*resultBox_.width/(initSize_.width))/log(SCALE_STEP)),scaledImg,blurredImg,GaussBlurKernelSize); |
|
|
|
|
double scale = scaleAndBlur(img_,cvRound(log(1.0 * resultBox_.width / (initSize_.width)) / log(SCALE_STEP)), |
|
|
|
|
scaledImg,blurredImg,GaussBlurKernelSize,SCALE_STEP); |
|
|
|
|
TLDDetector::generateScanGrid(img_.rows,img_.cols,initSize_,scanGrid); |
|
|
|
|
getClosestN(scanGrid,Rect2d(resultBox_.x / scale,resultBox_.y / scale,resultBox_.width / scale,resultBox_.height / scale),10,closest); |
|
|
|
|
|
|
|
|
|
for(int i=0;i<(int)closest.size();i++){ |
|
|
|
|
for(int j=0;j<10;j++){ |
|
|
|
|
for( int i = 0; i < (int)closest.size(); i++ ) |
|
|
|
|
{ |
|
|
|
|
for( int j = 0; j < 10; j++ ) |
|
|
|
|
{ |
|
|
|
|
Point2f center; |
|
|
|
|
Size2f size; |
|
|
|
|
Mat_<uchar> standardPatch(STANDARD_PATCH_SIZE,STANDARD_PATCH_SIZE),blurredPatch(initSize_); |
|
|
|
@ -741,8 +779,10 @@ int TrackerTLDImpl::Pexpert::additionalExamples(std::vector<Mat_<uchar> >& examp |
|
|
|
|
size.height = (float)(closest[i].height * rng.uniform((double)0.99,(double)1.01)); |
|
|
|
|
float angle = (float)rng.uniform(-5.0,5.0); |
|
|
|
|
|
|
|
|
|
for(int y=0;y<standardPatch.rows;y++){ |
|
|
|
|
for(int x=0;x<standardPatch.cols;x++){ |
|
|
|
|
for( int y = 0; y < standardPatch.rows; y++ ) |
|
|
|
|
{ |
|
|
|
|
for( int x = 0; x < standardPatch.cols; x++ ) |
|
|
|
|
{ |
|
|
|
|
standardPatch(x,y) += (uchar)rng.gaussian(5.0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -760,14 +800,16 @@ int TrackerTLDImpl::Pexpert::additionalExamples(std::vector<Mat_<uchar> >& examp |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool TrackerTLDImpl::Nexpert::operator()(Rect2d box){ |
|
|
|
|
if(overlap(resultBox_,box)<0.2){ |
|
|
|
|
bool TrackerTLDImpl::Nexpert::operator()(Rect2d box) |
|
|
|
|
{ |
|
|
|
|
if( overlap(resultBox_,box) < NEXPERT_THRESHOLD ) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Data::Data(Rect2d initBox){ |
|
|
|
|
Data::Data(Rect2d initBox) |
|
|
|
|
{ |
|
|
|
|
double minDim = std::min(initBox.width,initBox.height); |
|
|
|
|
scale = 20.0 / minDim; |
|
|
|
|
minSize.width = (int)(initBox.width * 20.0 / minDim); |
|
|
|
@ -776,20 +818,26 @@ Data::Data(Rect2d initBox){ |
|
|
|
|
dprintf(("minSize = %dx%d\n",minSize.width,minSize.height)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Data::printme(FILE* port){ |
|
|
|
|
void Data::printme(FILE* port) |
|
|
|
|
{ |
|
|
|
|
dfprintf((port,"Data:\n")); |
|
|
|
|
dfprintf((port,"\tframeNum = %d\n",frameNum)); |
|
|
|
|
dfprintf((port,"\tconfident = %s\n",confident?"true":"false")); |
|
|
|
|
dfprintf((port,"\tfailedLastTime = %s\n",failedLastTime?"true":"false")); |
|
|
|
|
dfprintf((port,"\tminSize = %dx%d\n",minSize.width,minSize.height)); |
|
|
|
|
} |
|
|
|
|
void TrackerTLDModel::printme(FILE* port){ |
|
|
|
|
|
|
|
|
|
void TrackerTLDModel::printme(FILE* port) |
|
|
|
|
{ |
|
|
|
|
dfprintf((port,"TrackerTLDModel:\n")); |
|
|
|
|
dfprintf((port,"\tpositiveExamples.size() = %d\n",(int)positiveExamples.size())); |
|
|
|
|
dfprintf((port,"\tnegativeExamples.size() = %d\n",(int)negativeExamples.size())); |
|
|
|
|
} |
|
|
|
|
void MyMouseCallbackDEBUG::onMouse( int event, int x, int y){ |
|
|
|
|
if(event== EVENT_LBUTTONDOWN){ |
|
|
|
|
|
|
|
|
|
void MyMouseCallbackDEBUG::onMouse( int event, int x, int y) |
|
|
|
|
{ |
|
|
|
|
if( event == EVENT_LBUTTONDOWN ) |
|
|
|
|
{ |
|
|
|
|
Mat imgCanvas; |
|
|
|
|
img_.copyTo(imgCanvas); |
|
|
|
|
TrackerTLDModel* tldModel = ((TrackerTLDModel*)static_cast<TrackerModel*>(detector_->model)); |
|
|
|
@ -811,7 +859,8 @@ void MyMouseCallbackDEBUG::onMouse( int event, int x, int y){ |
|
|
|
|
int dx = initSize.width / 10, dy = initSize.height / 10, |
|
|
|
|
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")); |
|
|
|
|
tldModel->prepareClassifiers((int)blurred_img.step[0]); |
|
|
|
|
dfprintf((stderr,"p = %f\n",(tldModel->ensembleClassifierNum(&blurred_img.at<uchar>(dy * j,dx * i))))); |
|
|
|
|
fprintf(stderr,"ensembleClassifier = %s\n", |
|
|
|
@ -829,23 +878,31 @@ void MyMouseCallbackDEBUG::onMouse( int event, int x, int y){ |
|
|
|
|
waitKey(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
void TrackerTLDModel::pushIntoModel(const Mat_<uchar>& example,bool positive){ |
|
|
|
|
|
|
|
|
|
void TrackerTLDModel::pushIntoModel(const Mat_<uchar>& example, bool positive) |
|
|
|
|
{ |
|
|
|
|
std::vector<Mat_<uchar> >* proxyV; |
|
|
|
|
unsigned int* proxyN; |
|
|
|
|
std::vector<unsigned int>* proxyT; |
|
|
|
|
if(positive){ |
|
|
|
|
int* proxyN; |
|
|
|
|
std::vector<int>* proxyT; |
|
|
|
|
if( positive ) |
|
|
|
|
{ |
|
|
|
|
proxyV = &positiveExamples; |
|
|
|
|
proxyN = &timeStampPositiveNext; |
|
|
|
|
proxyT = &timeStampsPositive; |
|
|
|
|
}else{ |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
proxyV = &negativeExamples; |
|
|
|
|
proxyN = &timeStampNegativeNext; |
|
|
|
|
proxyT = &timeStampsNegative; |
|
|
|
|
} |
|
|
|
|
if(proxyV->size()<MAX_EXAMPLES_IN_MODEL){ |
|
|
|
|
if( proxyV->size() < MAX_EXAMPLES_IN_MODEL ) |
|
|
|
|
{ |
|
|
|
|
proxyV->push_back(example); |
|
|
|
|
proxyT->push_back(*proxyN); |
|
|
|
|
}else{ |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
int index = rng.uniform((int)0,(int)proxyV->size()); |
|
|
|
|
(*proxyV)[index] = example; |
|
|
|
|
(*proxyT)[index] = (*proxyN); |
|
|
|
|