Commit 8aa19882 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #67 from nailbiter/luca

Remove dependence on optim module
parents 12e1e11d 0cd798ed
set(the_description "Tracking API") set(the_description "Tracking API")
ocv_define_module(tracking opencv_imgproc opencv_optim opencv_video opencv_highgui) ocv_define_module(tracking opencv_imgproc opencv_core opencv_video opencv_highgui)
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
#include "feature.hpp" #include "feature.hpp"
#include "onlineMIL.hpp" #include "onlineMIL.hpp"
#include "onlineBoosting.hpp" #include "onlineBoosting.hpp"
#include "opencv2/optim.hpp"
#include <iostream> #include <iostream>
#define BOILERPLATE_CODE(name,classname) \ #define BOILERPLATE_CODE(name,classname) \
...@@ -804,7 +803,8 @@ class CV_EXPORTS_W TrackerSamplerCS : public TrackerSamplerAlgorithm ...@@ -804,7 +803,8 @@ class CV_EXPORTS_W TrackerSamplerCS : public TrackerSamplerAlgorithm
}; };
class CV_EXPORTS_W TrackerSamplerPF : public TrackerSamplerAlgorithm{ class CV_EXPORTS_W TrackerSamplerPF : public TrackerSamplerAlgorithm
{
public: public:
struct CV_EXPORTS Params struct CV_EXPORTS Params
{ {
...@@ -819,8 +819,8 @@ protected: ...@@ -819,8 +819,8 @@ protected:
bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample ); bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample );
private: private:
Params params; Params params;
Ptr<optim::Solver> _solver; Ptr<MinProblemSolver> _solver;
Ptr<optim::Solver::Function> _function; Ptr<MinProblemSolver::Function> _function;
}; };
/************************************ Specific TrackerFeature Classes ************************************/ /************************************ Specific TrackerFeature Classes ************************************/
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <climits> #include <climits>
const int CMDLINEMAX = 30; const int CMDLINEMAX = 30;
const int ASSESS_TILL = 100; int ASSESS_TILL = INT_MAX;
const int LINEMAX = 40; const int LINEMAX = 40;
using namespace std; using namespace std;
...@@ -62,6 +62,10 @@ static void help(){ ...@@ -62,6 +62,10 @@ static void help(){
"./tracker [<keys and args>] <video_name> <ground_truth> <algorithm1> <init_box1> <algorithm2> <init_box2> ...\n" "./tracker [<keys and args>] <video_name> <ground_truth> <algorithm1> <init_box1> <algorithm2> <init_box2> ...\n"
<< endl; << endl;
cout << "\n\nConsole keys: \n"
"\t-s - save images\n"
"\t-l=100 - assess only, say, first 100 frames\n";
cout << "\n\nHot keys: \n" cout << "\n\nHot keys: \n"
"\tq - quit the program\n" "\tq - quit the program\n"
"\tp - pause video\n"; "\tp - pause video\n";
...@@ -74,8 +78,13 @@ static void parseCommandLineArgs(int argc, char** argv,char* videos[],char* gts[ ...@@ -74,8 +78,13 @@ static void parseCommandLineArgs(int argc, char** argv,char* videos[],char* gts[
for(int i=1;i<argc;i++){ for(int i=1;i<argc;i++){
if(argv[i][0]=='-'){ if(argv[i][0]=='-'){
for(int j=0;j<CMDLINEMAX;j++){ for(int j=0;j<CMDLINEMAX;j++){
if(!strcmp(argv[i],keys[j])){ char* ptr = strchr(argv[i], '=');
keys[j][0]='\0'; if( !strncmp(argv[i], keys[j], (ptr == NULL) ? strlen(argv[i]) : (ptr-argv[i]) ) )
{
if( ptr == NULL )
keys[j][0]='\0';
else
strcpy(keys[j], ptr+1);
} }
} }
continue; continue;
...@@ -293,6 +302,7 @@ static AssessmentRes assessment(char* video,char* gt_str, char* algorithms[],cha ...@@ -293,6 +302,7 @@ static AssessmentRes assessment(char* video,char* gt_str, char* algorithms[],cha
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
rectangle( image, boundingBox,palette[0], 2, 1 ); rectangle( image, boundingBox,palette[0], 2, 1 );
putText(image, "GROUND TRUTH", Point(1,16 + 0*14), FONT_HERSHEY_SIMPLEX, 0.5, palette[0],2);
frameCounter++; frameCounter++;
for(int i=0;i<(int)trackers.size();i++){ for(int i=0;i<(int)trackers.size();i++){
...@@ -301,10 +311,14 @@ static AssessmentRes assessment(char* video,char* gt_str, char* algorithms[],cha ...@@ -301,10 +311,14 @@ static AssessmentRes assessment(char* video,char* gt_str, char* algorithms[],cha
trackerRes=trackers[i]->update( frame, initBoxes[i] ); trackerRes=trackers[i]->update( frame, initBoxes[i] );
start=clock()-start; start=clock()-start;
averageMillisPerFrame[i]+=1000.0*start/CLOCKS_PER_SEC; averageMillisPerFrame[i]+=1000.0*start/CLOCKS_PER_SEC;
if(trackerRes==false){ if( trackerRes == false )
{
initBoxes[i].height=initBoxes[i].width=-1.0; initBoxes[i].height=initBoxes[i].width=-1.0;
}else{ }
else
{
rectangle( image, initBoxes[i], palette[i+1], 2, 1 ); rectangle( image, initBoxes[i], palette[i+1], 2, 1 );
putText(image, algorithms[i], Point(1,16 + (i+1)*14), FONT_HERSHEY_SIMPLEX, 0.5, palette[i+1],2);
} }
for(int j=0;j<(int)res.results[i].size();j++) for(int j=0;j<(int)res.results[i].size();j++)
res.results[i][j]->assess(boundingBox,initBoxes[i]); res.results[i][j]->assess(boundingBox,initBoxes[i]);
...@@ -340,15 +354,23 @@ static AssessmentRes assessment(char* video,char* gt_str, char* algorithms[],cha ...@@ -340,15 +354,23 @@ static AssessmentRes assessment(char* video,char* gt_str, char* algorithms[],cha
} }
int main( int argc, char** argv ){ int main( int argc, char** argv ){
palette.push_back(Scalar(255,0,0));//BGR palette.push_back(Scalar(255,0,0));//BGR, blue
palette.push_back(Scalar(0,0,255)); palette.push_back(Scalar(0,0,255));//red
palette.push_back(Scalar(0,255,255)); palette.push_back(Scalar(0,255,255));//yellow
palette.push_back(Scalar(255,255,0));//orange
int vcount=0,acount=0; int vcount=0,acount=0;
char* videos[CMDLINEMAX],*gts[CMDLINEMAX],*algorithms[CMDLINEMAX],*initBoxes[CMDLINEMAX][CMDLINEMAX]; char* videos[CMDLINEMAX],*gts[CMDLINEMAX],*algorithms[CMDLINEMAX],*initBoxes[CMDLINEMAX][CMDLINEMAX];
char keys[CMDLINEMAX][LINEMAX]; char keys[CMDLINEMAX][LINEMAX];
strcpy(keys[0],"-s"); strcpy(keys[0],"-s");
strcpy(keys[1],"-a");
parseCommandLineArgs(argc,argv,videos,gts,&vcount,algorithms,initBoxes,&acount,keys); parseCommandLineArgs(argc,argv,videos,gts,&vcount,algorithms,initBoxes,&acount,keys);
saveImageKey=(keys[0][0]=='\0'); saveImageKey=(keys[0][0]=='\0');
if( strcmp(keys[1],"-a") != 0 )
ASSESS_TILL = atoi(keys[1]);
else
ASSESS_TILL = INT_MAX;
CV_Assert(acount<CMDLINEMAX && vcount<CMDLINEMAX); CV_Assert(acount<CMDLINEMAX && vcount<CMDLINEMAX);
printf("videos and gts\n"); printf("videos and gts\n");
...@@ -365,9 +387,8 @@ int main( int argc, char** argv ){ ...@@ -365,9 +387,8 @@ int main( int argc, char** argv ){
} }
std::vector<AssessmentRes> results; std::vector<AssessmentRes> results;
for(int i=0;i<vcount;i++){ for(int i=0;i<vcount;i++)
results.push_back(assessment(videos[i],gts[i],algorithms,((char**)initBoxes)+i,acount)); results.push_back(assessment(videos[i],gts[i],algorithms,((char**)initBoxes)+i,acount));
}
CV_Assert( (int)results[0].results[0].size() < CMDLINEMAX ); CV_Assert( (int)results[0].results[0].size() < CMDLINEMAX );
printf("\n\n"); printf("\n\n");
...@@ -379,10 +400,10 @@ int main( int argc, char** argv ){ ...@@ -379,10 +400,10 @@ int main( int argc, char** argv ){
resultStrings[i].push_back(buf+i*CMDLINEMAX*LINEMAX + j*40); resultStrings[i].push_back(buf+i*CMDLINEMAX*LINEMAX + j*40);
} }
} }
for(int i=0;i<(int)results[0].results[0].size();i++){ for(int i=0;i<(int)results[0].results[0].size();i++)
nameStrings.push_back(buf2+LINEMAX*i); nameStrings.push_back(buf2+LINEMAX*i);
} for(int tableCount=0;tableCount<(int)results[0].results[0].size();tableCount++)
for(int tableCount=0;tableCount<(int)results[0].results[0].size();tableCount++){ {
CV_Assert(results[0].results[0][tableCount]->printName(nameStrings[tableCount])<LINEMAX); CV_Assert(results[0].results[0][tableCount]->printName(nameStrings[tableCount])<LINEMAX);
for(int videoCount=0;videoCount<(int)results.size();videoCount++) for(int videoCount=0;videoCount<(int)results.size();videoCount++)
for(int algoCount=0;algoCount<(int)results[0].results.size();algoCount++){ for(int algoCount=0;algoCount<(int)results[0].results.size();algoCount++){
......
#include "opencv2/optim.hpp" #include "opencv2/core.hpp"
#include "opencv2/core/core_c.h" #include "opencv2/core/core_c.h"
#include <algorithm> #include <algorithm>
#include <typeinfo> #include <typeinfo>
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
namespace cv{ namespace cv{
//!particle filtering class //!particle filtering class
class PFSolver : public optim::Solver{ class PFSolver : public MinProblemSolver{
public: public:
class Function : public optim::Solver::Function class Function : public MinProblemSolver::Function
{ {
public: public:
//!if parameters have no sense due to some reason (e.g. lie outside of function domain), this function "corrects" them, //!if parameters have no sense due to some reason (e.g. lie outside of function domain), this function "corrects" them,
...@@ -31,13 +31,13 @@ namespace cv{ ...@@ -31,13 +31,13 @@ namespace cv{
void getParamsSTD(OutputArray std)const; void getParamsSTD(OutputArray std)const;
void setParamsSTD(InputArray std); void setParamsSTD(InputArray std);
Ptr<optim::Solver::Function> getFunction() const; Ptr<MinProblemSolver::Function> getFunction() const;
void setFunction(const Ptr<Solver::Function>& f); void setFunction(const Ptr<MinProblemSolver::Function>& f);
TermCriteria getTermCriteria() const; TermCriteria getTermCriteria() const;
void setTermCriteria(const TermCriteria& termcrit); void setTermCriteria(const TermCriteria& termcrit);
private: private:
Mat_<double> _std,_particles,_logweight; Mat_<double> _std,_particles,_logweight;
Ptr<Solver::Function> _Function; Ptr<MinProblemSolver::Function> _Function;
PFSolver::Function* _real_function; PFSolver::Function* _real_function;
TermCriteria _termcrit; TermCriteria _termcrit;
int _maxItNum,_iter,_particlesNum; int _maxItNum,_iter,_particlesNum;
...@@ -46,11 +46,11 @@ namespace cv{ ...@@ -46,11 +46,11 @@ namespace cv{
RNG rng; RNG rng;
}; };
CV_EXPORTS_W Ptr<PFSolver> createPFSolver(const Ptr<optim::Solver::Function>& f=Ptr<optim::Solver::Function>(),InputArray std=Mat(), CV_EXPORTS_W Ptr<PFSolver> createPFSolver(const Ptr<MinProblemSolver::Function>& f=Ptr<MinProblemSolver::Function>(),InputArray std=Mat(),
TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER,5,0.0),int particlesNum=100,double alpha=0.6); TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER,5,0.0),int particlesNum=100,double alpha=0.6);
PFSolver::PFSolver(){ PFSolver::PFSolver(){
_Function=Ptr<Solver::Function>(); _Function=Ptr<MinProblemSolver::Function>();
_real_function=NULL; _real_function=NULL;
_std=Mat_<double>(); _std=Mat_<double>();
rng=RNG(getTickCount()); rng=RNG(getTickCount());
...@@ -154,14 +154,14 @@ namespace cv{ ...@@ -154,14 +154,14 @@ namespace cv{
double PFSolver::getAlpha(){ double PFSolver::getAlpha(){
return _alpha; return _alpha;
} }
Ptr<optim::Solver::Function> PFSolver::getFunction() const{ Ptr<MinProblemSolver::Function> PFSolver::getFunction() const{
return _Function; return _Function;
} }
void PFSolver::setFunction(const Ptr<optim::Solver::Function>& f){ void PFSolver::setFunction(const Ptr<MinProblemSolver::Function>& f){
CV_Assert(f.empty()==false); CV_Assert(f.empty()==false);
Ptr<Solver::Function> non_const_f(f); Ptr<MinProblemSolver::Function> non_const_f(f);
Solver::Function* f_ptr=static_cast<Solver::Function*>(non_const_f); MinProblemSolver::Function* f_ptr=static_cast<MinProblemSolver::Function*>(non_const_f);
PFSolver::Function *pff=dynamic_cast<PFSolver::Function*>(f_ptr); PFSolver::Function *pff=dynamic_cast<PFSolver::Function*>(f_ptr);
CV_Assert(pff!=NULL); CV_Assert(pff!=NULL);
...@@ -194,7 +194,7 @@ namespace cv{ ...@@ -194,7 +194,7 @@ namespace cv{
} }
} }
Ptr<PFSolver> createPFSolver(const Ptr<optim::Solver::Function>& f,InputArray std,TermCriteria termcrit,int particlesNum,double alpha){ Ptr<PFSolver> createPFSolver(const Ptr<MinProblemSolver::Function>& f,InputArray std,TermCriteria termcrit,int particlesNum,double alpha){
Ptr<PFSolver> ptr(new PFSolver()); Ptr<PFSolver> ptr(new PFSolver());
if(f.empty()==false){ if(f.empty()==false){
......
...@@ -608,7 +608,7 @@ bool TLDDetector::detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std ...@@ -608,7 +608,7 @@ bool TLDDetector::detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std
END_TICK("detector"); END_TICK("detector");
dfprintf((stdout, "after NCC: nneg = %d npos = %d\n", nneg, npos)); dfprintf((stdout, "after NCC: nneg = %d npos = %d\n", nneg, npos));
#if !0 #if !1
std::vector<Rect2d> poss, negs; std::vector<Rect2d> poss, negs;
for( int i = 0; i < (int)patches.size(); i++ ) for( int i = 0; i < (int)patches.size(); i++ )
......
...@@ -397,11 +397,11 @@ bool TrackerSamplerPF::samplingImpl( const Mat& image, Rect boundingBox, std::ve ...@@ -397,11 +397,11 @@ bool TrackerSamplerPF::samplingImpl( const Mat& image, Rect boundingBox, std::ve
Ptr<TrackerTargetState> ptr; Ptr<TrackerTargetState> ptr;
Mat_<double> _last_guess=(Mat_<double>(1,4)<<(double)boundingBox.x,(double)boundingBox.y, Mat_<double> _last_guess=(Mat_<double>(1,4)<<(double)boundingBox.x,(double)boundingBox.y,
(double)boundingBox.x+boundingBox.width,(double)boundingBox.y+boundingBox.height); (double)boundingBox.x+boundingBox.width,(double)boundingBox.y+boundingBox.height);
PFSolver* promoted_solver=dynamic_cast<PFSolver*>(static_cast<optim::Solver*>(_solver)); PFSolver* promoted_solver=dynamic_cast<PFSolver*>(static_cast<MinProblemSolver*>(_solver));
promoted_solver->setParamsSTD(params.std); promoted_solver->setParamsSTD(params.std);
promoted_solver->minimize(_last_guess); promoted_solver->minimize(_last_guess);
dynamic_cast<TrackingFunctionPF*>(static_cast<optim::Solver::Function*>(promoted_solver->getFunction()))->update(image); dynamic_cast<TrackingFunctionPF*>(static_cast<MinProblemSolver::Function*>(promoted_solver->getFunction()))->update(image);
while(promoted_solver->iteration() <= promoted_solver->getTermCriteria().maxCount); while(promoted_solver->iteration() <= promoted_solver->getTermCriteria().maxCount);
promoted_solver->getOptParam(_last_guess); promoted_solver->getOptParam(_last_guess);
......
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