How to efficiently preview a stream of images in a frame or Delphi 6 form from a background stream?

I have a Delphi 6 application that receives and processes an image stream from an external camera. I have code in the background thread, as it is a heavy processor, and I do not want it to interfere with the user interface code that runs on the main thread. I want to update a rectangular area on a shape or frame using TBitmaps, which I create from JPEG camera frames that are received at 25 frames per second.

I want to know which method will give me the best performance and what will call the Windows API or Delphi calls to use it. I would suggest that I should not use the TImage or TPicture component or a similar VCL component because they start in the main thread, and I am sure that trying to get something through a Synchronize () call will be inefficient and may slow down the threads involved . I would also like to get a technique that provides a smooth video display, such as dual buffer control, without any “striped” effects. Any advice on fixing the Canvas properly or managing the device context, etc. will also be appreciated, especially tips on preventing common errors when releasing resources.

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

+4
source share
1 answer

AFAIK TBitmap are thread safe if you only work on your canvas. Synchronize is required if you are sending GDI messages and need a screen refresh, but from my experiment using TBitmap.Canvas is just a wrapper around a thread-safe Windows API. If you are processing a bitmap using pixel arithmetic (using, for example, Scanline ), one unique bitmap per stream, you can do this in the background.

But I suspect that using TBitmap not the most efficient way. Try http://graphics32.org or http://aggpas.org , which is a very fast way to work with bitmaps.

If you can, as imago suggested, the best way to process your input stream is to take advantage of the direct X-stream process.

For a thread-safe process, if each thread is going to consume 100% of its core (which is very likely for the image process), it is usually assumed that you are better off creating NumOfCPU-1 threads for your processing. For example, you can create a pool of threads and then let them use bitmaps from the input stream.

+3
source

Source: https://habr.com/ru/post/1389018/


All Articles