Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

/How to speed up TLD tracker in opencv 3 with contrib modules ?

i have tried running TLD which is builtin in opencv 3 + contrib module , but this code seems to work really slow for TLD

include <opencv2 core="" utility.hpp="">

include <opencv2 tracking.hpp="">

include <opencv2 videoio.hpp="">

include <opencv2 highgui.hpp="">

include <iostream>

include <cstring>

using namespace std; using namespace cv;

static Mat image; static Rect2d boundingBox; static bool paused; static bool selectObject = false; static bool startSelection = false;

static const char* keys = { "{@tracker_algorithm | | Tracker algorithm }" "{@video_name | | video name }" "{@start_frame |0| Start frame }" "{@bounding_frame |0,0,0,0| Initial bounding frame}"};

static void onMouse( int event, int x, int y, int, void* ) { if( !selectObject ) { switch ( event ) { case EVENT_LBUTTONDOWN: //set origin of the bounding box startSelection = true; boundingBox.x = x; boundingBox.y = y; boundingBox.width = boundingBox.height = 0; break; case EVENT_LBUTTONUP: //sei with and height of the bounding box boundingBox.width = std::abs( x - boundingBox.x ); boundingBox.height = std::abs( y - boundingBox.y ); paused = false; selectObject = true; break; case EVENT_MOUSEMOVE:

    if( startSelection && !selectObject )
    {
      //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 );
      imshow( "Tracking API", currentFrame );
    }
    break;
}

} }

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"; }

int main( int argc, char** argv ) { //open the capture VideoCapture cap(0); if( !cap.isOpened() ) { return -1; }

//
//  "MIL", "BOOSTING", "MEDIANFLOW", "TLD"
//
string tracker_algorithm = "MIL";
if ( argc>1 ) tracker_algorithm = argv[1];

Mat frame;
paused = false;
namedWindow( "Tracking API", 0 );
setMouseCallback( "Tracking API", onMouse, 0 );

Ptr<Tracker> tracker = Tracker::create( tracker_algorithm );
if( tracker == NULL )
{
    cout << "***Error in the instantiation of the tracker...***\n";
    return -1;
}

//get the first frame
cap >> frame;
frame.copyTo( image );
imshow( "Tracking API", image );

bool initialized = false;
int frameCounter = 0;

for ( ;; )
{
    char c = (char) waitKey( 2 );
    if( c == 'q' || c == 27 )
        break;
    if( c == 'p' )
        paused = !paused;

    if ( !paused )
    {
        cap >> frame;
        if(frame.empty())
        {
            break;
        }
        frame.copyTo( image );

        if( selectObject )
        {
            if( !initialized )
            {
                //initializes the tracker
                if( !tracker->init( frame, boundingBox ) )
                {
                cout << "***Could not initialize tracker...***\n";
                return -1;
                }
                initialized = true;
            }
            else
            {
                //updates the tracker
                if( tracker->update( frame, boundingBox ) )
                {
                    rectangle( image, boundingBox, Scalar( 255, 0, 0 ), 2, 1 );
                }
            }
        }
        imshow( "Tracking API", image );
        frameCounter++;
    }
}

return 0;

} Is there any way to speed it up , by changing its parameters or anything else. Help neeeded . THNX in advance

click to hide/show revision 2
No.2 Revision

updated 2015-01-27 08:20:48 -0600

berak gravatar image

/How to speed up TLD tracker in opencv 3 with contrib modules ?

i have tried running TLD which is builtin in opencv 3 + contrib module , but this code seems to work really slow for TLD

include <opencv2 core="" utility.hpp="">

include <opencv2 tracking.hpp="">

include <opencv2 videoio.hpp="">

include <opencv2 highgui.hpp="">

include <iostream>

include <cstring>

#include <opencv2/core/utility.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstring>

using namespace std;
using namespace cv;

cv; static Mat image; static Rect2d boundingBox; static bool paused; static bool selectObject = false; static bool startSelection = false;

false; static const char* keys = { "{@tracker_algorithm | | Tracker algorithm }" "{@video_name | | video name }" "{@start_frame |0| Start frame }" "{@bounding_frame |0,0,0,0| Initial bounding frame}"};

frame}"}; static void onMouse( int event, int x, int y, int, void* ) { if( !selectObject ) { switch ( event ) { case EVENT_LBUTTONDOWN: //set origin of the bounding box startSelection = true; boundingBox.x = x; boundingBox.y = y; boundingBox.width = boundingBox.height = 0; break; case EVENT_LBUTTONUP: //sei with and height of the bounding box boundingBox.width = std::abs( x - boundingBox.x ); boundingBox.height = std::abs( y - boundingBox.y ); paused = false; selectObject = true; break; case EVENT_MOUSEMOVE:

EVENT_MOUSEMOVE:
 if( startSelection && !selectObject )
 {
  //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 );
 imshow( "Tracking API", currentFrame );
 }
 break;
 }

} }

} 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;

endl; cout << "\n\nHot keys: \n" "\tq - quit the program\n" "\tp - pause video\n"; }

} int main( int argc, char** argv ) { //open the capture VideoCapture cap(0); if( !cap.isOpened() ) { return -1; }

}
//
 // "MIL", "BOOSTING", "MEDIANFLOW", "TLD"
 //
 string tracker_algorithm = "MIL";
 if ( argc>1 ) tracker_algorithm = argv[1];
 Mat frame;
 paused = false;
 namedWindow( "Tracking API", 0 );
 setMouseCallback( "Tracking API", onMouse, 0 );
 Ptr<Tracker> tracker = Tracker::create( tracker_algorithm );
 if( tracker == NULL )
 {
  cout << "***Error in the instantiation of the tracker...***\n";
 return -1;
 }
 //get the first frame
 cap >> frame;
 frame.copyTo( image );
 imshow( "Tracking API", image );
 bool initialized = false;
 int frameCounter = 0;
 for ( ;; )
 {
  char c = (char) waitKey( 2 );
  if( c == 'q' || c == 27 )
 break;
  if( c == 'p' )
 paused = !paused;
  if ( !paused )
 {
  cap >> frame;
 if(frame.empty())
 {
 break;
 }
  frame.copyTo( image );
 if( selectObject )
 {
  if( !initialized )
 {
  //initializes the tracker
  if( !tracker->init( frame, boundingBox ) )
 {
  cout << "***Could not initialize tracker...***\n";
 return -1;
 }
 initialized = true;
 }
 else
 {
  //updates the tracker
  if( tracker->update( frame, boundingBox ) )
 {
  rectangle( image, boundingBox, Scalar( 255, 0, 0 ), 2, 1 );
 }
 }
 }
  imshow( "Tracking API", image );
 frameCounter++;
 }
 }
 return 0;
}

} Is there any way to speed it up , by changing its parameters or anything else. Help neeeded . THNX in advance

/How How to speed up TLD tracker in opencv 3 with contrib modules ?

i have tried running ran the sample TLD which code , it works but the framerates are low and delay is builtin in opencv 3 + contrib module very high , but this code seems to work really slow for TLD

#include <opencv2/core/utility.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstring>

using namespace std;
using namespace cv;

static Mat image;
static Rect2d boundingBox;
static bool paused;
static bool selectObject = false;
static bool startSelection = false;

static const char* keys =
{ "{@tracker_algorithm | | Tracker algorithm }"
    "{@video_name      | | video name        }"
    "{@start_frame     |0| Start frame       }" 
    "{@bounding_frame  |0,0,0,0| Initial bounding frame}"};

static void onMouse( int event, int x, int y, int, void* )
{
  if( !selectObject )
  {
    switch ( event )
    {
      case EVENT_LBUTTONDOWN:
        //set origin of the bounding box
        startSelection = true;
        boundingBox.x = x;
        boundingBox.y = y;
        boundingBox.width = boundingBox.height = 0;
        break;
      case EVENT_LBUTTONUP:
        //sei with and height of the bounding box
        boundingBox.width = std::abs( x - boundingBox.x );
        boundingBox.height = std::abs( y - boundingBox.y );
        paused = false;
        selectObject = true;
        break;
      case EVENT_MOUSEMOVE:

        if( startSelection && !selectObject )
        {
          //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 );
          imshow( "Tracking API", currentFrame );
        }
        break;
    }
  }
}

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";
}

int main( int argc, char** argv )
{
    //open the capture
    VideoCapture cap(0);
    if( !cap.isOpened() )
    {
      return -1;
    }

    //
    //  "MIL", "BOOSTING", "MEDIANFLOW", "TLD"
    //
    string tracker_algorithm = "MIL";
    if ( argc>1 ) tracker_algorithm = argv[1];

    Mat frame;
    paused = false;
    namedWindow( "Tracking API", 0 );
    setMouseCallback( "Tracking API", onMouse, 0 );

    Ptr<Tracker> tracker = Tracker::create( tracker_algorithm );
    if( tracker == NULL )
    {
        cout << "***Error in the instantiation of the tracker...***\n";
        return -1;
    }

    //get the first frame
    cap >> frame;
    frame.copyTo( image );
    imshow( "Tracking API", image );

    bool initialized = false;
    int frameCounter = 0;

    for ( ;; )
    {
        char c = (char) waitKey( 2 );
        if( c == 'q' || c == 27 )
            break;
        if( c == 'p' )
            paused = !paused;

        if ( !paused )
        {
            cap >> frame;
            if(frame.empty())
            {
                break;
            }
            frame.copyTo( image );

            if( selectObject )
            {
                if( !initialized )
                {
                    //initializes the tracker
                    if( !tracker->init( frame, boundingBox ) )
                    {
                    cout << "***Could not initialize tracker...***\n";
                    return -1;
                    }
                    initialized = true;
                }
                else
                {
                    //updates the tracker
                    if( tracker->update( frame, boundingBox ) )
                    {
                        rectangle( image, boundingBox, Scalar( 255, 0, 0 ), 2, 1 );
                    }
                }
            }
            imshow( "Tracking API", image );
            frameCounter++;
        }
    }

    return 0;
}

Is are there any way to speed it up , by changing its parameters parameter or anything else. Help neeeded . THNX in advance else that can be altered to boost it??? Please help.

click to hide/show revision 4
No.4 Revision

updated 2015-01-27 08:42:06 -0600

berak gravatar image

How to speed up TLD tracker in opencv 3 with contrib modules ?

i ran the sample TLD code code , it works but the framerates are low and delay is very high , are there any parameter or anything else that can be altered to boost it??? Please help.

click to hide/show revision 5
No.5 Revision

updated 2015-01-27 08:45:09 -0600

berak gravatar image

How to speed up TLD tracker in opencv 3 with contrib modules ?

i ran the sample TLD code , (using the "MIL" tracker), it works but the framerates are low and delay is very high , are there any parameter or anything else that can be altered to boost it??? Please help.

How to speed up TLD tracker in opencv 3 with contrib modules ?

i ran the sample TLD code (using the "MIL" "TLD" tracker), it works but the framerates are low and delay is very high , are there any parameter or anything else that can be altered to boost it??? Please help.