I need to create an image that has twice as many columns of the original image. Therefore, I saved the width of the new image twice as compared to the original image.
Although this is a very simple task, and I have already done it, I am interested in learning about the strange results obtained when performing this task using memcpy() .
My code is:
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; }
Original Image:

Result

Expected results:

Question: When the resulting image is only twice as large as the original image, how is it that 4 original images are copied to a new image? Secondly, memcpy() copies the continuous memory location in different ways, therefore, in accordance with this, I should get the image that is shown in the "Expected Results".
source share