opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.41k stars 5.76k forks source link

Segmentation fault with cuda_DisparityBilateralFilter #3245

Closed mminervini closed 2 years ago

mminervini commented 2 years ago
System information

Tried on:

And also:

Detailed description

In Python, using member function apply() of cv2.cuda_DisparityBilateralFilter causes segmentation fault. On the same systems, using in C++ cuda::createDisparityBilateralFilter() and apply() works as expected.

Steps to reproduce
import numpy as np
import cv2

np_disparity = np.random.randint(0, 64, (128, 128), dtype=np.int16)
np_image = np.random.randint(0, 255, (128, 128, 3), dtype=np.uint8)
cu_disparity = cv2.cuda_GpuMat(np_disparity)
cu_image = cv2.cuda_GpuMat(np_image)

disparity_bilateral_filter = cv2.cuda_DisparityBilateralFilter()
cu_filtered_disparity = disparity_bilateral_filter.apply(cu_disparity, cu_image)
# Segmentation fault (core dumped)
Issue submission checklist
asmorkalov commented 2 years ago

C++ DisparityBilateralFilter is inherited from cv::Algorithm and is created by factory method cv::cuda::createDisparityBilateralFilter. For Python case you need to call the same factory to create properly initialized object with call cv.cuda.createDisparityBilateralFilter.

The working code:

import numpy as np
import cv2

np_disparity = np.random.randint(0, 64, (128, 128), dtype=np.int16)
np_image = np.random.randint(0, 255, (128, 128, 3), dtype=np.uint8)
cu_disparity = cv2.cuda_GpuMat(np_disparity)
cu_image = cv2.cuda_GpuMat(np_image)

disparity_bilateral_filter = cv2.cuda.createDisparityBilateralFilter()
cu_filtered_disparity = disparity_bilateral_filter.apply(cu_disparity, cu_image)
mminervini commented 2 years ago

Thank you for clarifying. I found the cv2.cuda_DisparityBilateralFilter class and didn't realize I had to create an instance through a factory function rather than using the class constructor itself.