title: Understanding the copy done by memcpy()
body: <p>I have to create an image which has two times the number of columns to that of the original image. Therefore, I have kept the width of the new image two times to that of the original image.</p>
  
  <p>Although this is a very simple task and I have already done it but <strong>I am wondering about the strange results obtained by doing this task using <code>memcpy()</code></strong>. </p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>int main()
  {
  
      Mat image = imread("pikachu.png", 1);
      int columns = image.cols;
      int rows = image.rows;
  
      Mat twoTimesImage(image.rows, 2 * image.cols, CV_8UC3, Scalar(0));
  
      unsigned char *pSingleImg = image.data;
      unsigned char *ptwoTimes = twoTimesImage.data;
  
      size_t memsize = 3 * image.rows*image.cols;
  
      memcpy(ptwoTimes , pSingleImg, memsize);
      memcpy(ptwoTimes + memsize, pSingleImg, memsize);
  
      cv::imshow("two_times_image.jpg", twoTimesImage);
  
      return 0;
  }
  </code></pre>
  
  <p><strong>Original Image:</strong></p>
  
  <p><a href="https://i.imgur.com/ImjqDA0m.png" rel="nofollow noreferrer"><img src="https://i.imgur.com/ImjqDA0m.png" alt="image1"></a></p>
  
  <p><strong>Result</strong></p>
  
  <p><a href="https://i.imgur.com/bdajMOh.jpg" rel="nofollow noreferrer"><img src="https://i.imgur.com/bdajMOh.jpg" alt="image2"></a></p>
  
  <p><strong>Expected Results:</strong></p>
  
  <p><a href="https://i.imgur.com/URsoZx3.jpg" rel="nofollow noreferrer"><img src="https://i.imgur.com/URsoZx3.jpg" alt="image3"></a></p>
  
  <p><strong>Question:</strong> When the resulting image is just two times to that of the original image then, how come 4 original images are getting copied to the new image? Secondly, the <code>memcpy()</code> copies the continous memory location in a row-wise fashion so, according to that I should get an image which is shown in the "Expected results".</p>