Search code examples
python-3.xopencvnumpyhough-transformopencv3.1

Why does the HoughLinesP output a 3D array, instead of a 2D array?


I was working with the function (Python, Numpy, OpenCV3) over an image, and this is the sample output I have -

[[[539 340 897 538]]

 [[533 340 877 538]]

 [[280 460 346 410]]

 [[292 462 353 411]]

 [[540 343 798 492]]]

Its size is (5,1,4)

I am trying to understand what scenario will the function output something like (5,2,4) or (5,3,4). But I can't think of any and all the images I have worked with right now, it's a 3D array with the number of columns as 1.

Wouldn't just a 2D array be sufficient and perhaps more efficient?


Solution

  • I asked on the OpenCV Q&A and got the following response -

    opencv is a c++ library, and the python wrappers are auto-generated from some scripts, so in c++ we have:

    vector lines; to hold the hough results.

    now unfortunately , Vec4i is a descendant of Matx , which is actually a 2d thing, so in python you get:

    [ #one for the vector

    [ #one for the 1st dim of Vec4i (1, pretty useless, admittedly :)

    [ #one for the 2nd dim of Vec4i (4 elements)

    again, i think, you'll just have to live with it.