mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-19 02:16:34 +08:00
Vadim
This commit is contained in:
@@ -23,18 +23,6 @@ vector<Scalar> palette;
|
|||||||
|
|
||||||
void print_table(char* videos[],int videoNum,char* algorithms[],int algNum,const vector<vector<char*> >& results,char* tableName);
|
void print_table(char* videos[],int videoNum,char* algorithms[],int algNum,const vector<vector<char*> >& results,char* tableName);
|
||||||
|
|
||||||
static void listTrackers(){
|
|
||||||
vector<String> algorithms;
|
|
||||||
Algorithm::getList(algorithms);
|
|
||||||
cout << "\nAvailable tracker algorithms:\n";
|
|
||||||
for (size_t i=0; i < algorithms.size(); i++){
|
|
||||||
const char* algoname=algorithms[i].c_str();
|
|
||||||
char *pos=NULL;
|
|
||||||
if((pos=strstr((char*)algoname,"TRACKER."))!=NULL){
|
|
||||||
printf("%s\n",pos+8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static int lineToRect(char* line,Rect2d& res){
|
static int lineToRect(char* line,Rect2d& res){
|
||||||
char * ptr=line,*pos=ptr;
|
char * ptr=line,*pos=ptr;
|
||||||
if(line==NULL || line[0]=='\0'){
|
if(line==NULL || line[0]=='\0'){
|
||||||
@@ -75,21 +63,11 @@ static void help(){
|
|||||||
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";
|
||||||
listTrackers();
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
static void parseCommandLineArgs(int argc, char** argv,char* videos[],char* gts[],
|
static void parseCommandLineArgs(int argc, char** argv,char* videos[],char* gts[],
|
||||||
int* vc,char* algorithms[],char* initBoxes[][CMDLINEMAX],int* ac){
|
int* vc,char* algorithms[],char* initBoxes[][CMDLINEMAX],int* ac){
|
||||||
|
|
||||||
vector<String> trackers;
|
|
||||||
Algorithm::getList(trackers);
|
|
||||||
for(int i=0;i<(int)trackers.size();i++){
|
|
||||||
if(strstr(trackers[i].c_str(),"TRACKER.")!=trackers[i].c_str()){
|
|
||||||
trackers.erase(trackers.begin()+i);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*ac=*vc=0;
|
*ac=*vc=0;
|
||||||
for(int i=1;i<argc;i++){
|
for(int i=1;i<argc;i++){
|
||||||
if(argv[i][0]=='-'){
|
if(argv[i][0]=='-'){
|
||||||
@@ -105,13 +83,14 @@ static void parseCommandLineArgs(int argc, char** argv,char* videos[],char* gts[
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
bool isVideo=true;
|
bool isVideo=false;
|
||||||
for(int j=0;j<(int)trackers.size();j++){
|
for(int j=0,len=strlen(argv[i]);j<len;j++){
|
||||||
if(strcmp(argv[i],trackers[j].c_str()+8)==0){
|
if(!('A'<=argv[i][j] && argv[i][j]<='Z') && argv[i][j]!='.'){
|
||||||
isVideo=false;
|
isVideo=true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isVideo){
|
if(isVideo){
|
||||||
videos[*vc]=argv[i];
|
videos[*vc]=argv[i];
|
||||||
i++;
|
i++;
|
||||||
|
@@ -19,19 +19,6 @@ static const char* keys =
|
|||||||
"{@start_frame |0| Start frame }"
|
"{@start_frame |0| Start frame }"
|
||||||
"{@bounding_frame |0,0,0,0| Initial bounding frame}"};
|
"{@bounding_frame |0,0,0,0| Initial bounding frame}"};
|
||||||
|
|
||||||
static void listTrackers(){
|
|
||||||
vector<String> algorithms;
|
|
||||||
Algorithm::getList(algorithms);
|
|
||||||
cout << "\nAvailable tracker algorithms:\n";
|
|
||||||
for (size_t i=0; i < algorithms.size(); i++){
|
|
||||||
const char* algoname=algorithms[i].c_str();
|
|
||||||
char *pos=NULL;
|
|
||||||
if((pos=strstr((char*)algoname,"TRACKER."))!=NULL){
|
|
||||||
printf("%s\n",pos+8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void onMouse( int event, int x, int y, int, void* )
|
static void onMouse( int event, int x, int y, int, void* )
|
||||||
{
|
{
|
||||||
if( !selectObject )
|
if( !selectObject )
|
||||||
@@ -78,7 +65,6 @@ static void help()
|
|||||||
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";
|
||||||
listTrackers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char** argv ){
|
int main( int argc, char** argv ){
|
||||||
|
@@ -77,8 +77,12 @@ namespace cv
|
|||||||
class TrackerMedianFlowImpl : public TrackerMedianFlow{
|
class TrackerMedianFlowImpl : public TrackerMedianFlow{
|
||||||
public:
|
public:
|
||||||
TrackerMedianFlowImpl(TrackerMedianFlow::Params paramsIn):termcrit(TermCriteria::COUNT|TermCriteria::EPS,20,0.3){params=paramsIn;isInit=false;}
|
TrackerMedianFlowImpl(TrackerMedianFlow::Params paramsIn):termcrit(TermCriteria::COUNT|TermCriteria::EPS,20,0.3){params=paramsIn;isInit=false;}
|
||||||
bool medianFlowImpl(Mat oldImage,Mat newImage,Rect2d& oldBox);
|
void read( const FileNode& fn );
|
||||||
|
void write( FileStorage& fs ) const;
|
||||||
private:
|
private:
|
||||||
|
bool initImpl( const Mat& image, const Rect2d& boundingBox );
|
||||||
|
bool updateImpl( const Mat& image, Rect2d& boundingBox );
|
||||||
|
bool medianFlowImpl(Mat oldImage,Mat newImage,Rect2d& oldBox);
|
||||||
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);
|
||||||
//FIXME: this can be optimized: current method uses sort->select approach, there are O(n) selection algo for median; besides
|
//FIXME: this can be optimized: current method uses sort->select approach, there are O(n) selection algo for median; besides
|
||||||
//it makes copy all the time
|
//it makes copy all the time
|
||||||
|
@@ -102,7 +102,7 @@ private:
|
|||||||
TLDDetector* detector_;
|
TLDDetector* detector_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Data : public TrackerTLD::Private{
|
class Data {
|
||||||
public:
|
public:
|
||||||
Data(Rect2d initBox);
|
Data(Rect2d initBox);
|
||||||
Size getMinSize(){return minSize;}
|
Size getMinSize(){return minSize;}
|
||||||
@@ -118,7 +118,7 @@ private:
|
|||||||
|
|
||||||
class TrackerTLDModel;
|
class TrackerTLDModel;
|
||||||
|
|
||||||
class TLDDetector : public TrackerTLD::Private{
|
class TLDDetector {
|
||||||
public:
|
public:
|
||||||
TLDDetector(const TrackerTLD::Params& params,Ptr<TrackerModel>model_in):model(model_in),params_(params){}
|
TLDDetector(const TrackerTLD::Params& params,Ptr<TrackerModel>model_in):model(model_in),params_(params){}
|
||||||
~TLDDetector(){}
|
~TLDDetector(){}
|
||||||
@@ -128,6 +128,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
friend class MyMouseCallbackDEBUG;
|
friend class MyMouseCallbackDEBUG;
|
||||||
Ptr<TrackerModel> model;
|
Ptr<TrackerModel> model;
|
||||||
|
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);
|
||||||
@@ -168,7 +169,7 @@ class TrackerProxyImpl : public TrackerProxy{
|
|||||||
public:
|
public:
|
||||||
TrackerProxyImpl(Tparams params=Tparams()):params_(params){}
|
TrackerProxyImpl(Tparams params=Tparams()):params_(params){}
|
||||||
bool init( const Mat& image, const Rect2d& boundingBox ){
|
bool init( const Mat& image, const Rect2d& boundingBox ){
|
||||||
trackerPtr=Ptr<T>(new T(params_));
|
trackerPtr=T::createTracker();
|
||||||
return trackerPtr->init(image,boundingBox);
|
return trackerPtr->init(image,boundingBox);
|
||||||
}
|
}
|
||||||
bool update( const Mat& image,Rect2d& boundingBox){
|
bool update( const Mat& image,Rect2d& boundingBox){
|
||||||
@@ -223,7 +224,7 @@ class TrackerTLDImpl : public TrackerTLD
|
|||||||
|
|
||||||
TrackerTLD::Params params;
|
TrackerTLD::Params params;
|
||||||
Ptr<Data> data;
|
Ptr<Data> data;
|
||||||
Ptr<TrackerProxy> tracker;
|
Ptr<TrackerProxy> trackerProxy;
|
||||||
Ptr<TLDDetector> detector;
|
Ptr<TLDDetector> detector;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -244,28 +245,25 @@ Ptr<TrackerTLD> TrackerTLD::createTracker(const TrackerTLD::Params ¶meters){
|
|||||||
TrackerTLDImpl::TrackerTLDImpl( const TrackerTLD::Params ¶meters) :
|
TrackerTLDImpl::TrackerTLDImpl( const TrackerTLD::Params ¶meters) :
|
||||||
params( parameters ){
|
params( parameters ){
|
||||||
isInit = false;
|
isInit = false;
|
||||||
tracker=Ptr<TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params> >(
|
trackerProxy=Ptr<TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params> >(
|
||||||
new TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params>());
|
new TrackerProxyImpl<TrackerMedianFlow,TrackerMedianFlow::Params>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackerTLD::~TrackerTLD(){
|
void TrackerTLDImpl::read( const cv::FileNode& fn )
|
||||||
}
|
|
||||||
|
|
||||||
void TrackerTLD::read( const cv::FileNode& fn )
|
|
||||||
{
|
{
|
||||||
params.read( fn );
|
params.read( fn );
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackerTLD::write( cv::FileStorage& fs ) const
|
void TrackerTLDImpl::write( cv::FileStorage& fs ) const
|
||||||
{
|
{
|
||||||
params.write( fs );
|
params.write( fs );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TrackerTLD::initImpl(const Mat& image, const Rect2d& boundingBox ){
|
bool TrackerTLDImpl::initImpl(const Mat& image, const Rect2d& boundingBox ){
|
||||||
Mat image_gray;
|
Mat image_gray;
|
||||||
tracker->init(image,boundingBox);
|
trackerProxy->init(image,boundingBox);
|
||||||
cvtColor( image, image_gray, COLOR_BGR2GRAY );
|
cvtColor( image, image_gray, COLOR_BGR2GRAY );
|
||||||
data=new Data(boundingBox);
|
data=Ptr<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){
|
||||||
@@ -278,7 +276,7 @@ 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()));
|
||||||
detector=new TLDDetector(params,model);
|
detector=Ptr<TLDDetector>(new TLDDetector(params,model));
|
||||||
data->confident=false;
|
data->confident=false;
|
||||||
data->failedLastTime=false;
|
data->failedLastTime=false;
|
||||||
|
|
||||||
@@ -294,10 +292,9 @@ bool TrackerTLD::initImpl(const Mat& image, const Rect2d& boundingBox ){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TrackerTLD::updateImpl(const Mat& image, Rect2d& boundingBox){
|
bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox){
|
||||||
Mat image_gray,image_blurred,imageForDetector;
|
Mat image_gray,image_blurred,imageForDetector;
|
||||||
cvtColor( image, image_gray, COLOR_BGR2GRAY );
|
cvtColor( image, image_gray, COLOR_BGR2GRAY );
|
||||||
Data* data=((Data*)static_cast<TrackerTLD::Private*>(privateInfo[2]));
|
|
||||||
double scale=data->getScale();
|
double scale=data->getScale();
|
||||||
if(scale>1.0){
|
if(scale>1.0){
|
||||||
resize(image_gray,imageForDetector,Size(cvRound(image.cols*scale),cvRound(image.rows*scale)));
|
resize(image_gray,imageForDetector,Size(cvRound(image.cols*scale),cvRound(image.rows*scale)));
|
||||||
@@ -306,8 +303,6 @@ bool TrackerTLD::updateImpl(const Mat& image, Rect2d& boundingBox){
|
|||||||
}
|
}
|
||||||
GaussianBlur(imageForDetector,image_blurred,GaussBlurKernelSize,0.0);
|
GaussianBlur(imageForDetector,image_blurred,GaussBlurKernelSize,0.0);
|
||||||
TrackerTLDModel* tldModel=((TrackerTLDModel*)static_cast<TrackerModel*>(model));
|
TrackerTLDModel* tldModel=((TrackerTLDModel*)static_cast<TrackerModel*>(model));
|
||||||
TrackerProxy* trackerProxy=(TrackerProxy*)static_cast<Private*>(privateInfo[0]);
|
|
||||||
TLDDetector* detector=((TLDDetector*)static_cast<TrackerTLD::Private*>(privateInfo[1]));
|
|
||||||
data->frameNum++;
|
data->frameNum++;
|
||||||
Mat_<uchar> standardPatch(15,15);
|
Mat_<uchar> standardPatch(15,15);
|
||||||
std::vector<Rect2d> detectorResults;
|
std::vector<Rect2d> detectorResults;
|
||||||
|
Reference in New Issue
Block a user