HoughLinesP() example in documentation throws TypeError

asked 2014-08-04 21:45:26 -0500

Hey all,

I've been trying to get the HoughLinesP() function to work in Python 2.7.3. I tried using the example given in the Probablistic Hough Transform section of the documentation, modifying it to use an image that I have, but every time I try to get it to work, I get this error: (precise)roger@localhost:~/projects/moos2$ python lines.pyTraceback (most recent call last):
File "lines.py", line 9, in <module>
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
TypeError: <unknown> is not a numpy array

I'm not sure why it doesn't work, but I can't seem to work around this error, especially since I'm so unfamiliar with OpenCV. Is there a bug in the documentation code, or am I doing something wrong?

The code (with my modification of the file line) reads:

import cv2
import numpy as np

img = cv2.imread('amite.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
minLineLength = 100
maxLineGap = 10
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
for x1,y1,x2,y2 in lines[0]:
cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)

cv2.imwrite('houghlines5.jpg',img)

What's wrong?

edit retag flag offensive close merge delete