Merge pull request #29663 from Prasoon-Bodke:fix/houghlinesp-doc-shape-5.0

samples: fix HoughLines/HoughLinesP Python sample for 5.0 shape change (fixes #29637) - #29663

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake

<!-- Note!!! If you are an automated agent, we have a special process for you: add 🤖🤖🤖 to the end of the PR title. -->

Fixes #29637.

OpenCV 5.0 changed vector-backed Mat/OutputArray to true 1D arrays (see 
migration guide: 1D and 0D array semantics). This changes HoughLines/
HoughLinesP Python return shape from (N,1,X) to (N,X), breaking the old 
indexing pattern used in the tutorial sample.

Tested locally against opencv-python 5.0 — script runs without error, 
lines drawn correctly on samples/data/sudoku.png.
This commit is contained in:
Prasoon Bodke
2026-08-13 14:14:31 +03:00
committed by GitHub
parent b6575e040f
commit 5846edaa83
4 changed files with 18 additions and 19 deletions
@@ -39,9 +39,7 @@ def main(argv):
## [draw_lines]
# Draw the lines
if lines is not None:
for i in range(0, len(lines)):
rho = lines[i][0][0]
theta = lines[i][0][1]
for rho, theta in lines.reshape(-1, 2):
a = math.cos(theta)
b = math.sin(theta)
x0 = a * rho
@@ -59,8 +57,9 @@ def main(argv):
## [draw_lines_p]
# Draw the lines
if linesP is not None:
for i in range(0, len(linesP)):
l = linesP[i][0]
num_lines, _ = linesP.shape
for i in range(num_lines):
l = linesP[i]
cv.line(cdstP, (l[0], l[1]), (l[2], l[3]), (0,0,255), 3, cv.LINE_AA)
## [draw_lines_p]
## [imshow]
@@ -76,4 +75,4 @@ def main(argv):
## [exit]
if __name__ == "__main__":
main(sys.argv[1:])
main(sys.argv[1:])