如何有效地从后台线程对Delphi 6框架或窗体执行图像流预览? [英] How to perform an image stream preview to a Delphi 6 frame or form from a background thread efficiently?

查看:63
本文介绍了如何有效地从后台线程对Delphi 6框架或窗体执行图像流预览?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Delphi 6应用程序,该应用程序接收并处理来自外部相机的图像流.我在后台线程上有代码,因为它占用大量CPU,并且我不希望它干扰在主线程上运行的用户界面代码.我想用我从相机的JPEG帧(以每秒25帧的速率接收)创建的TBitmap更新表单或帧上的矩形区域.

I have a Delphi 6 application that receives and processes an image stream from an external camera. I have the code on a background thread since it is CPU heavy and I don't want it interfering with with the user interface code that runs on the main thread. I want to update a rectangular area on a form or frame with the TBitmaps I create from the camera's JPEG frames that are received at a rate of 25 frames per second.

我想知道哪种方法将为我带来最佳性能,以及Windows API调用或Delphi调用使用的方法.我猜我不应该使用TImage或TPicture或类似的VCL组件,因为它们运行在主线程上,而且我敢肯定,尝试通过Synchronize()调用完成任何事情的效率都会很低,并且有可能会变慢减少涉及的线程.我还希望有一种技术能够提供平滑的视频显示,就像双缓冲控件一样,没有任何条纹"效果.另外,任何有关适当的Canvas锁定或设备上下文管理的技巧,尤其是避免在释放资源时出现常见错误的技巧,都将受到赞赏.

I want to know what method will give me the best performance and what Windows API calls or Delphi calls to use to do it. I would guess I should not use a TImage or TPicture or similar VCL component because they run on the main thread and I'm pretty sure trying to get anything done via a Synchronize() call is going to be inefficient and has the potential to slow down the threads involved. I would also want a technique that provides a smooth video display like double buffered controls do without any "striping" effects. Also, any tips on proper Canvas locking or device context management, etc. would be appreciated, especially tips on avoiding common mistakes in freeing resources.

当然,一个指向可以满足我需要的良好代码示例的链接会很棒.

Of course, a link to a good code sample that does what I need would be great.

推荐答案

AFAIK TBitmap如果仅在其画布上工作,则是线程安全的.如果您发送GDI消息并需要刷新屏幕,则需要Synchronize,但是从我的实验来看,使用TBitmap.Canvas只是线程安全Windows API的包装.如果您使用像素算术(例如使用Scanline)处理位图(每个线程一个唯一的位图),则可以在后台进行.

AFAIK TBitmap are thread-safe, if you work only on its canvas. Synchronize is needed if you send GDI messages and need to refresh the screen, but from my experiment, using TBitmap.Canvas is just a wrapper around thread-safe Windows API. If you process the bitmap with pixel arithmetics (using e.g. Scanline), one unique bitmap per thread, you can do it on background.

但是我怀疑使用TBitmap并不是最有效的方法.尝试 http://graphics32.org http://aggpas.org ,这是处理位图的非常快速的方法.

But I suspect using TBitmap is not the most efficient way. Give a try to http://graphics32.org or http://aggpas.org which are very fast way to work on bitmaps.

如imajoosy所建议的那样,处理输入流的最佳方法是使用直接X流处理能力.

If you can, as imajoosy proposed, the best way to process your input stream is to use direct X streaming process abilities.

对于线程安全的进程,如果每个线程都将消耗其内核的100%(对于映像进程,则很有可能),通常假定您最好为处理创建NumberOfCPU-1线程.例如,您可以创建一个线程池,然后让那些线程使用输入流中的位图.

For thread-safe process, if each thread is about to consume 100% of its core (which is very likely for image process), it is generally assumed that you shall better create NumberOfCPU-1 threads for your processing. For instance, you could create a pool of threads, then let those consume the bitmaps from the input stream.

这篇关于如何有效地从后台线程对Delphi 6框架或窗体执行图像流预览?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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