My configuration is Jetson AGX Xavier running JetPack 4.5.1. VPI 1.0
I am seeing a green band of color at top of image (start of array) when using VPI to convert from RGB to NV12. This artifact is present whether I color-convert with VPI on CPU or with CUDA. This artifact is not present if I do color conversion on x86 CPU/GPU VPI. Could this be a power of two issue?
Please see pertinent code below and the artifact image attached.COLOR_YUV2RGB_NV12.bmp (5.9 MB)
Here is the code in question:
cv::Mat cvMatData(frame->getHeight(), frame->getWidth(), CV_8UC3, outDataPtr);
assert(cvMatData.type() == CV_8UC3);
#if !defined(_M_ARM) && !defined(__aarch64__)
_frameBGR = ToVPIImage(_frameBGR, cvMatData);
//convert to NV12 on CPU
CHECK_STATUS(vpiSubmitConvertImageFormat(_stream, VPI_BACKEND_CPU, _frameBGR, _output, NULL));
#else
cv::cuda::GpuMat cvGpuImage(cvMatData);
VPIImageData imgData;
memset(&imgData, 0, sizeof(imgData));
imgData.format = VPI_IMAGE_FORMAT_BGR8;
imgData.numPlanes = 1;
imgData.planes[0].width = cvGpuImage.cols;
imgData.planes[0].height = cvGpuImage.rows;
imgData.planes[0].pitchBytes = cvGpuImage.step;
imgData.planes[0].data = cvGpuImage.data;
CHECK_STATUS(vpiImageCreateCUDAMemWrapper(&imgData, VPI_BACKEND_CUDA, &_frameBGR));
//convert to NV12 on GPU
CHECK_STATUS(vpiSubmitConvertImageFormat(_stream, VPI_BACKEND_CUDA, _frameBGR, _output, NULL));
#endif
//block to finish conversion
CHECK_STATUS(vpiStreamSync(_stream));
// Lock output image to retrieve its data on cpu memory
VPIImageData outData;
CHECK_STATUS(vpiImageLock(_output, VPI_LOCK_READ, &outData));
assert(outData.format == VPI_IMAGE_FORMAT_NV12_ER);
cv::Mat cvOutData = cv::Mat(frame->getHeight() * 3/2, frame->getWidth(), CV_8UC1, outData.planes[0].data, outData.planes[0].pitchBytes);
// VPI data is aligned for perf and cv::Mat ends up non-continuous, memcpy fixes the problem
if (!cvOutData.isContinuous()){
cvOutData = cvOutData.clone();
}
// dump image
cv::Mat rgb;
cv::cvtColor(cvOutData,rgb,CV_YUV2RGB_NV12);
cv::imwrite(rgb);