Skip to content

Segmentation Fault with HoughLinesPointSet #21029

@tv3141

Description

@tv3141
System information (version)
  • OpenCV => 4.5
  • Operating System / Platform => Linux 64 Bit
  • Compiler => ? (whatever was used to build the opencv-python package)
Detailed description

The function HoughLinesPointSet crashes randomly with Segmentation Faults.

The Hough accumulator (histogram of angles and distances that define lines) is populated using a pointer and an index calculated from r, the distance to a candidate line. The accumulator is initialized independently from the point coordinates, however r depends on the point coordinates, and thus can lead to memory access outside the accumulator.

accum[(n+1) * (numrho+2) + r+1]++;

Steps to reproduce
import sys
import numpy as np
import cv2
print(sys.version)
print(np.__version__)
print(cv2.__version__)

from cv2 import HoughLinesPointSet

def foo():
    points = np.array([(100, 100), (1000, 1000), (10000, 10000), (100000, 100000)])

    # Create array shape required by opencv
    # https://stackoverflow.com/questions/47402445/need-help-in-understanding-error-for-cv2-undistortpoints/47403282#47403282
    points = points[:, np.newaxis, :].astype('float32')

    ## Hough transform config
    # rho: distance origin to closest point on line
    rhoMin = 0
    rhoMax = 10
    rhoStep = 0.1

    # theta: angle between x-axis and line connection closest point to origin
    # limit line search to horizontal lines
    thetaMin = np.deg2rad(85)
    thetaMax = np.deg2rad(95)
    thetaStep = np.deg2rad(1)

    lines_max = 5
    threshold = 100

    HoughLinesPointSet(points, lines_max, threshold, rhoMin, rhoMax, rhoStep, thetaMin, thetaMax, thetaStep)


for i in range(1000):
    foo()

Output:

3.9.6 (default, Jul 30 2021, 16:35:19) 
[GCC 7.5.0]
1.21.1
4.5.4-dev
Segmentation fault (core dumped)
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions