opencv Tracker is too slow in high revolution!

asked 2018-07-26 05:27:31 -0600

rainY gravatar image

System information (version)

OpenCV => 3.4.2:

Operating System / Platform => Android:

Compiler => cmake

Detailed description

Hi, Is there any way to improve the Tracking frame rate? When I use high resolution, the efficiency is very slow. example: I set the resolution of my phone to 1280 * 720. the fps is 20 or less. in TrackerKCF algorithm. when set resolution to 640 * 480 .the fps will arrive at More than 20 close to 30. But my needs here are at 1280 * 720, reaching a frame rate close to 30 or 30+.

Please help me,thanks!

detail code:

i invoke startTracking by JNI in Camera's onPreviewCallback.

 void startTracking(uint8_t* src_frame, int w, int h){  

  if(!isRectInit) return;  

image = Mat(h,w,CV_8UC1,src_frame);
tracker = TrackerKCF::create();
isInit = tracker->init(image, bbox);
//cv::rectangle(image, bbox, Scalar( 255, 0, 0 ), 2, 1 );
//updates the tracker
// Start timer
double timer = (double)getTickCount();     
// Update the tracking result  
bool isOk = tracker->update(image, bbox);
// Calculate Frames per second (FPS)
LOGD("startTracking  5 -- isOk = %d -- after update :%f--%f--%f--%f",isOk,bbox.x,bbox.y
float fps = getTickFrequency() / ((double)getTickCount() - timer);
LOGD("startTracking  6 -- %f ",fps);
edit retag flag offensive close merge delete


yes, KCF is slow. but you have 7 alternatives to choose from there. try medianflow, CSRT, or MOSSE instead.

(and please close your issue here . it's the wrong repository (opencv_contrib) and you are not reporting a bug.)

berak gravatar imageberak ( 2018-07-26 05:32:18 -0600 )edit

hi berak, I closed the issue new . But I have tried the algorithms you mentioned, I found that the KCF effect is the best in those algorithms.

rainY gravatar imagerainY ( 2018-07-26 05:36:46 -0600 )edit

@berak Is there any other solution?

rainY gravatar imagerainY ( 2018-07-26 05:58:29 -0600 )edit

there is a benchmark program in the samples. i came to the opposite conclusion

berak gravatar imageberak ( 2018-07-26 06:01:25 -0600 )edit

@rainY what kind of objects do you want to track?

sturkmen gravatar imagesturkmen ( 2018-07-26 07:04:34 -0600 )edit

Why do you need to work at full resolution? You are on a mobile platform. Try to resize your image to a lower resolution, perform the tracking at this scale and update the bounding box to match the full resolution?

You have out of the box tracking algorithms. If you need better accuracy, you would probably need to implement yourself a modified tracking algorithm. Maybe track at low resolution and try to refine somehow the tracking at high resolution using a prior information from the tracking at low resolution?

Eduardo gravatar imageEduardo ( 2018-07-26 07:54:45 -0600 )edit

@sturkmen Track anything,I only need to specify a region to track which area I am delineating.

rainY gravatar imagerainY ( 2018-07-26 20:49:19 -0600 )edit

@Eduardo "Try to resize your image to a lower resolution, perform the tracking at this scale and update the bounding box to match the full resolution?" I don't understand this sentence very well. Can you give me some code examples?

rainY gravatar imagerainY ( 2018-07-26 20:51:12 -0600 )edit

@berak Did your conclusion be tested with this code?
Tracking sample Is fps too low or not caused by VideoCapture? My data is obtained from the camera's onPreviewCallback, without VideoCapture. Is there any other way to improve fps besides replacing the algorithm?

rainY gravatar imagerainY ( 2018-07-26 20:58:14 -0600 )edit

I try medianflow. Occur this issue . app crash in TrackerMedianFlow

rainY gravatar imagerainY ( 2018-07-27 03:05:41 -0600 )edit