How to convert cv::Mat to NvBufSurface without memcpy

Hi,
jetpack: 5.1.2
I read some topics about cv::Mat to NvBufSurface, but all of those need memcpy which is unacceptable for me. Because I don’t want any cpu cost in this process.
So my question is: 1. If it possible convert cv::Mat to NvBufSurface without memcpy?
2. Does NvBufSurface2Raw use memcpy or some cpu copy method actually?
Thanks!
BR/Tim

Hi,

1. Please check below for a comment:

2. Based on the description, it should include a copy step.
https://docs.nvidia.com/jetson/archives/r35.2.1/ApiReference/group__ds__aaa.html#ga001206f7623c36d0dadbdc39906162c7

Thanks.

Hi AastaLLL
This comment’s answer actually is about NvBufSurface to Mat.
So it seems no way to optimise those memcpy in jetpack, right?
BR/Tim

Hi,
You are correct that converting cv::Mat to NvBufSurface requires memory copy. It is not required if you allocate NvBufSurface first, and then map to cv::Mat.

NvBufSurface2Raw() uses the function similar to memcpy() to copy data from NvBufSurface to a CPU buffer.

Hi DaneLLL,
Thanks for your reply!
I tried NvBufSurface2Raw, and it seems had better cpu loading performance than memcpy. Is it use DMA?
Thanks!
BR/Tim

Hi,
It is done with private function and may have better or identical performance when comparing to memcpy().

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.