为什么 HoughLinesP 输出的是 3D 数组,而不是 2D 数组?
Why does the HoughLinesP output a 3D array, instead of a 2D array?
我在图像上使用函数 (Python、Numpy、OpenCV3),这是我的示例输出 -
[[[539 340 897 538]]
[[533 340 877 538]]
[[280 460 346 410]]
[[292 462 353 411]]
[[540 343 798 492]]]
它的大小是 (5,1,4)
我想了解函数输出类似 (5,2,4) 或 (5,3,4) 的情况。但是我想不出我现在处理过的所有图像,它是一个列数为 1 的 3D 数组。
难道仅仅一个二维数组就足够了吗?也许效率更高?
如果你不想要额外的维度,因为它是 1,只需使用挤压
>>> a = np.arange(5*4).reshape(5,1,4)
>>> a
array([[[ 0, 1, 2, 3]],
[[ 4, 5, 6, 7]],
[[ 8, 9, 10, 11]],
[[12, 13, 14, 15]],
[[16, 17, 18, 19]]])
>>> a.squeeze()
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15],
[16, 17, 18, 19]])
有时额外的轴会派上用场
a.swapaxes(1,2)
array([[[ 0],
[ 1],
[ 2],
[ 3]],
... Snip
[[16],
[17],
[18],
[19]]])
鉴于更新并假设需要第一个 return 相同的结果假设不需要额外的维度。
>>> a[0].squeeze()
array([0, 1, 2, 3])
>>> a.squeeze()[0]
array([0, 1, 2, 3])
我在 OpenCV Q&A 上询问并得到了以下回复 -
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.
我在图像上使用函数 (Python、Numpy、OpenCV3),这是我的示例输出 -
[[[539 340 897 538]]
[[533 340 877 538]]
[[280 460 346 410]]
[[292 462 353 411]]
[[540 343 798 492]]]
它的大小是 (5,1,4)
我想了解函数输出类似 (5,2,4) 或 (5,3,4) 的情况。但是我想不出我现在处理过的所有图像,它是一个列数为 1 的 3D 数组。
难道仅仅一个二维数组就足够了吗?也许效率更高?
如果你不想要额外的维度,因为它是 1,只需使用挤压
>>> a = np.arange(5*4).reshape(5,1,4)
>>> a
array([[[ 0, 1, 2, 3]],
[[ 4, 5, 6, 7]],
[[ 8, 9, 10, 11]],
[[12, 13, 14, 15]],
[[16, 17, 18, 19]]])
>>> a.squeeze()
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15],
[16, 17, 18, 19]])
有时额外的轴会派上用场
a.swapaxes(1,2)
array([[[ 0],
[ 1],
[ 2],
[ 3]],
... Snip
[[16],
[17],
[18],
[19]]])
鉴于更新并假设需要第一个 return 相同的结果假设不需要额外的维度。
>>> a[0].squeeze()
array([0, 1, 2, 3])
>>> a.squeeze()[0]
array([0, 1, 2, 3])
我在 OpenCV Q&A 上询问并得到了以下回复 -
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.