PDA

View Full Version : Using concurrency for video processing



ccbaci
4th September 2013, 08:51
Hi all,

I am doing real time video processing. I have to apply a vision algorithm to every single frame and show it on a view. So far, I managed it. However, it is slow and I am losing most of the image frames, because of the complexities in the processing algorithm. While the algorithm is running, I should continue getting frames and make use of them inside another threads. I had to somehow use multi-threading. I have read through this explanatory doc http://www.develer.com/promo/workshop/enhancing_with_multi_threading.pdf and seen that the best way is concurrency. I thought of a flow using 50 threads pseudo coded as such:



result[50]; // array of QFuture<QImage>
while(1)
{
result[0] = run(algorithm); // "algorithm" includes getting a frame from camera, process and return

for(i = 1; i < 20; i++)
{
if(result[0].isRunning())
{
result[i] = run(algorithm);
}
else
break; // breaking depends on the algorithm time
}

for(j = 0; j < i; j++)
{
run(show, result[j].result()); // show results on ui
}
}


This flow assumes no time loss when running a concurrent process. My questions are:

- Say I have a video 200 fps = 1 frame per 5 ms. Does "QtConcurrent::run" start its execution faster than ms range, so that I can guarantee not to lose any frames?
- Is concurrency cause memory leaks or any application crashes reported?
- Is there a faster and applicable way of multi-threading for my issue?