Skip to content

Instantly share code, notes, and snippets.

@sagi-z
Created March 23, 2017 14:17
Show Gist options
  • Save sagi-z/6b0dd749f6bda446c63d6465fd231239 to your computer and use it in GitHub Desktop.
Save sagi-z/6b0dd749f6bda446c63d6465fd231239 to your computer and use it in GitHub Desktop.
//...
if( capture.isOpened() )
{
//...
tbb::concurrent_bounded_queue<ProcessingChainData *> guiQueue;
guiQueue.set_capacity(2); // TBB NOTE: flow control so the pipeline won't fill too much RAM
auto pipelineRunner = thread( detectAndDrawTBB, ref(capture), ref(guiQueue), ref(cascade), ref(nestedCascade), scale, tryflip );
//...
// TBB NOTE: GUI is executed in main thread
ProcessingChainData *pData=0;
for(;! done;)
{
if (guiQueue.try_pop(pData))
{
char c = (char)waitKey(1);
if( c == 27 || c == 'q' || c == 'Q' )
{
done = true;
}
imshow( "result", pData->img );
delete pData;
pData = 0;
}
}
double tfreq = getTickFrequency();
double secs = ((double) getTickCount() - startTime)/tfreq;
cout << "Execution took " << fixed << secs << " seconds." << endl;
// TBB NOTE: flush the queue after marking 'done'
do
{
delete pData;
} while (guiQueue.try_pop(pData));
pipelineRunner.join(); // TBB NOTE: wait for the pipeline to finish
}
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment