Skip to content

Conversation

@raimbekovm
Copy link
Contributor

Summary

Fixes a bug where the OpenCL-accelerated implementation of cv::HoughLines ignored min_theta and max_theta parameters, always computing angles from 0 instead of the specified range.

Problem Description

When calling cv::HoughLines with OpenCL acceleration and specifying min_theta/max_theta parameters (e.g., to detect only horizontal lines with theta ∈ [80°, 100°]), the function would fail to find any lines. This is because:

  1. The C++ code correctly computed numangle based on the theta range
  2. But the OpenCL kernels always computed angles starting from 0, ignoring min_theta
  3. This caused a mismatch between the accumulator indexing and actual angles

Changes Made

C++ code (hough.cpp):

  • Added min_theta parameter to ocl_fillAccum function signature
  • Updated calls to ocl_fillAccum in ocl_HoughLines (passes min_theta) and ocl_HoughLinesP (passes 0.0 for default [0, π] range)
  • Updated getLinesKernel.args to pass min_theta to the kernel

OpenCL kernels (hough_lines.cl):

  • Updated fill_accum_global and fill_accum_local kernels to accept min_theta parameter
  • Changed angle computation from theta * theta_idx to min_theta + theta * theta_idx
  • Updated get_lines kernel to correctly compute detected line angles as min_theta + y * theta

Testing

The fix resolves the issue described in #28036 where horizontal line detection with min_theta=80°, max_theta=100° failed with OpenCL but worked without it.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch (4.x)
  • There is a reference to the original bug report and related work (cv::HoughLines with OpenCL use min_theta/max_theta incorrectly #28036)
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
  • The feature is well documented and sample code can be built with the project CMake

Fixes #28036

The OpenCL implementation of cv::HoughLines ignored min_theta and
max_theta parameters. While numangle was computed correctly, the
kernels always started angle computation from 0 instead of min_theta.

Changes:
- Added min_theta parameter to ocl_fillAccum function
- Updated fill_accum_global and fill_accum_local kernels to compute
  angles as: min_theta + theta * theta_idx
- Updated get_lines kernel to correctly report detected line angles
- HoughLinesP continues to use default [0, PI] range (min_theta=0.0)

Fixes opencv#28036
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cv::HoughLines with OpenCL use min_theta/max_theta incorrectly

1 participant