Ask Your Question
0

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

asked 2016-11-01 11:00:37 -0500

sjuneja gravatar image

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 dimensions are (5,1,4)

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

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

edit retag flag offensive close merge delete

Comments

cv2.__version__ ?

(and yes, it sounds like half-way between a bug and a major inconvenience)

berak gravatar imageberak ( 2016-11-01 11:05:12 -0500 )edit

@berak OpenCV version : 3.1.0

sjuneja gravatar imagesjuneja ( 2016-11-01 11:13:08 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-11-01 11:24:21 -0500

berak gravatar image

updated 2016-11-01 11:57:44 -0500

well, i can try to explain, why it is so, but there seems to be no quick way to fix it:

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

vector<Vec4i> 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.

edit flag offensive delete link more

Comments

Both the links in your answer link to the same line of code. Was that intentional?

But regardless, my skills aren't enough to understand how this all gets converted, and what it means that Vec41 is a descendant of Matx. It's not necessary, but if you could point me in a general direction to understand the "process" of it all better, I would highly appreciate it. But thank you!

sjuneja gravatar imagesjuneja ( 2016-11-01 11:46:33 -0500 )edit
1

ah, sorry, link fail (corrected now, thanks for pointing out)

again, the python wrapper script thinks, Vec4i is a 2d array (with 1st dimension set to 1)

berak gravatar imageberak ( 2016-11-01 11:54:09 -0500 )edit

Thanks. Is there a link/github code to these "python wrappers" for me to look at?

sjuneja gravatar imagesjuneja ( 2016-11-01 11:59:49 -0500 )edit
1
berak gravatar imageberak ( 2016-11-01 12:02:16 -0500 )edit

Awesome. Thanks a lot for your help!

sjuneja gravatar imagesjuneja ( 2016-11-01 12:25:35 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-11-01 11:00:37 -0500

Seen: 151 times

Last updated: Nov 01 '16