OpenCV CascadeClassifier多线程中的C ++接口 [英] OpenCV CascadeClassifier C++ Interface in Multiple Threads

查看:1325
本文介绍了OpenCV CascadeClassifier多线程中的C ++接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在多个线程中使用CascadeClassifier对象运行OpenCV C ++接口。

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

我的程序工作原理是我的主线程加载some_file.xml转换为CascadeClassifier对象。生成三个或更多线程,并且它们通过级联对象。程序很快崩溃。我做了几个测试,并得出结论,CascadeClassifier对象在执行detectmultiscale函数时不是线程安全的。

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?

推荐答案

如果你使用HaP级联的LBP级联存储新格式,那么你可以避免从每个新线程的文件系统读取级联:

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:

将级联加载到内存中:

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

接下来将fs对象传递给每个新线程并创建CascadeClassifier对象:

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

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

这篇关于OpenCV CascadeClassifier多线程中的C ++接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆