title: OpenCV and Mat vectors: assignment with copyTo and clone()
body: <p>I have tried to look for solution myself, but I have spent so much time and still no use.</p>
  
  <p>Here is the issue: I am capturing frames (from std camera) and putting them into buffer - vector (of Mat). When I take a frame, I put it into first position and all of the rest are pushed to the right, like this:</p>
  
  <p>Let say we have a vector of Mats {1 2 3}, then I capture frame 0 and I must have {0 1 2}.</p>
  
  <p>I have defined vector for this purpose, but when pushing elements, I face weird behaviour. Here is my code (objectPatches is Mat vector, frameHSV is simple Mat):</p>
  
  <pre><code>        for (vector&lt;Mat&gt;::size_type j = objectPatches.size() - 1; j &gt;= 1; j--) {
          objectPatches[j - 1].copyTo(objectPatches[j]); // DOES NOT
  
          objectPatches[j] = objectPatches[j - 1].clone(); //WORKS
      }
      frameHSV.copyTo(objectPatches[0]);
  </code></pre>
  
  <p>When I try to update buffer using copyTo(), all buffer values are filled with the same value (are the same images) and I do not get so called "wave" of pictures (changing wave), however, when I try to do the same with clone(), it does work fine and I get the result. What is the reason for this assignment? Is there something I miss?</p>
  
  <p>Thanks a lot.</p>
  
  <p>EDIT 1:</p>
  
  <p>Before the loop, objectPatches already hold images of the same size, so I mean that vector is fully initialized and does have some init data assigned. In loop step it only has to rearrange those images to the right.</p>
  
  <p>EDIT 2:</p>
  
  <p>vector objectPatches, when initialized, is filled with push_back() function. Code clipping:</p>
  
  <pre><code>Mat capframe;
  capFromCamera.read(capFrame);
  objectPatches.push_back(capFrame);
  </code></pre>
  
  <p>So that means, based on Micka answer, that they share the same data array.</p>