Ask Your Question
0

HoughLinesP does not accept output from threshold. why?

asked 2013-11-23 09:30:37 -0600

epc gravatar image

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

berak gravatar image

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,

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-11-24 10:34:28 -0600

Guanta gravatar image

I just double-checked and HoughLinesP works fine for me. Can you double-check that thresh is of the correct format, i.e.:

print threshd.shape, thresh.dtype

should give you sth like:

((600, 868), dtype('uint8'))

If you get sth like (600,868,3) would indicate that you haven't converted the image correctly to a single channel. However, I guess your type is wrong, maybe due to the filtering process before.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-11-23 09:30:37 -0600

Seen: 1,025 times

Last updated: Nov 24 '13