Commit c06bb0dc authored by Alex Leontiev's avatar Alex Leontiev

Vadim

parent 296a864a
...@@ -1022,16 +1022,7 @@ class CV_EXPORTS_W TrackerMedianFlow : public Tracker ...@@ -1022,16 +1022,7 @@ class CV_EXPORTS_W TrackerMedianFlow : public Tracker
void write( FileStorage& /*fs*/ ) const; void write( FileStorage& /*fs*/ ) const;
}; };
TrackerMedianFlow( const TrackerMedianFlow::Params &parameters = TrackerMedianFlow::Params() ); BOILERPLATE_CODE("MEDIANFLOW",TrackerMedianFlow);
virtual ~TrackerMedianFlow();
void read( const FileNode& fn );
void write( FileStorage& fs ) const;
protected:
bool initImpl( const Mat& image, const Rect2d& boundingBox );
bool updateImpl( const Mat& image, Rect2d& boundingBox );
Params params;
AlgorithmInfo* info() const;
}; };
class CV_EXPORTS_W TrackerTLD : public Tracker class CV_EXPORTS_W TrackerTLD : public Tracker
...@@ -1044,18 +1035,7 @@ class CV_EXPORTS_W TrackerTLD : public Tracker ...@@ -1044,18 +1035,7 @@ class CV_EXPORTS_W TrackerTLD : public Tracker
void write( FileStorage& /*fs*/ ) const; void write( FileStorage& /*fs*/ ) const;
}; };
TrackerTLD( const TrackerTLD::Params &parameters = TrackerTLD::Params() ); BOILERPLATE_CODE("TLD",TrackerTLD);
virtual ~TrackerTLD();
void read( const FileNode& fn );
void write( FileStorage& fs ) const;
class Private{public: virtual ~Private(){}};
protected:
bool initImpl( const Mat& image, const Rect2d& boundingBox );
bool updateImpl( const Mat& image, Rect2d& boundingBox );
Params params;
std::vector<Ptr<Private> > privateInfo;
AlgorithmInfo* info() const;
}; };
} /* namespace cv */ } /* namespace cv */
......
...@@ -100,7 +100,7 @@ private: ...@@ -100,7 +100,7 @@ private:
std::vector<uchar> x1,y1,x2,y2; std::vector<uchar> x1,y1,x2,y2;
}; };
class TrackerProxy : public TrackerTLD::Private{ class TrackerProxy{
public: public:
virtual bool init( const Mat& image, const Rect2d& boundingBox)=0; virtual bool init( const Mat& image, const Rect2d& boundingBox)=0;
virtual bool update(const Mat& image, Rect2d& boundingBox)=0; virtual bool update(const Mat& image, Rect2d& boundingBox)=0;
......
...@@ -112,6 +112,8 @@ Ptr<Tracker> Tracker::create( const String& trackerType ) ...@@ -112,6 +112,8 @@ Ptr<Tracker> Tracker::create( const String& trackerType )
{ {
BOILERPLATE_CODE("MIL",TrackerMIL); BOILERPLATE_CODE("MIL",TrackerMIL);
BOILERPLATE_CODE("BOOSTING",TrackerBoosting); BOILERPLATE_CODE("BOOSTING",TrackerBoosting);
BOILERPLATE_CODE("MEDIANFLOW",TrackerMedianFlow);
BOILERPLATE_CODE("TLD",TrackerTLD);
return Ptr<Tracker>(); return Ptr<Tracker>();
} }
......
...@@ -74,9 +74,9 @@ namespace cv ...@@ -74,9 +74,9 @@ namespace cv
* bring "out" all the parameters to TrackerMedianFlow::Param * bring "out" all the parameters to TrackerMedianFlow::Param
*/ */
class MedianFlowCore{ class TrackerMedianFlowImpl : public TrackerMedianFlow{
public: public:
MedianFlowCore(TrackerMedianFlow::Params paramsIn):termcrit(TermCriteria::COUNT|TermCriteria::EPS,20,0.3){params=paramsIn;} TrackerMedianFlowImpl(TrackerMedianFlow::Params paramsIn):termcrit(TermCriteria::COUNT|TermCriteria::EPS,20,0.3){params=paramsIn;isInit=false;}
bool medianFlowImpl(Mat oldImage,Mat newImage,Rect2d& oldBox); bool medianFlowImpl(Mat oldImage,Mat newImage,Rect2d& oldBox);
private: private:
Rect2d vote(const std::vector<Point2f>& oldPoints,const std::vector<Point2f>& newPoints,const Rect2d& oldRect,Point2f& mD); Rect2d vote(const std::vector<Point2f>& oldPoints,const std::vector<Point2f>& newPoints,const Rect2d& oldRect,Point2f& mD);
...@@ -99,14 +99,12 @@ class MedianFlowCore{ ...@@ -99,14 +99,12 @@ class MedianFlowCore{
class TrackerMedianFlowModel : public TrackerModel{ class TrackerMedianFlowModel : public TrackerModel{
public: public:
TrackerMedianFlowModel(TrackerMedianFlow::Params params):medianFlow(params){} TrackerMedianFlowModel(TrackerMedianFlow::Params /*params*/){}
MedianFlowCore* getMedianFlowCore(){return &medianFlow;}
Rect2d getBoundingBox(){return boundingBox_;} Rect2d getBoundingBox(){return boundingBox_;}
void setBoudingBox(Rect2d boundingBox){boundingBox_=boundingBox;} void setBoudingBox(Rect2d boundingBox){boundingBox_=boundingBox;}
Mat getImage(){return image_;} Mat getImage(){return image_;}
void setImage(const Mat& image){image.copyTo(image_);} void setImage(const Mat& image){image.copyTo(image_);}
protected: protected:
MedianFlowCore medianFlow;
Rect2d boundingBox_; Rect2d boundingBox_;
Mat image_; Mat image_;
void modelEstimationImpl( const std::vector<Mat>& /*responses*/ ){} void modelEstimationImpl( const std::vector<Mat>& /*responses*/ ){}
...@@ -128,38 +126,32 @@ void TrackerMedianFlow::Params::write( cv::FileStorage& fs ) const{ ...@@ -128,38 +126,32 @@ void TrackerMedianFlow::Params::write( cv::FileStorage& fs ) const{
fs << "pointsInGrid" << pointsInGrid; fs << "pointsInGrid" << pointsInGrid;
} }
TrackerMedianFlow::~TrackerMedianFlow() void TrackerMedianFlowImpl::read( const cv::FileNode& fn )
{
}
void TrackerMedianFlow::read( const cv::FileNode& fn )
{ {
params.read( fn ); params.read( fn );
} }
void TrackerMedianFlow::write( cv::FileStorage& fs ) const void TrackerMedianFlowImpl::write( cv::FileStorage& fs ) const
{ {
params.write( fs ); params.write( fs );
} }
TrackerMedianFlow::TrackerMedianFlow( const TrackerMedianFlow::Params &parameters) : Ptr<TrackerMedianFlow> TrackerMedianFlow::createTracker(const TrackerMedianFlow::Params &parameters){
params( parameters ){ return Ptr<TrackerMedianFlowImpl>(new TrackerMedianFlowImpl(parameters));
isInit = false;
} }
bool TrackerMedianFlow::initImpl( const Mat& image, const Rect2d& boundingBox ){ bool TrackerMedianFlowImpl::initImpl( const Mat& image, const Rect2d& boundingBox ){
model=Ptr<TrackerMedianFlowModel>(new TrackerMedianFlowModel(params)); model=Ptr<TrackerMedianFlowModel>(new TrackerMedianFlowModel(params));
((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->setImage(image); ((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->setImage(image);
((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->setBoudingBox(boundingBox); ((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->setBoudingBox(boundingBox);
return true; return true;
} }
bool TrackerMedianFlow::updateImpl( const Mat& image, Rect2d& boundingBox ){ bool TrackerMedianFlowImpl::updateImpl( const Mat& image, Rect2d& boundingBox ){
Mat oldImage=((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->getImage(); Mat oldImage=((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->getImage();
Rect2d oldBox=((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->getBoundingBox(); Rect2d oldBox=((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->getBoundingBox();
if(!(((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->getMedianFlowCore())-> if(!medianFlowImpl(oldImage,image,oldBox)){
medianFlowImpl(oldImage,image,oldBox)){
return false; return false;
} }
boundingBox=oldBox; boundingBox=oldBox;
...@@ -168,7 +160,7 @@ bool TrackerMedianFlow::updateImpl( const Mat& image, Rect2d& boundingBox ){ ...@@ -168,7 +160,7 @@ bool TrackerMedianFlow::updateImpl( const Mat& image, Rect2d& boundingBox ){
return true; return true;
} }
std::string MedianFlowCore::type2str(int type) { std::string TrackerMedianFlowImpl::type2str(int type) {
std::string r; std::string r;
uchar depth = type & CV_MAT_DEPTH_MASK; uchar depth = type & CV_MAT_DEPTH_MASK;
...@@ -190,7 +182,7 @@ std::string MedianFlowCore::type2str(int type) { ...@@ -190,7 +182,7 @@ std::string MedianFlowCore::type2str(int type) {
return r; return r;
} }
bool MedianFlowCore::medianFlowImpl(Mat oldImage,Mat newImage,Rect2d& oldBox){ bool TrackerMedianFlowImpl::medianFlowImpl(Mat oldImage,Mat newImage,Rect2d& oldBox){
std::vector<Point2f> pointsToTrackOld,pointsToTrackNew; std::vector<Point2f> pointsToTrackOld,pointsToTrackNew;
Mat oldImage_gray,newImage_gray; Mat oldImage_gray,newImage_gray;
...@@ -251,7 +243,7 @@ bool MedianFlowCore::medianFlowImpl(Mat oldImage,Mat newImage,Rect2d& oldBox){ ...@@ -251,7 +243,7 @@ bool MedianFlowCore::medianFlowImpl(Mat oldImage,Mat newImage,Rect2d& oldBox){
return true; return true;
} }
Rect2d MedianFlowCore::vote(const std::vector<Point2f>& oldPoints,const std::vector<Point2f>& newPoints,const Rect2d& oldRect,Point2f& mD){ Rect2d TrackerMedianFlowImpl::vote(const std::vector<Point2f>& oldPoints,const std::vector<Point2f>& newPoints,const Rect2d& oldRect,Point2f& mD){
static int iteration=0;//FIXME -- we don't want this static var in final release static int iteration=0;//FIXME -- we don't want this static var in final release
Rect2d newRect; Rect2d newRect;
Point2d newCenter(oldRect.x+oldRect.width/2.0,oldRect.y+oldRect.height/2.0); Point2d newCenter(oldRect.x+oldRect.width/2.0,oldRect.y+oldRect.height/2.0);
...@@ -310,7 +302,7 @@ Rect2d MedianFlowCore::vote(const std::vector<Point2f>& oldPoints,const std::vec ...@@ -310,7 +302,7 @@ Rect2d MedianFlowCore::vote(const std::vector<Point2f>& oldPoints,const std::vec
} }
template<typename T> template<typename T>
T MedianFlowCore::getMedian(std::vector<T>& values,int size){ T TrackerMedianFlowImpl::getMedian(std::vector<T>& values,int size){
if(size==-1){ if(size==-1){
size=(int)values.size(); size=(int)values.size();
} }
...@@ -323,7 +315,7 @@ T MedianFlowCore::getMedian(std::vector<T>& values,int size){ ...@@ -323,7 +315,7 @@ T MedianFlowCore::getMedian(std::vector<T>& values,int size){
} }
} }
void MedianFlowCore::computeStatistics(std::vector<float>& data,int size){ void TrackerMedianFlowImpl::computeStatistics(std::vector<float>& data,int size){
int binnum=10; int binnum=10;
if(size==-1){ if(size==-1){
size=(int)data.size(); size=(int)data.size();
...@@ -337,11 +329,11 @@ void MedianFlowCore::computeStatistics(std::vector<float>& data,int size){ ...@@ -337,11 +329,11 @@ void MedianFlowCore::computeStatistics(std::vector<float>& data,int size){
dprintf(("[%4f,%4f] -- %4d\n",mini+(maxi-mini)/binnum*i,mini+(maxi-mini)/binnum*(i+1),bins[i])); dprintf(("[%4f,%4f] -- %4d\n",mini+(maxi-mini)/binnum*i,mini+(maxi-mini)/binnum*(i+1),bins[i]));
} }
} }
double MedianFlowCore::l2distance(Point2f p1,Point2f p2){ double TrackerMedianFlowImpl::l2distance(Point2f p1,Point2f p2){
double dx=p1.x-p2.x, dy=p1.y-p2.y; double dx=p1.x-p2.x, dy=p1.y-p2.y;
return sqrt(dx*dx+dy*dy); return sqrt(dx*dx+dy*dy);
} }
void MedianFlowCore::check_FB(const Mat& oldImage,const Mat& newImage, void TrackerMedianFlowImpl::check_FB(const Mat& oldImage,const Mat& newImage,
const std::vector<Point2f>& oldPoints,const std::vector<Point2f>& newPoints,std::vector<bool>& status){ const std::vector<Point2f>& oldPoints,const std::vector<Point2f>& newPoints,std::vector<bool>& status){
if(status.size()==0){ if(status.size()==0){
...@@ -364,7 +356,7 @@ void MedianFlowCore::check_FB(const Mat& oldImage,const Mat& newImage, ...@@ -364,7 +356,7 @@ void MedianFlowCore::check_FB(const Mat& oldImage,const Mat& newImage,
status[i]=(FBerror[i]<FBerrorMedian); status[i]=(FBerror[i]<FBerrorMedian);
} }
} }
void MedianFlowCore::check_NCC(const Mat& oldImage,const Mat& newImage, void TrackerMedianFlowImpl::check_NCC(const Mat& oldImage,const Mat& newImage,
const std::vector<Point2f>& oldPoints,const std::vector<Point2f>& newPoints,std::vector<bool>& status){ const std::vector<Point2f>& oldPoints,const std::vector<Point2f>& newPoints,std::vector<bool>& status){
std::vector<float> NCC(oldPoints.size(),0.0); std::vector<float> NCC(oldPoints.size(),0.0);
......
...@@ -87,6 +87,7 @@ using namespace tld; ...@@ -87,6 +87,7 @@ using namespace tld;
namespace cv namespace cv
{ {
class TLDDetector; class TLDDetector;
class MyMouseCallbackDEBUG{ class MyMouseCallbackDEBUG{
public: public:
...@@ -127,7 +128,6 @@ public: ...@@ -127,7 +128,6 @@ public:
protected: protected:
friend class MyMouseCallbackDEBUG; friend class MyMouseCallbackDEBUG;
Ptr<TrackerModel> model; Ptr<TrackerModel> model;
inline 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)>0.5;} bool ensembleClassifier(const uchar* data,int rowstep){return ensembleClassifierNum(data,rowstep)>0.5;}
double ensembleClassifierNum(const uchar* data,int rowstep); double ensembleClassifierNum(const uchar* data,int rowstep);
...@@ -209,6 +209,25 @@ class TrackerTLDModel : public TrackerModel{ ...@@ -209,6 +209,25 @@ class TrackerTLDModel : public TrackerModel{
std::vector<TLDEnsembleClassifier> classifiers; std::vector<TLDEnsembleClassifier> classifiers;
}; };
class TrackerTLDImpl : public TrackerTLD
{
public:
TrackerTLDImpl( const TrackerTLD::Params &parameters = TrackerTLD::Params() );
void read( const FileNode& fn );
void write( FileStorage& fs ) const;
protected:
bool initImpl( const Mat& image, const Rect2d& boundingBox );
bool updateImpl( const Mat& image, Rect2d& boundingBox );
TrackerTLD::Params params;
Ptr<Data> data;
Ptr<TrackerProxy> tracker;
Ptr<TLDDetector> detector;
};
TrackerTLD::Params::Params(){ TrackerTLD::Params::Params(){
} }
...@@ -218,11 +237,15 @@ void TrackerTLD::Params::read( const cv::FileNode& /*fn*/ ){ ...@@ -218,11 +237,15 @@ void TrackerTLD::Params::read( const cv::FileNode& /*fn*/ ){
void TrackerTLD::Params::write( cv::FileStorage& /*fs*/ ) const{ void TrackerTLD::Params::write( cv::FileStorage& /*fs*/ ) const{
} }
TrackerTLD::TrackerTLD( const TrackerTLD::Params &parameters) : Ptr<TrackerTLD> TrackerTLD::createTracker(const TrackerTLD::Params &parameters){
return Ptr<TrackerTLDImpl>(new TrackerTLDImpl(parameters));
}
TrackerTLDImpl::TrackerTLDImpl( const TrackerTLD::Params &parameters) :
params( parameters ){ params( parameters ){
isInit = false; isInit = false;
privateInfo.push_back(Ptr<TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params> >( tracker=Ptr<TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params> >(
new TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params>())); new TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params>());
} }
TrackerTLD::~TrackerTLD(){ TrackerTLD::~TrackerTLD(){
...@@ -240,9 +263,9 @@ void TrackerTLD::write( cv::FileStorage& fs ) const ...@@ -240,9 +263,9 @@ void TrackerTLD::write( cv::FileStorage& fs ) const
bool TrackerTLD::initImpl(const Mat& image, const Rect2d& boundingBox ){ bool TrackerTLD::initImpl(const Mat& image, const Rect2d& boundingBox ){
Mat image_gray; Mat image_gray;
((TrackerProxy*)static_cast<Private*>(privateInfo[0]))->init(image,boundingBox); tracker->init(image,boundingBox);
cvtColor( image, image_gray, COLOR_BGR2GRAY ); cvtColor( image, image_gray, COLOR_BGR2GRAY );
Data* data=new Data(boundingBox); data=new Data(boundingBox);
double scale=data->getScale(); double scale=data->getScale();
Rect2d myBoundingBox=boundingBox; Rect2d myBoundingBox=boundingBox;
if(scale>1.0){ if(scale>1.0){
...@@ -255,13 +278,10 @@ bool TrackerTLD::initImpl(const Mat& image, const Rect2d& boundingBox ){ ...@@ -255,13 +278,10 @@ bool TrackerTLD::initImpl(const Mat& image, const Rect2d& boundingBox ){
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()));
TLDDetector* detector=new TLDDetector(params,model); detector=new TLDDetector(params,model);
data->confident=false; data->confident=false;
data->failedLastTime=false; data->failedLastTime=false;
privateInfo.push_back(Ptr<TLDDetector>(detector));
privateInfo.push_back(Ptr<Data>(data));
#if !1 #if !1
dprintf(("here I am\n")); dprintf(("here I am\n"));
Mat image_blurred; Mat image_blurred;
......
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