title: Making Queue of cv::Mat
body: <p>I have implemented a simple program containing a single producer and consumer. In this program producer thread is grabbing frame from Camera's Live stream and saving it in queue as well as in a folder, whereas in Main thread(Consumer) i am getting this frame and saving it, In order to see that the Frame got by the consumer is same as the one that is pushed by the producer. But the results are not same. Can anyone help me out in identifying my mistake?</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;cv.h&gt;
  #include &lt;highgui.h&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;queue&gt;
  #include &lt;deque&gt;
  #include &lt;time.h&gt;
  #include "Producer.h"
  #include "boost\thread.hpp"
  using namespace cv;
  using namespace std;
  
  queue&lt;Producer&gt; Producers;
  boost::mutex sharedMutex;
  
  void threadFunction()
  {
      Producer p;
      string name="Havard";
      VideoCapture capture("rtsp://192.168.10.20:1125/Master-0?profile=Master-0");
      stringstream filenamep;
      SYSTEMTIME st;
      Mat Image;
      Mat Image2;
      for(int i=0;i&lt;200;i++)
      {
          sharedMutex.lock();
          capture &gt;&gt; Image;
          Image.copyTo(Image2);
          p.setVariables(i,name,Image2);
          Producers.push(p);
          filenamep &lt;&lt; "D:/MultiThreading/MakingThreadSafeQueue/Images/" &lt;&lt; p.count &lt;&lt; "p.jpg";
          imwrite(filenamep.str(),Image2);
          sharedMutex.unlock();
          filenamep.str("");
          Image.release();
          Image2.release();
      }
  }
  
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      Mat ImgC;
      Producer p2;
      boost::thread producerThread(&amp;threadFunction);
      stringstream filename;
      while(1)
      {
      Sleep(500);
      while(!Producers.empty())
      {
      sharedMutex.lock();
      p2=Producers.front();
      p2.img.copyTo(ImgC);
      imshow("Frame",p2.img);
      filename &lt;&lt; "D:/MultiThreading/MakingThreadSafeQueue/Images/" &lt;&lt; p2.count &lt;&lt; ".jpg";
      imwrite(filename.str(),ImgC);
      Producers.pop();
      sharedMutex.unlock();
      ImgC.release();
      p2.img.release();
      filename.str("");
      }
      char c=cvWaitKey(1);
      if(c==27) break;
      }
      return 0;
  } 
  </code></pre>