mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-19 11:14:32 +08:00
Tracking-Learning-Detection and MedianFlow
This contribution includes the following logical components into tracking module: .) Change Rect to Rect2d into headers for Tracker's methods; This contribution includes the following logical components into tracking module: .) Change Rect to Rect2d into headers for Tracker's methods; .) MedianFlow tracker; .) extensible benchmark to compare trackers interactively and assess them quantitatively; .) TLD tracker (work-in-progress); Work was funded by Google Summer of Code 2014 initiative. Mentors: Gary Bradski and Vadim Pisarevsky.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <opencv2/tracking.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
@@ -15,21 +16,20 @@ static bool startSelection = false;
|
||||
static const char* keys =
|
||||
{ "{@tracker_algorithm | | Tracker algorithm }"
|
||||
"{@video_name | | video name }"
|
||||
"{@start_frame |1| Start frame }"
|
||||
"{@start_frame |0| Start frame }"
|
||||
"{@bounding_frame |0,0,0,0| Initial bounding frame}"};
|
||||
|
||||
static void help()
|
||||
{
|
||||
cout << "\nThis example shows the functionality of \"Long-term optical tracking API\""
|
||||
"-- pause video [p] and draw a bounding box around the target to start the tracker\n"
|
||||
"Example of <video_name> is in opencv_extra/testdata/cv/tracking/\n"
|
||||
"Call:\n"
|
||||
"./tracker <tracker_algorithm> <video_name> <start_frame> [<bounding_frame>]\n"
|
||||
<< endl;
|
||||
|
||||
cout << "\n\nHot keys: \n"
|
||||
"\tq - quit the program\n"
|
||||
"\tp - pause video\n";
|
||||
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* )
|
||||
@@ -58,7 +58,7 @@ static void onMouse( int event, int x, int y, int, void* )
|
||||
//draw the bounding box
|
||||
Mat currentFrame;
|
||||
image.copyTo( currentFrame );
|
||||
rectangle( currentFrame, Point( (int)boundingBox.x, (int)boundingBox.y ), Point( x, y ), Scalar( 255, 0, 0 ), 2, 1 );
|
||||
rectangle( currentFrame, Point( boundingBox.x, boundingBox.y ), Point( x, y ), Scalar( 255, 0, 0 ), 2, 1 );
|
||||
imshow( "Tracking API", currentFrame );
|
||||
}
|
||||
break;
|
||||
@@ -66,8 +66,22 @@ static void onMouse( int event, int x, int y, int, void* )
|
||||
}
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
static void help()
|
||||
{
|
||||
cout << "\nThis example shows the functionality of \"Long-term optical tracking API\""
|
||||
"-- pause video [p] and draw a bounding box around the target to start the tracker\n"
|
||||
"Example of <video_name> is in opencv_extra/testdata/cv/tracking/\n"
|
||||
"Call:\n"
|
||||
"./tracker <tracker_algorithm> <video_name> <start_frame> [<bounding_frame>]\n"
|
||||
<< endl;
|
||||
|
||||
cout << "\n\nHot keys: \n"
|
||||
"\tq - quit the program\n"
|
||||
"\tp - pause video\n";
|
||||
listTrackers();
|
||||
}
|
||||
|
||||
int main( int argc, char** argv ){
|
||||
CommandLineParser parser( argc, argv, keys );
|
||||
|
||||
String tracker_algorithm = parser.get<String>( 0 );
|
||||
@@ -81,24 +95,19 @@ int main( int argc, char** argv )
|
||||
}
|
||||
|
||||
int coords[4]={0,0,0,0};
|
||||
bool initFrameWasGivenInCommandLine=false;
|
||||
|
||||
do
|
||||
{
|
||||
bool initBoxWasGivenInCommandLine=false;
|
||||
do{
|
||||
String initBoundingBox=parser.get<String>(3);
|
||||
for(size_t pos=0,ctr=0;ctr<4;ctr++)
|
||||
{
|
||||
size_t npos=initBoundingBox.find_first_of(',',pos);
|
||||
if(npos==string::npos && ctr<3)
|
||||
{
|
||||
for(size_t npos=0,pos=0,ctr=0;ctr<4;ctr++){
|
||||
npos=initBoundingBox.find_first_of(',',pos);
|
||||
if(npos==string::npos && ctr<3){
|
||||
printf("bounding box should be given in format \"x1,y1,x2,y2\",where x's and y's are integer cordinates of opposed corners of bdd box\n");
|
||||
printf("got: %s\n",initBoundingBox.substr(pos,string::npos).c_str());
|
||||
printf("manual selection of bounding box will be employed\n");
|
||||
break;
|
||||
}
|
||||
int num=atoi(initBoundingBox.substr(pos,(ctr==3)?(string::npos):(npos-pos)).c_str());
|
||||
if(num<=0)
|
||||
{
|
||||
if(num<=0){
|
||||
printf("bounding box should be given in format \"x1,y1,x2,y2\",where x's and y's are integer cordinates of opposed corners of bdd box\n");
|
||||
printf("got: %s\n",initBoundingBox.substr(pos,npos-pos).c_str());
|
||||
printf("manual selection of bounding box will be employed\n");
|
||||
@@ -107,9 +116,10 @@ int main( int argc, char** argv )
|
||||
coords[ctr]=num;
|
||||
pos=npos+1;
|
||||
}
|
||||
if(coords[0]>0 && coords[1]>0 && coords[2]>0 && coords[3]>0)
|
||||
initFrameWasGivenInCommandLine=true;
|
||||
} while((void)0, 0);
|
||||
if(coords[0]>0 && coords[1]>0 && coords[2]>0 && coords[3]>0){
|
||||
initBoxWasGivenInCommandLine=true;
|
||||
}
|
||||
}while(0);
|
||||
|
||||
//open the capture
|
||||
VideoCapture cap;
|
||||
@@ -141,7 +151,7 @@ int main( int argc, char** argv )
|
||||
//get the first frame
|
||||
cap >> frame;
|
||||
frame.copyTo( image );
|
||||
if(initFrameWasGivenInCommandLine){
|
||||
if(initBoxWasGivenInCommandLine){
|
||||
selectObject=true;
|
||||
paused=false;
|
||||
boundingBox.x = coords[0];
|
||||
@@ -160,15 +170,14 @@ int main( int argc, char** argv )
|
||||
{
|
||||
if( !paused )
|
||||
{
|
||||
cap >> frame;
|
||||
|
||||
if( frame.empty() )
|
||||
{
|
||||
break;
|
||||
if(initialized){
|
||||
cap >> frame;
|
||||
if(frame.empty()){
|
||||
break;
|
||||
}
|
||||
frame.copyTo( image );
|
||||
}
|
||||
|
||||
frame.copyTo( image );
|
||||
|
||||
if( !initialized && selectObject )
|
||||
{
|
||||
//initializes the tracker
|
||||
|
Reference in New Issue
Block a user