Hello. I have an image in the NvBufSurface, the image is ok. I am trying to build an VPIImage object pointing to this memory in order to make a prerpocessing before the input to AI model.
The image in the NvBufSurface is absolutely ok, because I can do this with the OpenCV library. But it doesn’t work with the VPI library.
The code looks like:
NvBufSurface *surface{};
surface = reinterpret_cast<NvBufSurface *>(map.data); // data was in map.data
// build VPI Image
VPIImage img_vpi = NULL;
VPIImageData img_data = {};
NvBufSurfaceMapParams buffer_params;
int result = NvBufSurfaceGetMapParams(surface, 0, &buffer_params);
assert(result == 0); // it is OK here
assert(buffer_params.fd != 0); // it is OK here
err_vpi = vpiImageCreateWrapper(&img_data, nullptr, imgFlags, &img_vpi);
assert(err_vpi == VPI_SUCCESS); // it is OK here
std::cout << "img_data.bufferType = " << img_data.bufferType << std::endl; // here output is “5”, what means "VPI_IMAGE_BUFFER_NVBUFFER "
// check some parameters
err_vpi = vpiImageGetSize(img_vpi, &width, &height);
assert(err_vpi == VPI_SUCCESS); // it is OK here
std::cout << "width = " << width << ", height = " << height << std::endl; // ouputs correct values
VPIImageFormat img_fmt;
err_vpi = vpiImageGetFormat(img_vpi, &img_fmt);
assert(err_vpi == VPI_SUCCESS); // it is OK here
std::cout << vpiImageFormatGetDataType(img_fmt) << std::endl; // outputs “1”, what means unsigned int
std::cout << vpiImageFormatGetColorModel(img_fmt) << std::endl; // outputs “2”, RGB
std::cout << vpiImageFormatGetPlaneCount(img_fmt) << std::endl; // outputs “1”
std::cout << vpiImageFormatGetChannelCount(img_fmt) << std::endl; // outputs “4”
// Now I try to access data in the image
VPIImageData outData;
err_vpi = vpiImageLockData(img_vpi, VPI_LOCK_READ, VPI_IMAGE_BUFFER_CUDA_PITCH_LINEAR, &outData);
std::cout << "outData.bufferType = " << outData.bufferType << std::endl; // outputs “2” what is VPI_IMAGE_BUFFER_CUDA_PITCH_LINEAR; but it must be: VPI_IMAGE_BUFFER_NVBUFFER !
assert(err_vpi == VPI_SUCCESS); // No error here
assert(outData.bufferType == VPI_IMAGE_BUFFER_CUDA_PITCH_LINEAR); // No error here, but why is it CUDA_PITCH_LINEAR?
// try to make an output with OpenCV
cv::Mat forOutput;
err_vpi = vpiImageDataExportOpenCVMat(outData, &forOutput);
std::cout << "vpiImageDataExportOpenCVMat status: " << vpiStatusGetName(err_vpi) << std::endl; // VPI_ERROR_INVALID_ARGUMENT
assert(err_vpi == VPI_SUCCESS); // error here
If I do not try to convert to OpenCV and try to use image in the preprocessing function, it is simply empty.
Could you please tell me what I am doing wrong? And why is the buffer type converted to CUDA_PITCH_LINEAR if I explicitly used VPI_IMAGE_BUFFER_NVBUFFER?
Thank you, but that thread on the forum that you provided is my thread ))) There I thought that it was working because the VPI Status was “VPI_SUCCESS”. However, the image is empty. That is why the problem according the provided link was not solved indeed.
Hello, the code is here. I read images from gstreamer pipeline to NvBufSurface. And then try to build VPIImage and make some operations with it. But it doesn’t work.
But when I use EGL frames and OpenCV then it is ok.
Thanks for your patience.
We have checked your source and below is what we got from your sample.
$ ./main
(gst-plugin-scanner:58349): GStreamer-WARNING **: 07:04:14.788: Failed to load plugin '/home/nvidia/topic_2273570/opencv/workspace/opencv-4.6.0/release/lib/python3/cv2.cpython-38-aarch64-linux-gnu.so': /home/nvidia/topic_2273570/opencv/workspace/opencv-4.6.0/release/lib/python3/cv2.cpython-38-aarch64-linux-gnu.so: undefined symbol: PyBool_Type
(gst-plugin-scanner:58349): GStreamer-WARNING **: 07:04:14.909: Failed to load plugin '/home/nvidia/topic_2273570/opencv/workspace/opencv-4.6.0/release/lib/cv2.so': /home/nvidia/topic_2273570/opencv/workspace/opencv-4.6.0/release/lib/cv2.so: undefined symbol: PyBool_Type
Nvidia Video Converter (nvvidconv) plugin is installed. [Platform = TEGRA]
got input:
img_data.bufferType = 5
width = 1280, height = 720
Before preprocessing data type = 1
Before preprocessing Color Model = 1
Before preprocessing Plane Count = 2
Before preprocessing Channel Count = 3
outData.bufferType = 2
Status in main, wrapper around received image: VPI_SUCCESS
vpiImageCreateWrapper status: VPI_SUCCESS
Crop status: VPI_ERROR_INVALID_OPERATION
main: main.cpp:172: GstFlowReturn on_new_sample_from_sink(GstElement*, void*): Assertion `err_vpi == VPI_SUCCESS' failed.
Aborted (core dumped)
Based on the log, the vpiImageCreateWrapper can work correctly.
The failure comes from vpiImageCreateView which should work with VPI internal buffer rather than the user-preallocated buffer.