cv2.cuda.HoughLineDetector() return Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

I am detecting lines in image with opencv, but on more than thousand images it’s very slow. So i installed cv2.cuda with GPU enabled from source on a conda env. I downloaded opencv ‘4.8.0-dev’ .

The line :
cv2.cuda.getCudaEnabledDeviceCount()
return me 1 , so it has detected the GPU

But i’ve got some issue with the function HoughLines. With cv2 without gpu the function run perfectly but when i try the cv2.cuda.HoughLinesDetector() i’ ve got an error:

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

Here my code:

import cv2
import numpy as np

print(cv2.cuda.getCudaEnabledDeviceCount())
img = cv2.imread('/home/reda/Documents/Dataset/france_croatie_cut/frame_155.jpg')

cv2.cuda.setDevice(0)  # Use the first GPU (change the device index if needed)
img_gpu = cv2.cuda_GpuMat()
img_gpu.upload(img)

# Convert the image to grayscale on the GPU
img_gray_gpu = cv2.cuda.cvtColor(img_gpu, cv2.COLOR_BGR2GRAY)

# Perform Hough Line Transform on the GPU
Hough_detector = cv2.cuda.HoughLinesDetector(rho=1, theta=np.pi / 180, threshold=170
                                             , minLineLength=90, maxLineGap=3)
# Download the detected lines from the GPU to the CPU
lines = Hough_detector.detect(img_gray_gpu, lines_gpu) # THE ERROR APPEAR AT THIS LINE

It seems that on c++ this function works but all documentation that i could found on cv2.cuda was only for c++ , there is no doc for python. Can anyone help me with this. Thanks a lot

It looks like your problem is that you are not using the createHoughLinesDetector method to create Hough_detector. You should be doing

# Perform Hough Line Transform on the GPU
Hough_detector = cv2.cuda.createHoughLinesDetector(rho=1, theta=np.pi / 180, threshold=170 , minLineLength=90, maxLineGap=3)

As the python docs are missing unless you build with doxygen, the best approach (which isn’t fool proof) is to follow the C++ docs to find out the functions you want to call and then use help in python to get the correct order for the arguments, e.g.

help(cv2.cuda.cvtColor)

Help on built-in function cvtColor:

cvtColor(…)
cvtColor(src, code[, dst[, dcn[, stream]]]) → dst
. @brief Converts an image from one color space to another.
.
. @param src Source image with CV_8U , CV_16U , or CV_32F depth and 1, 3, or 4 channels.
. @param dst Destination image.
. @param code Color space conversion code. For details, see cvtColor .
. @param dcn Number of channels in the destination image. If the parameter is 0, the number of the
. channels is derived automatically from src and the code .
. @param stream Stream for the asynchronous version.
.
. 3-channel color spaces (like HSV, XYZ, and so on) can be stored in a 4-channel image for better
. performance.
.
. @sa cvtColor

help(cv2.cuda.createHoughLinesDetector)

Help on built-in function createHoughLinesDetector:

createHoughLinesDetector(…)
createHoughLinesDetector(rho, theta, threshold[, doSort[, maxLines]]) → retval
. @brief Creates implementation for cuda::HoughLinesDetector .
.
. @param rho Distance resolution of the accumulator in pixels.
. @param theta Angle resolution of the accumulator in radians.
. @param threshold Accumulator threshold parameter. Only those lines are returned that get enough
. votes ( \f$>\texttt{threshold}\f$ ).
. @param doSort Performs lines sort by votes.
. @param maxLines Maximum number of output lines.

help(cv2.cuda.HoughLinesDetector.detect)

Help on method_descriptor:

detect(…)
detect(src[, lines[, stream]]) → lines
. @brief Finds lines in a binary image using the classical Hough transform.
.
. @param src 8-bit, single-channel binary source image.
. @param lines Output vector of lines. Each line is represented by a two-element vector
. \f$(\rho, \theta)\f$ . \f$\rho\f$ is the distance from the coordinate origin \f$(0,0)\f$ (top-left corner of
. the image). \f$\theta\f$ is the line rotation angle in radians (
. \f$0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}\f$ ).
. @param stream Stream for the asynchronous version.
.
. @sa HoughLines

Thanks, indeed it was createHoughLinesDetector(…) but unfortunately parameters
minLineLength , maxLineGap does not exist in the cuda version , is there anyway to add them ? I based my result on those parameters.

You could try createHoughSegmentDetector. See test below for an example