【发布时间】:2016-04-29 00:32:11
【问题描述】:
我希望我写的问题标题是正确的,因为我不知道如何准确地解释它。考虑下面的代码:
lines = cv2.HoughLines(edges,1,np.pi/180,200)
for rho,theta in lines[0]:
a = np.cos(theta)
b = np.sin(theta)
x0 = a*rho
y0 = b*rho
x1 = int(x0 + 1000*(-b))
y1 = int(y0 + 1000*(a))
x2 = int(x0 - 1000*(-b))
y2 = int(y0 - 1000*(a))
cv2.line(img,(x1,y1),(x2,y2),(0,0,255),2)
为什么一定要写成for rho,theta in lines[0]:?通过这种代码,我只能获得一行。我试图删除lines 中的索引,但我得到了ValueError: need more than 1 value to unpack。我试图打印返回的值,它看起来像这样:
[[[ 287. 1.97222209]]
[[ 885. 1.20427716]]
[[ 881. 1.22173047]]]
我已经解决了这个问题,我让代码看起来像这样:
lines = cv2.HoughLines(edges,1,np.pi/180,200)
for i in range(10):
for rho,theta in lines[i]:
我想知道,到底发生了什么?还是我在这里做错了什么?
【问题讨论】:
-
如果 tthe docs 说要使用
lines[0],那么这可能是正确的。 python 库是通往 C++ 核心的桥梁,因此索引可能与此有关。
标签: python opencv hough-transform