title: Display image in second thread, OpenCV?
body: <p>I have a loop to take in images from a high speed framegrabbger at 250fps. </p>
  
  <pre><code>/** Loop processes 250 video frames per second **/
  while(1){
    AcquireFrame();
    DoProcessing();
    TakeAction();
  }
  </code></pre>
  
  <p>At the same time, I would like the user to be able to monitor what is going on. The user  only needs to see images at around 30 fps (or less). How do I set up a second thread that displays the current frame every so often? </p>
  
  <pre><code>Thread(){
    cvShowImage();
    Wait(30); /** Wait for 30 ms **/
  }
  </code></pre>
  
  <p>I am on Windows on a quad core Intel machine using MinGW, gcc and OpenCV 1.1. The main criteria is that the display thread must take as little time away from my main processing loop as possible. Every millisecond counts.</p>
  
  <p>I have tried using <code>CreateThread()</code> to create a new thread with <code>cvShowImage()</code> and <code>cvWaitKey()</code> but <a href="http://tech.groups.yahoo.com/group/OpenCV/message/66862" rel="noreferrer">apparently those functions are not threadsafe</a>. </p>
  
  <p>I am considering using OpenMP, but some people <a href="http://software.intel.com/en-us/forums/threading-on-intel-parallel-architectures/topic/47611/" rel="noreferrer">report problems with OpenMP and OpenCV</a>. I also am considering trying to use DirectX directDraw because apparently it is very fast. but it <a href="http://www.codeproject.com/KB/directx/basicdd.aspx" rel="noreferrer">looks complicated</a> and evidentally there are <a href="http://www.emmestech.com/moron_guides/moron1.html" rel="noreferrer">problems using Windows DLL's with MinGw</a>.</p>
  
  <p>Which of these avenues would be the best place to start?</p>