How to get bayer raw16 in a EGLframe?

test2.tif (15.3 MB)

Hello,
I modified the sample code and got the attached image.

sample code: jetson_multimedia_api/argus/samples/cudaBayerDemosaic/CudaBayerDemosaicConsumer.cpp

//------------------------------------------------------------------
// Run the CUDA kernel to demosaic the Bayer input into the RGBA output.
cudaBayerDemosaic((CUdeviceptr)(bayerEglFrame.frame.pPitch[0]),
bayerEglFrame.width,
bayerEglFrame.height,
bayerEglFrame.pitch,
bayerEglFrame.eglColorFormat,
(CUdeviceptr)(rgbaEglFrame.frame.pPitch[0]));

    if (CUDA_SUCCESS != cuMemcpyDtoH(testMem, (CUdeviceptr)(bayerEglFrame.frame.pPitch[0]), 3264*2464*2))
        printf("error: fail cuMemcpyDtoH\n");
    
    if (frame == 100) {
        printf("w=%d h=%d, p=%d\n", bayerEglFrame.width, bayerEglFrame.height, bayerEglFrame.pitch);
        FILE *fp;
        fp = fopen("test.raw","w");
        fwrite(testMem, 2, 3264*2464, fp);
        fclose(fp);
    }

    // Return the Bayer frame to the Argus stream.
    cuResult = cuEGLStreamConsumerReleaseFrame(
            &m_cudaBayerStreamConnection, bayerResource, NULL);
    if (cuResult != CUDA_SUCCESS)
    {
        ORIGINATE_ERROR("Unable to release frame to EGLStream (CUresult %s).",
            getCudaErrorString(cuResult));
    }

//----------------------------------------------

Attached image is broken image.

I already knew that how to get bayer in no-bypass mode(v4l2src).
But I need bypass mode as this case.
Thanks.

Does the output from cudaBayerDemosaic normally?
Can you try memcpy instead of cuMemcpyDtoH also confirm the size is 3264*2464

Yes, cudaBayerDemosic’s display is correctly rendered.

I tried Memcpy instead of cuMemcpyDtoH. It occurred crash. (below)

[Memcpy]

nano@nano-desktop:~/work/jetson_multimedia_api/argus/build/samples/cudaBayerDemosaic$ export DISPLAY=:0
nano@nano-desktop:~/work/jetson_multimedia_api/argus/build/samples/cudaBayerDemosaic$ ./argus_cudabayerdemosaic
Executing Argus Sample: argus_cudabayerdemosaic
Executing Argus Sample: argus_cudabayerdemosaic
Argus Version: 0.97.3 (multi-process)
Initializing CUDA
CUDA CONSUMER:    Input frame format:
CUeglFrame:
 width: 3264
 height: 2464
 depth: 0
 pitch: 6656
 planeCount: 1
 numChannels: 1
 frameType: pitch
 colorFormat: S16 Bayer RGGB
 cuFormat: int16
CUDA PRODUCER:    Output frame format:
CUeglFrame:
 width: 1632
 height: 1232
 depth: 1
 pitch: 6528
 planeCount: 1
 numChannels: 4
 frameType: pitch
 colorFormat: ARGB
 cuFormat: uint8
Segmentation fault (core dumped)

[ cuMemcpyDtoH ]

nano@nano-desktop:~/work/jetson_multimedia_api/argus/build/samples/cudaBayerDemosaic$ DISPLAY=:0 ./argus_cudabayerdemosaic -f 200
Executing Argus Sample: argus_cudabayerdemosaic
Executing Argus Sample: argus_cudabayerdemosaic
Argus Version: 0.97.3 (multi-process)
Initializing CUDA
CUDA CONSUMER:    Input frame format:
CUeglFrame:
 width: 3264
 height: 2464
 depth: 0
 pitch: 6656
 planeCount: 1
 numChannels: 1
 frameType: pitch
 colorFormat: S16 Bayer RGGB
 cuFormat: int16
CUDA PRODUCER:    Output frame format:
CUeglFrame:
 width: 1632
 height: 1232
 depth: 1
 pitch: 6528
 planeCount: 1
 numChannels: 4
 frameType: pitch
 colorFormat: ARGB
 cuFormat: uint8
fps:0.000000
fps:7.200000
fps:11.340000
fps:14.538000
fps:16.776600
w=3264 h=2464, p=6656
fps:18.343620
fps:19.440534
fps:20.208374
fps:20.445862
fps:20.912103
CUDA CONSUMER:    No more frames. Cleaning up
CUDA CONSUMER:    Done
Argus sample 'argus_cudabayerdemosaic' completed successfully.

And camera output size is 3264x2464.

nano@nano-desktop:~/work/jetson_multimedia_api/argus/build/samples/cudaBayerDemosaic$ v4l2-ctl --all -d /dev/video0
Driver Info (not using libv4l2):
        Driver name   : tegra-video
        Card type     : vi-output, imx219 7-0010
        Bus info      : platform:54080000.vi:0
        Driver version: 4.9.201
        Capabilities  : 0x84200001
                Video Capture
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps   : 0x04200001
                Video Capture
                Streaming
                Extended Pix Format
Priority: 2
Video input : 0 (Camera 0: no power)
Format Video Capture:
        Width/Height      : 3264/2464
        Pixel Format      : 'RG10'
        Field             : None
        Bytes per Line    : 6528
        Size Image        : 16084992
        Colorspace        : sRGB
        Transfer Function : Default (maps to sRGB)
        YCbCr/HSV Encoding: Default (maps to ITU-R 601)
        Quantization      : Default (maps to Full Range)
        Flags             :

Do you have any idea?

The pitch is 6528 so when you read the raw file need configure the resolution as 3328*2464 instead of 3264

1 Like

You are right!
The issue has been resolved.

Thank you : )