In fact, you do not want to copy the data, since you start with an RGB image CV_8UC3, and want to work with a grayscale image CV_8UC1.
cvtColor, RGB .
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace cv;
int main()
{
Mat inImg = cv::imread("C:\\Users\\DUY\\Desktop\\basic_shapes.png");
Mat outImg;
cvtColor(inImg, outImg, COLOR_RGB2GRAY);
imshow("Test", inImg);
imshow("Test2", outImg);
waitKey();
}
memcopy uchar :
BGR BGR BGR BGR ...
, (G ):
G G G G ...
, outImg .
, outImage :
cv::Mat outImg(width, height, CV_8UC3);