About 04_video_dec_trt dec dma data difference with the opencv

hi all ,now i test the 04_video_dec_trt and when i dec the video data to dma_fd ,and then call the function convertEglFrameIntToFloat to convert int to float ,and call cudaMemcpy copy the cuda_buf to cpu and save a file ,but i also use the opencv function
convertTo(image, CV_32FC3, 1.0 , 0) and save the image.data,but i found that two data is totally different. so i want to know whether i can convert the image.data to the cuda_buf format data,thanks?

1 Like

Hi,
For mapping NvBuffer to cv::Mat, please refer to

You can get CPU buffer pointer by calling:

            NvBufferMemMap(m_compositedFrame, 0, NvBufferMem_Read, &pdata);
            NvBufferMemSyncForCpu(m_compositedFrame, 0, &pdata);

hi DaneLLL ,i have a question is that if we map the dma_fd to the opencv Mat ,but as i know that map cpu data is not a really frame data ,because if we want to get the frame data we have to do following data operation:
so why you say that data can be used by cv:mat

for ( plane = 0; plane < dest_param.num_planes; ++plane)
{
    ret = NvBufferMemMap (dest_dma_fd, plane, NvBufferMem_Read_Write, &virtualop_data_addr);
    if (ret == 0)
    {
        unsigned int i = 0;

        /* Syncs HW memory for reading from
        ** the buffer.
        */
        NvBufferMemSyncForCpu (dest_dma_fd, plane, &virtualop_data_addr);
        for (i = 0; i < dest_param.height[plane]; ++i)
        {
            streamsize bytes_to_write = dest_param.width[plane] * bytes_per_pixel_fmt[plane];

			memcpy(rawdata+ sumoffset,(unsigned char*)virtualop_data_addr + i * dest_param.pitch[plane],bytes_to_write);
			sumoffset += bytes_to_write;
        }

    }
    NvBufferMemUnMap (dest_dma_fd, plane, &virtualop_data_addr);
}

Hi,
If the NvBuffer is in NvBufferColorFormat_ABGR32, pitch linear, you can map it to

+            cv::Mat imgbuf = cv::Mat(STREAM_SIZE.height(),
+                                     STREAM_SIZE.width(),
+                                     CV_8UC4, pdata);

And OpenCV requires buffers in BGR, so need to do conversion:

+            cv::Mat display_img;
+            cvtColor(imgbuf, display_img, CV_RGBA2BGR);

yes ,i do you say that ,i try to fwite file
if call fwrite(display_img.data, 1, net_heightnet_width4,fp),that can get data file;but if i call
if call fwrite(imgbuf .data, 1, net_heightnet_width4,fp) ,that data file is null, so why

another question is that whether i can do some operation to convert the dma fd to cuda memory exception the function convertEglFrameIntToFloat

Hi,
For mapping dma fd to CUDA, you can refer to this sample: