memcpy拷贝函数所遇的坑
源代码:
double* featureData=new double[nSamples * nFeatures];
//featureData赋值代码省略
Mat trainFeature(nSamples, nFeatures, CV_64FC1, Scalar(0));
memcpy(trainFeature.data, featureData, (size_t)nSamples * nFeatures);
问题:发生生成的图像少了一大片,排查原因memcpy复制的字节数不够;
更改程序如下:
double* featureData=new double[nSamples * nFeatures];
//featureData赋值代码省略
Mat trainFeature(nSamples, nFeatures, CV_64FC1, Scalar(0));
memcpy(trainFeature.data, featureData, (size_t)nSamples * nFeatures * sizeof(double));