简体   繁体   中英

OpenCV CascadeClassifier C++ Interface in Multiple Threads

I would like to run an OpenCV C++ Interface using the CascadeClassifier Objects in multiple threads.

The way my program works is my main thread loads "some_file.xml" into a CascadeClassifier object. Three or more threads are spawned and they are passed the cascade object. The program soon crashes thereafter. I have done several tests and concluded that the CascadeClassifier object is not thread-safe when doing a "detectmultiscale" function.

I would like to avoid having to read the same file off of the hard drive every time a new thread is spawned. How can this be avoided?

If you are working with LBP cascade of with Haar cascade stored in new format then you can avoid reading cascade from file system for each new thread:

Load cascade into memory:

cv::FileStorage fs(path_to_cascade_file, cv::FileStorage::READ);
if (!fs.isOpened())
    HandleError();

Next pass fs object to the each new thread and create CascadeClassifier object:

cv::CascadeClassifier cc;
if (!cc.read(fs.getFirstTopLevelNode())
    HandleError2();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM