Commit 3011e80f authored by Vladimir's avatar Vladimir

Merge pull request #2 from Auron-X/TLD_fixes_&_optimizations

Tld fixes & optimizations
parents 26f16e64 7569b8a1
...@@ -118,7 +118,7 @@ int main() ...@@ -118,7 +118,7 @@ int main()
// VideoCapture cap(0); // VideoCapture cap(0);
// if( !cap.isOpened() ) // if( !cap.isOpened() )
// { // {
// cout << "Video stream error"; // cout << "Video stream error";
// return; // return;
// } // }
//cap >> frame; //cap >> frame;
......
...@@ -24,7 +24,6 @@ namespace cv{ ...@@ -24,7 +24,6 @@ namespace cv{
Mat_<double> HShist, Vhist; Mat_<double> HShist, Vhist;
}; };
TrackingHistogram _origHist; TrackingHistogram _origHist;
const TrackingFunctionPF & operator = (const TrackingFunctionPF &); const TrackingFunctionPF & operator = (const TrackingFunctionPF &);
}; };
......
...@@ -53,7 +53,7 @@ namespace cv ...@@ -53,7 +53,7 @@ namespace cv
} }
// Calculate posterior probability, that the patch belongs to the current EC model // Calculate posterior probability, that the patch belongs to the current EC model
double TLDDetector::ensembleClassifierNum(const uchar* data) double TLDDetector::ensembleClassifierNum(const uchar* data)
{ {
double p = 0; double p = 0;
for (int k = 0; k < (int)classifiers.size(); k++) for (int k = 0; k < (int)classifiers.size(); k++)
...@@ -146,7 +146,6 @@ namespace cv ...@@ -146,7 +146,6 @@ namespace cv
Rect2d maxScRect; Rect2d maxScRect;
//Detection part //Detection part
//To fix: use precalculated BB
do do
{ {
Mat_<double> intImgP, intImgP2; Mat_<double> intImgP, intImgP2;
......
...@@ -70,7 +70,6 @@ namespace cv ...@@ -70,7 +70,6 @@ namespace cv
public: public:
TLDDetector(){} TLDDetector(){}
~TLDDetector(){} ~TLDDetector(){}
inline double ensembleClassifierNum(const uchar* data); inline double ensembleClassifierNum(const uchar* data);
inline void prepareClassifiers(int rowstep); inline void prepareClassifiers(int rowstep);
double Sr(const Mat_<uchar>& patch); double Sr(const Mat_<uchar>& patch);
...@@ -89,8 +88,8 @@ namespace cv ...@@ -89,8 +88,8 @@ namespace cv
}; };
bool detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize); bool detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize);
protected: protected:
friend class MyMouseCallbackDEBUG; friend class MyMouseCallbackDEBUG;
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); }
......
...@@ -55,8 +55,7 @@ namespace cv ...@@ -55,8 +55,7 @@ namespace cv
measurements.assign(meas.begin() + beg, meas.begin() + end); measurements.assign(meas.begin() + beg, meas.begin() + end);
offset.assign(mpc, Point2i(0, 0)); offset.assign(mpc, Point2i(0, 0));
} }
// Calculate measure locations from 15x15 grid on minSize patches
// Calculate measure locations from 15x15 grid on minSize patches
void TLDEnsembleClassifier::stepPrefSuff(std::vector<Vec4b>& arr, int pos, int len, int gridSize) void TLDEnsembleClassifier::stepPrefSuff(std::vector<Vec4b>& arr, int pos, int len, int gridSize)
{ {
#if 0 #if 0
...@@ -92,7 +91,7 @@ namespace cv ...@@ -92,7 +91,7 @@ namespace cv
} }
#endif #endif
} }
// Calculate offsets for classifier // Calculate offsets for classifier
void TLDEnsembleClassifier::prepareClassifier(int rowstep) void TLDEnsembleClassifier::prepareClassifier(int rowstep)
{ {
...@@ -106,7 +105,7 @@ namespace cv ...@@ -106,7 +105,7 @@ namespace cv
} }
} }
} }
// Integrate patch into the Ensemble Classifier model // Integrate patch into the Ensemble Classifier model
void TLDEnsembleClassifier::integrate(const Mat_<uchar>& patch, bool isPositive) void TLDEnsembleClassifier::integrate(const Mat_<uchar>& patch, bool isPositive)
{ {
...@@ -137,7 +136,7 @@ namespace cv ...@@ -137,7 +136,7 @@ namespace cv
return posNum / (posNum + negNum); return posNum / (posNum + negNum);
} }
// Calculate the 13-bit fern index // Calculate the 13-bit fern index
int TLDEnsembleClassifier::codeFast(const uchar* data) const int TLDEnsembleClassifier::codeFast(const uchar* data) const
{ {
int position = 0; int position = 0;
...@@ -188,7 +187,7 @@ namespace cv ...@@ -188,7 +187,7 @@ namespace cv
stepPrefSuff(measurements, 2, size.height, gridSize); stepPrefSuff(measurements, 2, size.height, gridSize);
stepPrefSuff(measurements, 3, size.height, gridSize); stepPrefSuff(measurements, 3, size.height, gridSize);
//Compile fern classifiers //Compile fern classifiers
for (int i = 0, howMany = (int)measurements.size() / measurePerClassifier; i < howMany; i++) for (int i = 0, howMany = (int)measurements.size() / measurePerClassifier; i < howMany; i++)
classifiers.push_back(TLDEnsembleClassifier(measurements, i * measurePerClassifier, (i + 1) * measurePerClassifier)); classifiers.push_back(TLDEnsembleClassifier(measurements, i * measurePerClassifier, (i + 1) * measurePerClassifier));
......
...@@ -65,6 +65,5 @@ namespace cv ...@@ -65,6 +65,5 @@ namespace cv
int lastStep_; int lastStep_;
}; };
} }
} }
\ No newline at end of file
...@@ -64,13 +64,12 @@ namespace cv ...@@ -64,13 +64,12 @@ namespace cv
//Calculate the variance in initial BB //Calculate the variance in initial BB
originalVariance_ = variance(image(boundingBox)); originalVariance_ = variance(image(boundingBox));
//Find the scale //Find the scale
double scale = scaleAndBlur(image, cvRound(log(1.0 * boundingBox.width / (minSize.width)) / log(SCALE_STEP)), double scale = scaleAndBlur(image, cvRound(log(1.0 * boundingBox.width / (minSize.width)) / log(SCALE_STEP)),
scaledImg, blurredImg, GaussBlurKernelSize, SCALE_STEP); scaledImg, blurredImg, GaussBlurKernelSize, SCALE_STEP);
GaussianBlur(image, image_blurred, GaussBlurKernelSize, 0.0); GaussianBlur(image, image_blurred, GaussBlurKernelSize, 0.0);
TLDDetector::generateScanGrid(image.rows, image.cols, minSize_, scanGrid); TLDDetector::generateScanGrid(image.rows, image.cols, minSize_, scanGrid);
getClosestN(scanGrid, Rect2d(boundingBox.x / scale, boundingBox.y / scale, boundingBox.width / scale, getClosestN(scanGrid, Rect2d(boundingBox.x / scale, boundingBox.y / scale, boundingBox.width / scale,
boundingBox.height / scale), 10, closest); boundingBox.height / scale), 10, closest);
Mat_<uchar> blurredPatch(minSize); Mat_<uchar> blurredPatch(minSize);
...@@ -271,7 +270,7 @@ namespace cv ...@@ -271,7 +270,7 @@ namespace cv
} }
} }
} }
\ No newline at end of file
...@@ -51,7 +51,6 @@ namespace cv ...@@ -51,7 +51,6 @@ namespace cv
namespace tld namespace tld
{ {
class TrackerTLDModel : public TrackerModel class TrackerTLDModel : public TrackerModel
...@@ -75,14 +74,13 @@ namespace cv ...@@ -75,14 +74,13 @@ namespace cv
protected: protected:
Size minSize_; Size minSize_;
TrackerTLD::Params params_; TrackerTLD::Params params_;
void pushIntoModel(const Mat_<uchar>& example, bool positive); void pushIntoModel(const Mat_<uchar>& example, bool positive);
void modelEstimationImpl(const std::vector<Mat>& /*responses*/){} void modelEstimationImpl(const std::vector<Mat>& /*responses*/){}
void modelUpdateImpl(){} void modelUpdateImpl(){}
Rect2d boundingBox_; Rect2d boundingBox_;
RNG rng; RNG rng;
}; };
} }
......
...@@ -89,7 +89,7 @@ bool TrackerTLDImpl::initImpl(const Mat& image, const Rect2d& boundingBox) ...@@ -89,7 +89,7 @@ bool TrackerTLDImpl::initImpl(const Mat& image, const Rect2d& boundingBox)
myBoundingBox.width *= scale; myBoundingBox.width *= scale;
myBoundingBox.height *= scale; myBoundingBox.height *= scale;
} }
model = Ptr<TrackerTLDModel>(new TrackerTLDModel(params, image_gray, myBoundingBox, data->getMinSize())); model = Ptr<TrackerTLDModel>(new TrackerTLDModel(params, image_gray, myBoundingBox, data->getMinSize()));
data->confident = false; data->confident = false;
data->failedLastTime = false; data->failedLastTime = false;
...@@ -119,7 +119,7 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox) ...@@ -119,7 +119,7 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
for( int i = 0; i < 2; i++ ) for( int i = 0; i < 2; i++ )
{ {
Rect2d tmpCandid = boundingBox; Rect2d tmpCandid = boundingBox;
if( ( (i == 0) && !data->failedLastTime && trackerProxy->update(image, tmpCandid) ) || if( ( (i == 0) && !data->failedLastTime && trackerProxy->update(image, tmpCandid) ) ||
((i == 1) && (tldModel->detector->detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize())))) ((i == 1) && (tldModel->detector->detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize()))))
{ {
candidates.push_back(tmpCandid); candidates.push_back(tmpCandid);
...@@ -292,6 +292,6 @@ void Data::printme(FILE* port) ...@@ -292,6 +292,6 @@ void Data::printme(FILE* port)
dfprintf((port, "\tminSize = %dx%d\n", minSize.width, minSize.height)); dfprintf((port, "\tminSize = %dx%d\n", minSize.width, minSize.height));
} }
} }
} }
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
#include<algorithm> #include<algorithm>
#include<limits.h> #include<limits.h>
namespace cv namespace cv
{ {
TrackerTLD::Params::Params(){} TrackerTLD::Params::Params(){}
...@@ -60,7 +60,6 @@ void TrackerTLD::Params::write(cv::FileStorage& /*fs*/) const {} ...@@ -60,7 +60,6 @@ void TrackerTLD::Params::write(cv::FileStorage& /*fs*/) const {}
namespace tld namespace tld
{ {
class TrackerProxy class TrackerProxy
{ {
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#include "tldUtils.hpp" #include "tldUtils.hpp"
namespace cv namespace cv
{ {
namespace tld namespace tld
{ {
......
...@@ -63,7 +63,7 @@ namespace cv ...@@ -63,7 +63,7 @@ namespace cv
/* /*
* TODO: * TODO:
* add "non-detected" answer in algo --> test it with 2 rects --> frame-by-frame debug in TLD --> test it!! * add "non-detected" answer in algo --> test it with 2 rects --> frame-by-frame debug in TLD --> test it!!
* take all parameters out * take all parameters out
* asessment framework * asessment framework
* *
* *
......
...@@ -385,7 +385,7 @@ TrackerSamplerPF::Params::Params(){ ...@@ -385,7 +385,7 @@ TrackerSamplerPF::Params::Params(){
iterationNum=20; iterationNum=20;
particlesNum=100; particlesNum=100;
alpha=0.9; alpha=0.9;
std=(Mat_<double>(1,4)<<15.0,15.0,15.0,15.0); std=(Mat_<double>(1,4)<<15.0,15.0,15.0,15.0);
} }
TrackerSamplerPF::TrackerSamplerPF(const Mat& chosenRect,const TrackerSamplerPF::Params &parameters): TrackerSamplerPF::TrackerSamplerPF(const Mat& chosenRect,const TrackerSamplerPF::Params &parameters):
params( parameters ),_function(new TrackingFunctionPF(chosenRect)){ params( parameters ),_function(new TrackingFunctionPF(chosenRect)){
......
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