简体   繁体   中英

C# threads that synchronize two cameras

I need to capture images from two cameras and combine them together.

The flow is like this:

  • two threads, one for each camera, sample the camera frames.
  • Each one sends the frame to a third thread, the consumer.
  • Only when the consumer has two frames he processes them, and
  • releases the capture threads so they can get the next frame.

Can someone outline what I need to do ? I'm using C# .Net 4.0

Have you tried reading this article?

http://msdn.microsoft.com/en-us/library/ms228964.aspx

All about thread synchronization using .NET 4. Surprisingly simple.

I would use any static variables or database to store the progress of individual camera's sampling activity. When both camera marks their individual flag as completed, reader flag will consume all frames, reset those flags. Uplon reset of its own individual flag, worker threads start on capturing next frame. You can also use delegate patters (prescriber-subscriber) to inform each other through events.

i'd give each capture-worker 2 AutoResetEvent objects ... one to signal when capturing is done (A), and the other to wait for permission to start the next capture (B) ...

worker routine would be the following loop:

capture to local buffer
signal A
wait for B

consumer loop:

wait for both A
copy both buffers
signal both B
process copys of buffers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM