使用Qt并行化OpenCV处理 [英] Parallelize OpenCV Processing with Qt

查看:145
本文介绍了使用Qt并行化OpenCV处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Qt和OpenCV.我使用QtOpenGL Widgets并将opencv帧映射为glPlane上的纹理,这确实非常快并且效果很好.

I'm working with Qt and OpenCV. I use QtOpenGL Widgets and map opencv frames as textures on a glPlane, which is really fast and works great.

现在,我想知道是否可以通过使用QThreads进一步提高性能. QThread具有实现的映射和缩减功能.因此,应该有可能拆分opencv框架并让多个线程处理这些框架.

Now I wonder if I could improve performance even more by using QThreads. QThread has mapping and reducing features implemented. Therefore it should be possible to split opencv frames and let multiple Threads process the frames.

例如:如果我的帧是640x480,并且有4个线程可用,我会将帧分割为640x120大小的帧,然后将其传递给每个线程.

As Example: If my frame is 640x480 and I have 4 Threads available I would split the frame in 640x120 sized frames and pass one to each thread.

线程没有共享数据,因为每个线程都有自己的框架,最后我只需要附加这四个框架或将它们复制到新的框架中即可.

The Threads don't have shared data because every thread get it's own frame and at the end I just need to append the 4 frames or copy them into a new frame.

我的问题是,您认为这是否行得通,这会给我带来处理上的帮助,还是在其他地方存在瓶颈?

My Question is, do you think this will work and it will give me a boost in processing or is there a bottleneck elsewhere?

推荐答案

首先,请确保不要为每个框架都创建新线程-构造线程很昂贵.一个轻量级的解决方案是使用 QtConcurrent :: run()创建N个QFutures .在每个期货上使用 QFuture :: waitForFinished 并收集结果.但是,我不相信QFutures是用于实时处理的正确解决方案.一种替代方法是直接使用 QThreadPool .同样,请确保不要在每一帧都创建池.

First of all, make sure you don't create new threads for every frame - constructing threads are expensive. A lightweight solution could be to use QtConcurrent::run() to create N QFutures. Use QFuture::waitForFinished on each of the futures and collect the results. However, I'm not convinced that QFutures are the right solution for realtime processing. An alternative approach would be to use QThreadPool directly. Again, make sure you don't create the pool every frame.

这篇关于使用Qt并行化OpenCV处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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