Jetson Linux API Reference

32.7.1 Release
12_camera_v4l2_cuda (camera capture CUDA processing)


This sample demonstrates how to capture images from a V4L2 YUV type of camera and share the image stream with NVIDIA® CUDA® engines to draw a black box on the upper left corner.

Building and Running


  • You have followed Steps 1-3 in Building and Running.
  • If you are building from your host Linux PC (x86), you have followed Step 4 in Building and Running.
  • You have the following hardware:
    • V4L2 Camera (USB or YUV Camera with the format YUYV/YVYU/UYVY/VYUY)
    • Display

To build:

  • Enter:
      $ cd 12_camera_v4l2_cuda
      $ make

To run

  • Enter:

      $ ./camera_v4l2_cuda -d /dev/video0 -s 1280x720 -f YUYV -c

    The -c option enables CUDA processing.

  • Or enter:

      $ ./camera_v4l2_cuda -d /dev/video0 -s 640x480 -f YUYV -n 30 -c

    The -n option saves the n-th frame before video converter processing.

To view supported options

  • Use the -h option.


The following diagram shows the flow of data through this sample.

Block Diagram

Block Diagram

Key Structure and Functions

The sample defines the structure and functions listed in the following tables.

Structure Description
context_t Global structure to save the context for V4L2 camera, CUDA and EglRenderer.

Function Description
init_components Initializes V4L2 camera and EglRenderer.
prepare_buffers Allocates buffers for the capture_plane. Then, it shares the buffers with V4L2 Camera, CUDA, and EglRenderer.
start_stream Starts V4L2 camera streaming.
start_capture Main thread to enqueue and dequeue buffers.
stop_stream Stops V4L2 camera streaming.