OpenCV 3 Tracker will not work after reinitialization

I have a problem using the OpenCV 3 tracking module for tracking. It behaves the same way, either I use the interface class (cv :: Tracker), or the implementation class (for example, cv :: TrackerMedianFlow or cv :: TrackerMIL, etc.). The sample is a slightly modified sample from the OpenCV sample folder. After creating it correctly

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

initialization works just fine

 if ( !tracker->init( frame, boundingBox ) ) { std::cout << "***Could not initialize tracker...***\n"; return -1; } 

The problem arises in the later stages, with the main loop when tracking is lost. I use a separate detector to determine a new target. When I find a new target, I clear the tracker and initialize it with a new value

  tracker->clear( ); if ( !tracker->init( frame, detectedNewBBox) ) { std::cout << "***Could not initialize tracker without history...***\n"; return -1; } 

However, initialization always returns false. I am trying to find out why the Tracker cannot be initialized? The data has been checked several times and looks pretty correct. I even did a little experiment trying to initialize the tracker right after creating it with the same data that it wonโ€™t initialize the loop, and it works fine. Am I doing something wrong? I could not find the documentation on this ... Here is the link to the available documentation on this: Tracker OpenCV 3 Documentation

Thanks for any effort!

+6
source share
3 answers

I ran into the same problem, this is how I earned it:

 tracker->clear(); Ptr<Tracker> trackerNew = Tracker::create( tracker_algorithm ); tracker = trackerNew; tracker->init( image, boundingBox ); 

Perhaps this is not the right way or the most beautiful, but it does the job :)

+2
source

I ran into the same problem and here is my solution: Open the file in opencv_contrib / modules / tracking / src / tracker.cpp and apply the following changes:

 - if( isInit ) + /*if( isInit ) { return false; } + */ 

I recompiled opencv3 and reinstall it. This fixed it for me. I think they didnโ€™t want people to reinitialize the tracker for some reason. I'm not sure why?

0
source

If you want to track a new ROI (area of โ€‹โ€‹interest), I suggest you create a new tracker instead of clearing and reusing the previous tracker. Reusing when you need to call init will not give any additional benefit. As you noticed, re-initialization of the tracker is not allowed by default.

But if you want to resume tracking the same object with your correction, it may be possible by following these steps (I have not tried it myself yet, the following code is just pseudo-code ).

 Ptr<TrackerModel> model = tracker->getModel(); Ptr<TrackerTargetState> lastTargetstate = getLastTargetState(); // Make changes to lastTargetState (update position etc) // Set lastTargetState, I am not sure if you need to actually set it // or just editing the object through pointer should work. model->setLastTargetState(lastTargetstate); 
0
source

All Articles