OpenCV Mat Data point access and memcpy to another Mat, example source code

This is example source code.

Mat inImg = imread("Penguins.jpg",0);
//Data point copy
unsigned char * pData = inImg.data;
int width = inImg.rows;
int height = inImg.cols;
//gray color value reverse
for(int i=0; i < width; ++i)
  for(int j=0; j < height; ++j)
   pData[j*width+i] = 255-pData[j*width+i];
//create another Mat same size, type with inImg
Mat outImg(width, height, CV_8UC1);
//data copy using memcpy function
memcpy(outImg.data, pData, sizeof(unsigned char)*width*height);
//processing and copy check
imshow("Test", inImg);

imshow("Test2", outImg);


Thank you.

1 comment:

  1. As new programming progressively takes into account better gathering, dissecting and using information effectively will exceed expectations quicker than we have ever observed. artificial intelligence course