我读了一个图像,它的类型是CV_8UC1,我想将它转换为CV_32FC1.但是当我使用convertTO()函数时,我的图像变成完全白色,我不知道为什么!
Mat Image(512,512,CV_32FC1);
Image = imread("C:\\MGC.jpg",CV_LOAD_IMAGE_GRAYSCALE);
/// show image
namedWindow("pic");
int x = 0; int y = 0;
imshow("pic", Image);
cout<<Image.type()<<endl;
Image.convertTo(Image,CV_32FC1);
cout<<Image.type()<<endl;
////show converted image
namedWindow("pic1");
imshow("pic1",Image );
Run Code Online (Sandbox Code Playgroud) 我在设备中分配了一个2D数组,并希望将2D浮点数组复制到设备中.ImgSrc是openCV中的Mat类型,我通过使用cudaMemcpy2DToArray()将其元素复制到名为ImgSrc_f.then的2D浮点数组中.我将主机2D数组(ImgSrc_f)复制到设备2D数组Src.2D阵列的大小为512X512.
cudaChannelFormatDesc floattex = cudaCreateChannelDesc<float>();
cudaArray *Src;
cudaMallocArray(&Src, &floattex, 512, 512);
float *ImgSrc_f[512];
for (int i=0; i<512; i++)
ImgSrc_f[i] = (float *)malloc(512 * sizeof(float));
for(int i=0;i<512;i++)
for(int j=0;j<512;j++)
{
ImgSrc_f[i][j]=ImgSrc.at<float>(i,j);
}
//copy from host memory to device
cudaMemcpy2DToArray(Src, 0, 0,ImgSrc_f,512 * sizeof(float),512 *sizeof(float), 512,cudaMemcpyHostToDevice);
Run Code Online (Sandbox Code Playgroud)
但我得到了这个例外:
Access violation reading location 0x0000000000281000
Run Code Online (Sandbox Code Playgroud)