How to save images after tracking plug-ins

Hardware: Jetson Xavier NX
Software: DeepStream-App (6.1)

How to save images after tracking plug-ins;
The current format is:
First case:1920-1080-1920-NVBUF_COLOR_FORMAT_NV12_709_ER
Second case:1920-1080-2048-NVBUF_COLOR_FORMAT_NV12

zm@ubuntu:~$ deepstream-app --version-all
deepstream-app version 6.1.0
DeepStreamSDK 6.1.0
CUDA Driver Version: 11.4
CUDA Runtime Version: 11.4
TensorRT Version: 8.4
cuDNN Version: 8.3
libNVWarp360 Version: 2.0.1d3

#if 1   //Jetson Plan A

        NvBufSurfaceMap(surface, -1, -1, NVBUF_MAP_READ_WRITE);
        // NvBufSurfaceSyncForCpu(surface, -1, -1);
        // NvBufSurfaceSyncForDevice(surface, -1, -1);
        memcpy(src_data, (char *)surface->surfaceList[frame_meta->batch_id].mappedAddr.addr[0], surface->surfaceList[frame_meta->batch_id].dataSize);
        // NvBufSurfaceSyncForCpu(surface, -1, -1);
        NvBufSurfaceUnMap(surface, -1, -1);
#else   //Jetson Plan B
        NvBufSurfaceMap(surface, -1, -1, NVBUF_MAP_READ);
        // NvBufSurfaceSyncForCpu(surface, frame_meta->batch_id, -1);
        //  NvBufSurfaceSyncForDevice (surface, -1, -1);
        NvBufSurfacePlaneParams *pParams = &surface->surfaceList[frame_meta->batch_id].planeParams;
        unsigned int offset = 0;
        for (unsigned int num_planes = 0; num_planes < pParams->num_planes; num_planes++)
        {
            if (num_planes > 0)
                offset += pParams->height[num_planes - 1] * (pParams->bytesPerPix[num_planes - 1] * pParams->width[num_planes - 1]);
            for (unsigned int h = 0; h < pParams->height[num_planes]; h++)
            {
                memcpy((void *)(src_data + offset + h * pParams->bytesPerPix[num_planes] * pParams->width[num_planes]),
                       (void *)((char *)surface->surfaceList[frame_meta->batch_id].mappedAddr.addr[num_planes] + h * pParams->pitch[num_planes]),
                       pParams->bytesPerPix[num_planes] * pParams->width[num_planes]);
            }
            g_print("LINE:%d Size:%d-%d\n", __LINE__, pParams->bytesPerPix[num_planes] * pParams->width[num_planes], pParams->height[num_planes]);
        }
        NvBufSurfaceSyncForDevice(surface, -1, -1);
        // NvBufSurfaceSyncForCpu(surface, -1, -1);
        NvBufSurfaceUnMap(surface, -1, -1);
#endif
#else   //dGPU Plan C
        cudaMemcpy((void *)src_data,
                   (void *)surface->surfaceList[frame_meta->batch_id].dataPtr,
                   surface->surfaceList[frame_meta->batch_id].dataSize,
                   cudaMemcpyDeviceToHost);
#endif

I couldn’t get a valid image with any of the above combinations.
I can obtain the following pictures through plan A:



please refer to these two samples: Help,dump image from nvv4l2decoder problem
Deepstream sample code snippet

I updated the problem, please help to check again

The current format is:
First case:1920-1080-1920-NVBUF_COLOR_FORMAT_NV12_709_ER
Second case:1920-1080-2048-NVBUF_COLOR_FORMAT_NV12

        cv::Mat img;
        cv::Mat src_mat(frame_height * 3 / 2, frame_width, CV_8UC1, (void *)src_data, frame_step);
        cv::cvtColor(src_mat, img, COLOR_YUV2BGR_NV12);
        cv::imwrite(file_name, img);

There is no update from you for a period, assuming this is not an issue anymore.
Hence we are closing this topic. If need further support, please open a new one.
Thanks

Please refer to How to convert NV12_709/NV12_709_ER frame to cv::MAT on Jetson NX?
these formats are not supported by opencv, you can use convert these to rgb by nvconvert, please refer to Dump jpeg in deepstream5.0.

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