Nvbuffer pitch issue

hi, Dane

we use jetson_multimedia_api’s sample12 to fulfil zero-copy function.

if the camera’s output is 2592x1944 uyvy422, the nvbuffer’s pitch is 5376, each line’s valid data is 2592x2, we can use below method to save picture. the picture is normal.

but if the camera’s output is 1280x720 uyvy422, the nvbuffer’s pitch is 2560, eash line’s valid data also 1280x2=2560. we use the same method to save picture, but the picture is abnormal, it shows a green screen.

if the pitch is 2560, i think the valid data can not be 2560, so how do we know each line’s valid data?

if (eglFrame.frameType == CU_EGL_FRAME_TYPE_PITCH)

{



    int bytesPerPix = 2; // UYVY



    size_t srcPitch = eglFrame.pitch;        // 5376

    size_t dstPitch = eglFrame.width \* bytesPerPix;   // 5184

    printf("liuting new Handle_EGLImage srcPitch:%ld, width:%d, height:%d\\n",srcPitch, eglFrame.width, eglFrame.height);

    // 分配 host buffer (紧凑行)

    std::vector<uint8_t> hostBuffer(dstPitch \* eglFrame.height);



    // CUDA 2D 拷贝:GPU带pitch -> host紧凑

    CUDA_MEMCPY2D copyParams = {0};

    copyParams.srcMemoryType = CU_MEMORYTYPE_DEVICE;

    copyParams.srcDevice     = (CUdeviceptr)eglFrame.frame.pPitch\[0\];

    copyParams.srcPitch      = eglFrame.width\*bytesPerPix;

    // copyParams.srcPitch      = srcPitch;

    copyParams.srcXInBytes   = 0;

    copyParams.srcY          = 0;



    copyParams.dstMemoryType = CU_MEMORYTYPE_HOST;

    copyParams.dstHost       = hostBuffer.data();

    copyParams.dstPitch      = dstPitch;

    copyParams.dstXInBytes   = 0;

    copyParams.dstY          = 0;



    copyParams.WidthInBytes  = dstPitch;

    copyParams.Height        = eglFrame.height;



    status = cuMemcpy2D(&copyParams);

    if (status != CUDA_SUCCESS)

    {

        printf("cuMemcpy2D failed: %d\\n", status);

        cuGraphicsUnregisterResource(pResource);

        return;

    }



    // OpenCV 转 BGR

    cv::Mat uyvy(eglFrame.height, eglFrame.width, CV_8UC2, hostBuffer.data());

    cv::Mat bgr;

    cv::cvtColor(uyvy, bgr, cv::COLOR_YUV2BGR_UYVY);



    // 保存图片

    cv::imwrite("frame_uyvy.png", bgr);

Hi,
Please run default 12 sample and see if the camera preview is good. Seems like the camera source does not generate good frame data in the resolution.

hi,

使用sample12+你的cudamapping的patch, 2592x1944分辨率的uyvy422的相机可以正常在egl上显示图像。

但是1280x720的uyvy422相机就会出现很多白点,并且彩色相机会显示成灰度的效果。

但是我通过v4l2-ctl命令试过,可以正常显示,相机应该没问题,感觉是nvbuffer的pitch问题。

v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=UYVY --stream-mmap --stream-count=1 --stream-to=output.uyvy -d /dev/video6
ffplay -f rawvideo -pixel_format uyvy422 -video_size 1280x720 output.uyvy

Hi,
It looks to be output of depth camera. Would suggest check if you configure the camera source correctly. For the resolution 1280x720, pitch is identical to width.

hi

我确认了一下,这个相机uyvy输出有问题,通过12sample保存一帧数据,显示出来,也是一个灰度图。

所以我让相机输出GREY,通过如下命令进行验证
./v4l2_camera_cuda -d /dev/video6 -s 1280x720 -f GREY -c -n 1
输出灰度图时,保存的一帧数据也是灰度图,可以正常显示。但是egl显示的还是有很多白点。如下图片所示。所以通过nvbuffer处理过后的数据还是有问题。
第一张图是原始的灰度图
第二张图是egl的显示效果

Hi,
Please run the command and check the camera preview:

$ gst-launch-1.0 v4l2src device= /dev/video6 ! video/x-raw,width=1280,height=720,format=GRAY8 ! videoconvert ! video/x-raw,format=I420 ! xvimagesink

And please try

./v4l2_camera_cuda -d /dev/video6 -s 1280x720 -f GREY -c -n 120

-n 1 saves the first frame which does not have good exposure time. Please check the later frame data.

The camera preview looks identical to the output of RealSense D435, so it still looks like the camera source generates this kind of output.

hi, Dane
确认一下,上面两条命令执行下来也是有白点的,我之前尝试的v4l2-ctl命令,保存一帧数据没问题,多帧数据也有同样的白点。那这个问题确实是相机导致的,请关闭topic吧,感谢感谢

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