#include <stdio.h>
#include <string>
#include <iostream>
#include <opencv2/opencv.hpp>
usng namespace std;
using namespace cv;
int main(int argc, char **argv)
{
char* data = (char*)malloc(100*100);
Mat img = imread("./a.jpg");
Mat newImg = cv::Mat(100, 100, CV_8SC3, (void*)data); //transfer the data buf to Mat instance newImg
printf("data addr:%#x newImage.data:%#x\n", data, newImg.data); //newImg.data addr equeals to data addr
cv::resize(img, newImg, newImg.size(), 0, 0, cv::INTER_LINEAR);
printf("newImg.data ater resize:%#x\n", newImg.data);//newImage.data changed by cv::resize
free(data);
img.release();
return 1;
}
Result running this code:
data addr:0xa49a8360 newImage.data:0xa49a8360
newImg.data ater resize:0xa49b1cc0
Perhaps opencl API clSetKernelArg will be called and then moved the data buf.
And there will be a memory leak of this code detected by valgrind.