This sample uses V4L2 image capturing with NVIDIA® CUDA® format conversion.
$ cd 18_v4l2_camera_cuda_rgb $ make
Enter
make clean
$ ./v4l2_camera_cuda_rgb [options]
$ ./v4l2_camera_cuda_rgb --help
This is the overall process flow of v4l2_camera_cuda_rgb:
V4L2 CUDA USB camera ------> captured image (YUYV) ------> converted image (RGB)
As shown in the following diagrams, the buffer flow differs depending on V4L2 capturing modes and CUDA memory management.
V4L2 memory-mapped buffers (V4L2_MEMORY_MMAP) are allocated in kernel space. The application maps them in user space and copies them to the CUDA device allocated memory for CUDA processing.
The application allocates V4L2 user-space buffers (V4L2_MEMORY_USERPTR). In this situation, the driver directly fills in the user-space memory. When you allocate CUDA-mappable memory (with cudaHostAlloc
), the CUDA device can access the V4L2 captured buffer without memory copy.
$ ./v4l2_camera_cuda_rgb -d /dev/video0 -m _ _ _ _ | | mmap copy | | convert | | copy | | write |_| ------> ptr ------> |_| =========> |_| ------> |_| -------> file | kernel | user
$ ./v4l2_camera_cuda_rgb -d /dev/video0 -m -z _ _ _ | | mmap copy | | convert | | write |_| ------> ptr ------> |_| =========> |_| -------> file | kernel | user
$ ./v4l2_camera_cuda_rgb -d /dev/video0 -u _ _ _ _ userptr | | copy | | convert | | copy | | write ---------> |_| ------> |_| =========> |_| ------> |_| -------> file | kernel | user
$ ./v4l2_camera_cuda_rgb -d /dev/video0 -u -z _ _ userptr | | convert | | write ---------> |_| =========> |_| -------> file | kernel | user