Ask Your Question

Revision history [back]

HoughLinesP does not accept output from threshold. why?

Hi Folks,

I'm beginning with open-cv using the python bindings. I'm trying to do a simple proof-of-concept code to detect horizontal lines in images.

For that I'm trying a threshold manipulation plus a HoughLinesP transform to detect lines but cv2.HoughLinesP complains that the image is not 8-bit single channel.

retval, thresh = cv2.threshold(img_filtered, 254, 255, cv2.THRESH_BINARY_INV)
lines = cv2.HoughLinesP(thresh, 1, np.pi/180, 200, 800, 0)

>> error: (-5) The source image must be 8-bit, single-channel in function cvHoughLines2

I'm pretty sure the image is being loaded as grayscale (I tried two different approaches for this):

img = cv2.imread("source.jpg", 0)
gray = cv2.cvtColor (img, cv2.COLOR_BGR2GRAY)

What am I doing wrong here? What should I do to pass the output of cv2.threshold int cv2.HoughLinesP?

Thanks in advance,

click to hide/show revision 2
retagged

updated 2013-11-24 10:53:11 -0600

berak gravatar image

HoughLinesP does not accept output from threshold. why?

Hi Folks,

I'm beginning with open-cv using the python bindings. I'm trying to do a simple proof-of-concept code to detect horizontal lines in images.

For that I'm trying a threshold manipulation plus a HoughLinesP transform to detect lines but cv2.HoughLinesP complains that the image is not 8-bit single channel.

retval, thresh = cv2.threshold(img_filtered, 254, 255, cv2.THRESH_BINARY_INV)
lines = cv2.HoughLinesP(thresh, 1, np.pi/180, 200, 800, 0)

>> error: (-5) The source image must be 8-bit, single-channel in function cvHoughLines2

I'm pretty sure the image is being loaded as grayscale (I tried two different approaches for this):

img = cv2.imread("source.jpg", 0)
gray = cv2.cvtColor (img, cv2.COLOR_BGR2GRAY)

What am I doing wrong here? What should I do to pass the output of cv2.threshold int cv2.HoughLinesP?

Thanks in advance,