abidrahmank/OpenCV2-Python-Tutorials

Generalizing Hough lines tutorial

Opened this issue · 0 comments

I'm fairly new to opencv and am finding documentation/tutorials pretty brutal. There is an immense amount of "magic incantation" unexplained code out there.

Here is the example from the Hough lines tutorial:

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)

image

  • why lines[0]? It would appear this plots one line, but the soduku puzzle is all marked up
  • Expanding out, x1 = (cos(theta)*rho) - (1000*sin(theta)*rho). Where is 1000 coming from?
  • what is the unit of the threshold? I'm assuming pixels?
  • the line color is (0, 0, 255), but red is shown on the example

Some of these probably seem like nitpicks, but for someone who is pretty new and the fact that these tutorials rank high on google, it would seem advantageous to have things match up and not be confusing.

If someone could expand on some of the questions, I'd be happy to update the tutorial. I'm guessing this should be for line in lines, for rho,theta in line: and that the 1000 should match the output of img.shape