Green Images are saved in deepstream-5.1

**• Hardware Platform (Jetson NX) **
**• DeepStream Version (5.1) **
• JetPack Version (4.5.1)
• TensorRT Version (7.1.3)

Hello, Sir/Madam
I am using the deepstream-test5 with ip cam(1920x1080p) in my job now.
I have search around the forum for green image issues, and found this solution. However, I replace two files (deepstream_primary_gie_bin.c and deepstream_primary_gie.h), the problem is not solved.

When I set [streammux] with low resolution, I got the correct result. I have same problem like this.

My question is that how can I get correct frame from pipeline. Where can I find the code from deepstream which cause this problem.

this is my sample code where I got frame from pipeline:

cv::Mat enc_object(GstBuffer * buf, guint stream_id)
{
    NvBufSurface *ip_surf = NULL;
    char* src_data = NULL;
    GstMapInfo inmap = GST_MAP_INFO_INIT;
    if (!gst_buffer_map (buf, &inmap, GST_MAP_READ)) {
            g_print ("Error: Failed to map gst buffer\n");
            gst_buffer_unmap (buf, &inmap);
            return "error";
    }
    ip_surf = (NvBufSurface *) inmap.data;

    src_data = (char*) malloc(ip_surf->surfaceList[stream_id].dataSize);
    if(src_data == NULL) g_print("Error: failed to malloc src_data \n");

#ifdef PLATFORM_TEGRA
    NvBufSurfaceMap (ip_surf, -1, -1, NVBUF_MAP_READ);
    NvBufSurfacePlaneParams *pParams = &ip_surf->surfaceList[stream_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 *)ip_surf->surfaceList[stream_id].mappedAddr.addr[num_planes]+h*pParams->pitch[num_planes]),
                pParams->bytesPerPix[num_planes]*pParams->width[num_planes]
                );
        }
    }
    NvBufSurfaceSyncForDevice (ip_surf, -1, -1);
    NvBufSurfaceUnMap (ip_surf, -1, -1);
#else
    cudaMemcpy((void*)src_data,
                (void*)ip_surf->surfaceList[stream_id].dataPtr,
                ip_surf->surfaceList[stream_id].dataSize,
                cudaMemcpyDeviceToHost);
#endif

    gint frame_width = (gint)ip_surf->surfaceList[stream_id].width;
    gint frame_height = (gint)ip_surf->surfaceList[stream_id].height;
    gint frame_step = ip_surf->surfaceList[stream_id].pitch;

    cv::Mat picYV12 = cv::Mat(frame_height * 3/2, frame_width, CV_8UC1, src_data, frame_step);
    cv::Mat picBGR = cv::Mat (cv::Size(frame_width, frame_height), CV_8UC3);
    cv::cvtColor(picYV12, picBGR, CV_YUV2BGR_NV12);

    if(src_data != NULL) {
         free(src_data);
         src_data = NULL;
     }
    gst_buffer_unmap (buf, &inmap);
    return picBGR;
}

Thank you very much.

Please refer to the sample of deepstream-image-meta-test
https://docs.nvidia.com/metropolis/deepstream/dev-guide/text/DS_C_Sample_Apps.html

Hi,
The deepstream-image-meta-test can save the image in jpeg format successfully, but I want to encode the image to base64.
The sample code below can get the low resolution image data.

I want to save the image in 1080p. How can I solve such a problem?

Do you mean you want to scale the picture before encode it into jpeg? The NvDsBufSurfTransform API — Deepstream Deepstream Version: 5.1 documentation API can help you to scale the pictures with GPU.

What do you mean by “low resolution”? How can we reproduce your problem? Can you provide the complete code?

I write this function

called in bbox_generated_probe_after_analytics in deepstream-test5. Low resolution means when I set [streammux] with 720p, I can get the correct result. When I set [streammux] with 1080p, I get the green image like this

This is the main.cpp which revised from deepstream_test5_app_main.c
main.cpp (52.2 KB)

I ran both at x86 and Jetson wiith the same video file, and I got wrong result of base64 when I set [streammux] with 1080p in Jetson.
test_x86_1080p.txt (92.5 KB)
test_Jetson_1080p.txt (387.2 KB)

It is no problem when I set [streammux] with 720p.
test_x86_720p.txt (52.4 KB)
test_Jetson_720p.txt (51.6 KB)