我試過cudaMemcpy2DFromArray和cudaMemcpy2D,但都沒有正常工作。由於工作不正常,我的意思是GpuMat的確從cudaArray中複製了一些東西,但是水平尺度是錯誤的。如何將cudaArray(Cuda)複製到GpuMat(OpenCV)?
的代碼片段如下:
cudaArray *colorArr;
checkCudaErrors(cudaGraphicsMapResources(1, &cudaResourceColor, 0));
checkCudaErrors(cudaGraphicsSubResourceGetMappedArray(&colorArr, cudaResourceColor, 0, 0));
cv::gpu::GpuMat gpuColorMat(Size(w,h), CV_32FC3);
// Tried method 1: the following didn't work correctly
checkCudaErrors(cudaMemcpy2DFromArray(gpuColorMat.data, gpuColorMat.step, colorArr,
0, 0, gpuColorMat.cols*sizeof(float3), gpuColorMat.rows, cudaMemcpyDeviceToDevice));
// Tried method 2: also didn't work correctly. Same error as the first method.
float3 *cuarr;
checkCudaErrors(cudaMalloc((void**)&cuarr, w*h*sizeof(float3)));
checkCudaErrors(cudaMemcpy2DFromArray(cuarr, w*h, colorArr, 0, 0, w*sizeof(float3), h, cudaMemcpyDeviceToDevice));
checkCudaErrors(cudaMemcpy2D((float*)gpuColorMat.data, gpuColorMat.step, cuarr, w*sizeof(float3), w*sizeof(float3), h, cudaMemcpyDeviceToDevice));
// unmap buffer objects
checkCudaErrors(cudaGraphicsUnmapResources(1, &cudaResourceColor, 0));
誰能幫助我?
我想你的建議的方法。它也沒有工作。謝謝你們一樣! – Feng