Commit c06bb0dc authored by Alex Leontiev's avatar Alex Leontiev

Vadim

parent 296a864a
......@@ -1022,16 +1022,7 @@ class CV_EXPORTS_W TrackerMedianFlow : public Tracker
void write( FileStorage& /*fs*/ ) const;
};
TrackerMedianFlow( const TrackerMedianFlow::Params &parameters = TrackerMedianFlow::Params() );
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;
BOILERPLATE_CODE("MEDIANFLOW",TrackerMedianFlow);
};
class CV_EXPORTS_W TrackerTLD : public Tracker
......@@ -1044,18 +1035,7 @@ class CV_EXPORTS_W TrackerTLD : public Tracker
void write( FileStorage& /*fs*/ ) const;
};
TrackerTLD( const TrackerTLD::Params &parameters = TrackerTLD::Params() );
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;
BOILERPLATE_CODE("TLD",TrackerTLD);
};
} /* namespace cv */
......
......@@ -100,7 +100,7 @@ private:
std::vector<uchar> x1,y1,x2,y2;
};
class TrackerProxy : public TrackerTLD::Private{
class TrackerProxy{
public:
virtual bool init( const Mat& image, const Rect2d& boundingBox)=0;
virtual bool update(const Mat& image, Rect2d& boundingBox)=0;
......
......@@ -112,6 +112,8 @@ Ptr<Tracker> Tracker::create( const String& trackerType )
{
BOILERPLATE_CODE("MIL",TrackerMIL);
BOILERPLATE_CODE("BOOSTING",TrackerBoosting);
BOILERPLATE_CODE("MEDIANFLOW",TrackerMedianFlow);
BOILERPLATE_CODE("TLD",TrackerTLD);
return Ptr<Tracker>();
}
......
......@@ -74,9 +74,9 @@ namespace cv
* bring "out" all the parameters to TrackerMedianFlow::Param
*/
class MedianFlowCore{
class TrackerMedianFlowImpl : public TrackerMedianFlow{
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);
private:
Rect2d vote(const std::vector<Point2f>& oldPoints,const std::vector<Point2f>& newPoints,const Rect2d& oldRect,Point2f& mD);
......@@ -99,14 +99,12 @@ class MedianFlowCore{
class TrackerMedianFlowModel : public TrackerModel{
public:
TrackerMedianFlowModel(TrackerMedianFlow::Params params):medianFlow(params){}
MedianFlowCore* getMedianFlowCore(){return &medianFlow;}
TrackerMedianFlowModel(TrackerMedianFlow::Params /*params*/){}
Rect2d getBoundingBox(){return boundingBox_;}
void setBoudingBox(Rect2d boundingBox){boundingBox_=boundingBox;}
Mat getImage(){return image_;}
void setImage(const Mat& image){image.copyTo(image_);}
protected:
MedianFlowCore medianFlow;
Rect2d boundingBox_;
Mat image_;
void modelEstimationImpl( const std::vector<Mat>& /*responses*/ ){}
......@@ -128,38 +126,32 @@ void TrackerMedianFlow::Params::write( cv::FileStorage& fs ) const{
fs << "pointsInGrid" << pointsInGrid;
}
TrackerMedianFlow::~TrackerMedianFlow()
{
}
void TrackerMedianFlow::read( const cv::FileNode& fn )
void TrackerMedianFlowImpl::read( const cv::FileNode& fn )
{
params.read( fn );
}
void TrackerMedianFlow::write( cv::FileStorage& fs ) const
void TrackerMedianFlowImpl::write( cv::FileStorage& fs ) const
{
params.write( fs );
}
TrackerMedianFlow::TrackerMedianFlow( const TrackerMedianFlow::Params &parameters) :
params( parameters ){
isInit = false;
Ptr<TrackerMedianFlow> TrackerMedianFlow::createTracker(const TrackerMedianFlow::Params &parameters){
return Ptr<TrackerMedianFlowImpl>(new TrackerMedianFlowImpl(parameters));
}
bool TrackerMedianFlow::initImpl( const Mat& image, const Rect2d& boundingBox ){
bool TrackerMedianFlowImpl::initImpl( const Mat& image, const Rect2d& boundingBox ){
model=Ptr<TrackerMedianFlowModel>(new TrackerMedianFlowModel(params));
((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->setImage(image);
((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->setBoudingBox(boundingBox);
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();
Rect2d oldBox=((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->getBoundingBox();
if(!(((TrackerMedianFlowModel*)static_cast<TrackerModel*>(model))->getMedianFlowCore())->
medianFlowImpl(oldImage,image,oldBox)){
if(!medianFlowImpl(oldImage,image,oldBox)){
return false;
}
boundingBox=oldBox;
......@@ -168,7 +160,7 @@ bool TrackerMedianFlow::updateImpl( const Mat& image, Rect2d& boundingBox ){
return true;
}
std::string MedianFlowCore::type2str(int type) {
std::string TrackerMedianFlowImpl::type2str(int type) {
std::string r;
uchar depth = type & CV_MAT_DEPTH_MASK;
......@@ -190,7 +182,7 @@ std::string MedianFlowCore::type2str(int type) {
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;
Mat oldImage_gray,newImage_gray;
......@@ -251,7 +243,7 @@ bool MedianFlowCore::medianFlowImpl(Mat oldImage,Mat newImage,Rect2d& oldBox){
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
Rect2d newRect;
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
}
template<typename T>
T MedianFlowCore::getMedian(std::vector<T>& values,int size){
T TrackerMedianFlowImpl::getMedian(std::vector<T>& values,int size){
if(size==-1){
size=(int)values.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;
if(size==-1){
size=(int)data.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]));
}
}
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;
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){
if(status.size()==0){
......@@ -364,7 +356,7 @@ void MedianFlowCore::check_FB(const Mat& oldImage,const Mat& newImage,
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){
std::vector<float> NCC(oldPoints.size(),0.0);
......
......@@ -87,6 +87,7 @@ using namespace tld;
namespace cv
{
class TLDDetector;
class MyMouseCallbackDEBUG{
public:
......@@ -127,7 +128,6 @@ public:
protected:
friend class MyMouseCallbackDEBUG;
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);
bool ensembleClassifier(const uchar* data,int rowstep){return ensembleClassifierNum(data,rowstep)>0.5;}
double ensembleClassifierNum(const uchar* data,int rowstep);
......@@ -209,6 +209,25 @@ class TrackerTLDModel : public TrackerModel{
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(){
}
......@@ -218,11 +237,15 @@ void TrackerTLD::Params::read( const cv::FileNode& /*fn*/ ){
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 ){
isInit = false;
privateInfo.push_back(Ptr<TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params> >(
new TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params>()));
tracker=Ptr<TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params> >(
new TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params>());
}
TrackerTLD::~TrackerTLD(){
......@@ -240,9 +263,9 @@ void TrackerTLD::write( cv::FileStorage& fs ) const
bool TrackerTLD::initImpl(const Mat& image, const Rect2d& boundingBox ){
Mat image_gray;
((TrackerProxy*)static_cast<Private*>(privateInfo[0]))->init(image,boundingBox);
tracker->init(image,boundingBox);
cvtColor( image, image_gray, COLOR_BGR2GRAY );
Data* data=new Data(boundingBox);
data=new Data(boundingBox);
double scale=data->getScale();
Rect2d myBoundingBox=boundingBox;
if(scale>1.0){
......@@ -255,13 +278,10 @@ bool TrackerTLD::initImpl(const Mat& image, const Rect2d& boundingBox ){
myBoundingBox.height*=scale;
}
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->failedLastTime=false;
privateInfo.push_back(Ptr<TLDDetector>(detector));
privateInfo.push_back(Ptr<Data>(data));
#if !1
dprintf(("here I am\n"));
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