不同线程上的网络摄像头帧处理

发布于 2024-12-24 18:11:19 字数 357 浏览 3 评论 0原文

我有一个应用程序对每个新帧进行一些图像处理,最近我买了一个新的网络摄像头,与我的旧摄像头(360x240)相比,它的分辨率非常好,为 1280x960,我的应用程序对网络摄像头的每个新帧进行一些图像处理但在如此高分辨率的情况下,处理速度会变慢,并且我的应用程序会挂起。我想我可以在应用程序启动时启动 10 个线程,并将每个帧从主线程裁剪为 10 个相等的部分,然后将其传递给工作线程,这样每个工作线程只需处理帧的一小部分。

我的应用程序分析像素颜色并报告何时找到正确的颜色,因此我想使用线程重新创建它。

我之前使用过线程和线程池,但我不太确定如何保持线程活动并在运行时从主线程传递对象,因此任何代码都会有帮助,或者也许有更好的方法来解决这个问题?

谢谢

I have an application that does some image processing on each new frame, recently I bought a new web cam that has really nice resoultion of 1280x960 compared to my old cam(360x240), my application does some image processing on each new frame from web cam but with such a high resolution the processing just goes to slow and my app hangs. I was thinking that I could start say 10 threads at application start and crop each frame to 10 equal pieces from main thread and pass it to worker threads so every worker thread only has to deal with small part of frame.

My application analyzes pixel colors and report when correct color is found,so I would like to re-create this with threading.

I worked before with Threading and Thread pool but I'm not really sure how to keep thread alive and pass objects from main thread while it's running, so any piece of code would be helpuful, or maybe there is a better approach to this problem?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

站稳脚跟 2024-12-31 18:11:19

这是“生产者-消费者”的典型案例...网络摄像头是“生产者”,线程是“消费者”...

在 .NET (4) 中,有一个非常好的实现,称为 BlockingCollection< /code> 轻松构建它 - 请参阅 http://msdn.microsoft.com/en-us/library/dd997371.aspxhttp://msdn.microsoft.com/en-us/library/dd267312.aspx

That is a classic case for "Producer-Consumer"... you webcam being the "producer" and the threads being the "consumers"...

In .NET (4) there is a really nice implementation called BlockingCollection to build this easily - see http://msdn.microsoft.com/en-us/library/dd997371.aspx and http://msdn.microsoft.com/en-us/library/dd267312.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文