0

enter image description hereenter image description hereI am using cv2.houghlinesP, and I have seen a lot of people passing an empty array in the arguments.

It goes something like -

lines = cv2.HoughLinesP(img, rho, theta, threshold, np.array([]), minLineLength=min_line_len, maxLineGap=max_line_gap)

What role does np.array([]) play here?

  • 1
    Kind of pointless as it stands, since the last two optional parameters are already named, it could be completely skipped. Alternative with similar behaviour would be passing `None` there. Both basically mean, "there's no array to reuse for output". | In this function this parameter is kinda useless in Python. In general, you can provide it to reuse an array in multiple iterations (to avoid repeated allocations), but it has to be the correct size. Unfortunately you don't usually know how many line you'll find until after you've called the function. – Dan Mašek Sep 12 '19 at 22:25

1 Answers1

0

I think there may be a deficiency in the Python documentation for this function. For most of the C/C++ functions, you supply a pointer to a result array and it gets filled. But in Python, usually the whole result is just passed back.

For HoughLinesP you can follow this post or this tutorial and drop the empty array completely:

lines = cv2.HoughLinesP(img, rho, theta, threshold, minLineLength=min_line_len, maxLineGap=max_line_gap)
bfris
  • 5,272
  • 1
  • 20
  • 37
  • So what you are saying is that it doesn’t matter whether I pass the empty array or not? –  Sep 12 '19 at 18:40
  • I think it *does* matter whether you pass the array and you SHOULD NOT pass it at all. I've updated my answer to make it more clear. – bfris Sep 12 '19 at 18:46
  • I tried it, it still shows some weird error. I've updated my post with the results. –  Sep 12 '19 at 21:16
  • Figured it out! The post helped. I had read it before but didn't quite understand, but now I got it. –  Sep 12 '19 at 21:24