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 1280×960 compared to my old cam(360×240), 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
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
BlockingCollectionto build this easily – see http://msdn.microsoft.com/en-us/library/dd997371.aspx and http://msdn.microsoft.com/en-us/library/dd267312.aspx