I hope I wrote the question title right because I don't know how to exactly explain it. Consider below's code:
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)
Why it has to be wrote for rho,theta in lines[0]:
? By this kind of code, I can only obtain one line. I have tried to remove the indexing in lines
but I got ValueError: need more than 1 value to unpack
. I have tried to print the returned value and it look something like this:
[[[ 287. 1.97222209]]
[[ 885. 1.20427716]]
[[ 881. 1.22173047]]]
I have kinda solved this problem my making the code look like this:
lines = cv2.HoughLines(edges,1,np.pi/180,200)
for i in range(10):
for rho,theta in lines[i]:
I wonder, what is really happening? Or did I do something wrong here?
lines[0]
, then that's likely correct. The python libraries are a bridge to the C++ core, so the indexing probably has to do with that. – Selfconfidence