gpt4 book ai didi

python - 为什么 python OpenCV 提示图像不是单 channel 8 位?

转载 作者:太空宇宙 更新时间:2023-11-03 21:09:16 25 4
gpt4 key购买 nike

我尝试在 python 中运行以下代码来检测图像中的线条,但我收到错误消息,提示该图像不是 8 位单 channel 图像。

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 输出:

(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

我在这里做错了什么?

最佳答案

我相信你应该传递 CV_8U 因为图像是灰度的:

img_filtered = cv2.filter2D(gray, cv2.CV_8U, gb_kernel.transpose())

关于python - 为什么 python OpenCV 提示图像不是单 channel 8 位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20163333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com