gnebehay / OpenTLD

A C++ implementation of OpenTLD
http://gnebehay.github.com/OpenTLD/
GNU General Public License v3.0
460 stars 196 forks source link

Creating Multiple OpenTLD objects to Track Multiple objects #47

Open vreddy1990 opened 10 years ago

vreddy1990 commented 10 years ago

Instead of running multiple instances of OpenTLD application, would there be any problems in creating a class called OpenTLD and creating multiple instances of the class for tracking multiple objects? The OPenTLD class that I created has its own Main* etc.. and thus when used as an imported dll could easily track multiple objects.

Does any of the code have any static variables / objects that may be shared by all Main objects? This is the only problem that I am anticipating. If anyone has any advice please let me know. At present when I create the second OpenTLD object it works fine until I start running the TLD methods on the second object then the application crashes.

vreddy1990 commented 10 years ago

Can someone please advice me on how to handle int success = fbtrack(&prevImg, &currImg, bb_tracker, bb_tracker, &scale); If I skip this code I am able to run multiple instances of the OpenTLD class that I have created. This function is the culprit in crashing the program if a second instance is created. There is a static IplImage **PYR = 0; in Lk.cpp that may be a problem. I tried setting up a non-static IplImage pointer in Median Flow Tracker and passed its address through the intermediary functions to the fuctions that use PYR but it does not do the job. It actually crashes the program now with just one instance of OpenTLD.

vreddy1990 commented 10 years ago

Resolved the crash by locking the following function calls while a thread is accessing them in FBTrack.cpp, fbtrack(... ... ...)

include

mutex mtex;

mtex.lock(); initImgs(); trackLK(imgI, imgJ, pt, nPoints, ptTracked, nPoints, level, fb, ncc, status); initImgs(); mtex.unlock();

This way race condition is avoided. The two functions defined in Lk.cpp should ideally be in a class with non static members so that multiple threads are not stopped while waiting for unlock.