Drop-in replacement for ``cv2.GaussianBlur`` with CUDA acceleration. Parameters match ``cv2.GaussianBlur(src, ksize, sigmaX, sigmaY)``. When *ksize* is ``(0, 0)`` OpenCV computes the kernel size from *sigma_x*.
(
src: np.ndarray,
ksize: Tuple[int, int],
sigma_x: float,
sigma_y: float = 0,
)
| 84 | # --------------------------------------------------------------------------- |
| 85 | |
| 86 | def gpu_gaussian_blur( |
| 87 | src: np.ndarray, |
| 88 | ksize: Tuple[int, int], |
| 89 | sigma_x: float, |
| 90 | sigma_y: float = 0, |
| 91 | ) -> np.ndarray: |
| 92 | """Drop-in replacement for ``cv2.GaussianBlur`` with CUDA acceleration. |
| 93 | |
| 94 | Parameters match ``cv2.GaussianBlur(src, ksize, sigmaX, sigmaY)``. |
| 95 | When *ksize* is ``(0, 0)`` OpenCV computes the kernel size from *sigma_x*. |
| 96 | """ |
| 97 | if CUDA_AVAILABLE: |
| 98 | try: |
| 99 | src_u8 = _ensure_uint8(src) |
| 100 | cv_type = _cv_type_for(src_u8) |
| 101 | ks = _ksize_odd(ksize) if ksize != (0, 0) else ksize |
| 102 | |
| 103 | gauss = cv2.cuda.createGaussianFilter(cv_type, cv_type, ks, sigma_x, sigma_y) |
| 104 | gpu_src = cv2.cuda.GpuMat() |
| 105 | gpu_src.upload(src_u8) |
| 106 | gpu_dst = gauss.apply(gpu_src) |
| 107 | return gpu_dst.download() |
| 108 | except cv2.error: |
| 109 | pass |
| 110 | |
| 111 | return cv2.GaussianBlur(src, ksize, sigma_x, sigmaY=sigma_y) |
| 112 | |
| 113 | |
| 114 | # --------------------------------------------------------------------------- |
no test coverage detected