I'm try to run the following code in python to detect lines in an image, but I'm getting an error complaining that the image is not an 8bit single channel image.
img = cv2.imread("source.jpg")
gray = cv2.cvtColor (img, cv2.COLOR_BGR2GRAY)
gb_kernel = cv2.getGaborKernel((ks, ks),sig,th,lm,0,0,cv2.CV_32F)
img_filtered = cv2.filter2D(gray, cv2.CV_32F, gb_kernel.transpose())
retval, thresh = cv2.threshold(img_filtered, 254, 255, cv2.THRESH_BINARY_INV)
print thresh.shape
lines = cv2.HoughLinesP(thresh, 1, np.pi/180, 200, 800, 0)
python output:
(1440, 993)
OpenCV Error: Bad argument (The source image must be 8-bit, single-channel) in cvHoughLines2, file /Users/ericchaves/Projects/opencv-env/opencv-2.4.7/modules/imgproc/src/hough.cpp, line 712
Traceback (most recent call last):
File "detect-lines.py", line 22, in <module>
lines = cv2.HoughLinesP(thresh, 1, np.pi/180, 200, 800, 0)
cv2.error: /Users/ericchaves/Projects/opencv-env/opencv-2.4.7/modules/imgproc/src/hough.cpp:712: error: (-5) The source image must be 8-bit, single-channel in function cvHoughLines2
What am I doing wrong here?
I believe you should pass CV_8U instead since the image is grayscale:
img_filtered = cv2.filter2D(gray, cv2.CV_8U, gb_kernel.transpose())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With