I’m trying to convert VPIImage from VPI_IMAGE_FORMAT_NV12 to VPI_IMAGE_FORMAT_BGRA8 using the following code:
int w, h;
// img is the source image with format VPI_IMAGE_FORMAT_NV12
CHECK_VPI_STATUS(vpiImageGetSize(img, &w, &h));
CHECK_VPI_STATUS(vpiImageCreate(w, h, VPI_IMAGE_FORMAT_BGRA8, 0, &output));
CHECK_VPI_STATUS(vpiSubmitConvertImageFormat(stream, VPI_BACKEND_VIC, img, output, &cvtParams));
According to documentation: VPI - Vision Programming Interface: Convert Image Format this conversion is supported in VIC backend given scale == 1 and offset == 0, which is my case. I’m getting the following error:
VPI_ERROR_INVALID_IMAGE_FORMAT: Input format's color range must be same as output's
NV12 and BGRA8 have different color ranges, but the operation is listed as supported. Am I missing something? How can I convert VPIImage form NV12 to any BGR/RGB format?
Some more details:
- hardware: AGX Xavier
- Jetpack 4.6
- VPI library version 1.1
Thanks for reporting it and we will check this. Another solution is to use NvBuffer APIs and you can call NvBufferTransform() for the conversion. It is also executed on VIC. And can map NvBuffer to VPIImage by calling the functions:
VPI - Vision Programming Interface: Main Page
Thanks for reporting this.
Confirmed that we can reproduce the same error in our environment as well.
We are checking this with our internal team and will get back to you later.
Just for your information.
The conversion from NV12_ER to BGRA8 with the VIC backend is working.
Maybe this can be the temporal workaround for you.
Indeed converting NV12 → NV12_ER and then to BGRA8 works on VIC backend. Looks like a workaround for now. Please let me know if direct conversion should be feasible in the future too or this is just a necessary step.
In a similar way NV12_ER can be converted to BGR8 using CUDA backend.
@DaneLLL I do not understand how
NvBufferTransform() can be used for such conversion. I see it can do copying, scaling, fliping etc but not image format conversion. Am I missing something?
If you create source NvBuffer in NV12 and destination NvBuffer in BGRA, it will do the format conversion in NvBufferTransform()
After checking this with our internal team, the document is incorrect.
Please use NV12_ER → BGRA8 instead.
May I know how do you create the VPI input mage?
If it’s wrapped with vpiImageCreateOpenCVMatWrapper, you can get an NV12_ER image by changing VPIImageFormat directly.
Thanks for your replies.
To clarify, I’m creating the VPIImage in the following way:
vpiImageCreateNvBufferWrapper(dmabuf_fd, ¶ms, 0, &img);
Finally I used
NvBufferTransform() method for converting to RGBA. It works fine now without spare conversions. Thanks!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.