When using CUDA 12.6, what is best way to perform gaussian blur in python?

I understand there are at least 2 ways to do this:

  1. Using vpi module
  2. Using CV2

I’ve tried both,
1.

(python_env_01) nano@nano:~/Documents/yolo_stuff$ python3
Python 3.10.12 (main, Aug 15 2025, 14:32:43) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import vpi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'vpi'
>>> 
[1]+  Stopped                 python3
(python_env_01) nano@nano:~/Documents/yolo_stuff$
nano@nano:~$ python3
Python 3.10.12 (main, Aug 15 2025, 14:32:43) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import vpi
>>>

‘find /usr/lib/python3 -name vpi.so 2>/dev/null’ yields nothing

I want the python environment to remain closed from the system installed stuff to avoid conflicts, but to allow module vpi if possible?

Python code snippet:

   # 1. Create a GpuMat object and upload the CPU frame to the GPU
    # GpuMat objects hold data in GPU memory
    gpu_frame = cv2.cuda.GpuMat()
    gpu_frame.upload(frame)

    # 1. **FIXED:** Define the correct base type integer (depth)
    # DIAGNOSTIC RESULT: Input was 'uint8' (Depth 0), which corresponds to cv2.CV_8U.
    GPU_DEPTH_TYPE_INT = cv2.CV_8U 

    # 2. Apply the Gaussian Blur using the CUDA module
    # We must use the createGaussianFilter factory function and the .apply() method.
    
    # Create the reusable Gaussian filter object
    # Arguments: 1. srcType, 2. ksize, 3. sigmaX, 4. sigmaY, 5. dstType
    cuda_filter = cv2.cuda.createGaussianFilter(
        GPU_DEPTH_TYPE_INT,         # 1. srcType (Using cv2.CV_8U)
        (31, 31),                   # 2. ksize
        0,                          # 3. sigmaX
        0,                          # 4. sigmaY 
        GPU_DEPTH_TYPE_INT          # 5. dstType (Using cv2.CV_8U)
    )

    # Apply the filter to the GPU frame
    gpu_blurred_img = cuda_filter.apply(gpu_frame)
    
    # 3. Download the result back to a NumPy array in CPU memory
    blurred_img = gpu_blurred_img.download()

Result:


(python_env_01) nano@nano:~/Documents/yolo_stuff$ cd && python3 -m venv python_env_01 && source python_env_01/bin/activate && export LD_LIBRARY_PATH=/home/nano/python_env_01/lib/python3.10/site-packages/nvidia/cusparselt/lib:$LD_LIBRARY_PATH && cd && cd /home/nano/Documents/yolo_stuff && python3 test_yolo_on_video_file_onions_CUDA_17.py
CUDA is available for cv2.
Load a model ....
Starting object detection on video file: /media/nano/KIOXIA/Videos/best/my_webcam_recording_SAT_WE_271111_fixed_shortened.mp4
2025-10-02 15:54:31.984123028 [W:onnxruntime:Default, device_discovery.cc:164 DiscoverDevicesForPlatform] GPU device discovery failed: device_discovery.cc:89 ReadFileContents Failed to open file: "/sys/class/drm/card1/device/vendor"

[DEBUG] Input NumPy Frame Data Type (dtype): uint8
[DEBUG] GpuMat Depth (gpu_frame.depth()): 0
Traceback (most recent call last):
  File "/home/nano/Documents/yolo_stuff/test_yolo_on_video_file_onions_CUDA_17.py", line 323, in <module>
    frame_with_all_drawings, green_centers = process_frame_for_green_centers(
  File "/home/nano/Documents/yolo_stuff/test_yolo_on_video_file_onions_CUDA_17.py", line 172, in process_frame_for_green_centers
    cuda_filter = cv2.cuda.createGaussianFilter(
TypeError: Argument 'dstType' is required to be an integer

what is the correct code layout i should be using - are there any examples for cuda 12.6?

Please do not reply using LLM.
Thank you.

Hi,

It’s recommended to use VPI since we have optimized it for the Jetson device.
You can test a blurring sample with below steps:

$ /opt/nvidia/vpi3/bin/vpi_install_samples.sh .
$ cd NVIDIA_VPI-3.2-samples/tutorial_blur/
$ python3 main.py ../assets/kodim08.png 

The output tutorial_blurred_python.png can be found in the tutorial_blur folder.
The sample demonstrates with a box filter. Please refer to the link below to change it to Gaussian: (switch Language to ‘python’)

Thanks.