我使用nppiBGRToYCbCr420_8u_C3P3R
将RGB图像转换为YUV420。像这样的函数参数:
nppiBGRToYCbCr420_8u_C3P3R(const Npp8u pSrc, int nSrcStep, Npp8u pDst[3], int rDstStep[3], NppiSize oSizeROI)
我想将d_array[0]
复制到host_array
以显示Y频道图像并进行检查,但我发现nppiBGRToYCbCr420_8u_C3P3R
返回错误NPP_STEP_ERROR“(音高为921600 BGR.step为4096) (在opencv中,图像步长是2的N次方))。所以我希望有人可以帮助我。
答案 0 :(得分:2)
这里有两个主要问题:
nppiBGRToYCbCr420_8u_C3P3R
将具有交错BGR像素值的BGR图像转换为一个Y图像,一个Cb图像和一个Cr图像。即图像以三个分开的平面输出,因此P在“C3P3”中。使用nppiMalloc_8u_C1来分配设备输出图像会给出类似的结果(省略错误检查以简化并在浏览器中写入而不检查):
Mat temp = imread("1.jpg",1);
Npp8u *d_arrayY, *d_arrayCB, *d_arrayCR;
GpuMat BGR(temp);
unsigned char *host_array = (unsigned char*)malloc(temp.cols * temp.rows * sizeof(unsigned char ));
memset(host_array,0,temp.cols * temp.rows * sizeof(unsigned char));
size_t pitchY, pitchCB, pitchCR ;
d_arrayY = nppiMalloc_8u_C1(temp.cols, temp.rows, &pitchY);
d_arrayCB = nppiMalloc_8u_C1(temp.cols/2, temp.rows/2, &pitchCB);
d_arrayCR = nppiMalloc_8u_C1(temp.cols/2, temp.rows/2, &pitchCR);
int Dstep[3] = {pitchY,pitchCB,pitchCR};
Npp8u* d_ptrs[3] = {d_arrayY, d_arrayCB, d_arrayCR};
NppiSize ds;
ds.height = temp.rows;
ds.width = temp.cols;
nppiBGRToYCbCr420_8u_C3P3R(BGR.ptr<Npp8u>(), BGR.step, d_ptrs, Dstep, ds);
cudaMemcpy2D(host_array, temp.cols, d_arrayY, pitchY, temp.cols * sizeof(Npp8u), temp.rows, cudaMemcpyDeviceToHost);