0

我需要对过滤后的图像的拉普拉斯算子进行阈值过零检测。但是一旦应用拉普拉斯算子,在进行阈值处理时就会出错。有什么建议吗?

代码:

img = cv2.imread('H:/FYP/interim/aniso.jpg')
lap = cv2.Laplacian(img, 1, ksize=5)
retval, threshold = cv2.threshold(lap, 70, 255, cv2.THRESH_BINARY)
plt.imshow(threshold)

错误:

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-23-e36300501b24> in <module>
      1 img = cv2.imread('H:/FYP/interim/aniso.jpg')
      2 lap = cv2.Laplacian(img, 1, ksize=5)
----> 3 retval, threshold = cv2.threshold(lap, 70, 255, cv2.THRESH_BINARY)
      4 plt.imshow(threshold)

error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\thresh.cpp:1612: error: (-210:Unsupported format or combination of formats)  in function 'cv::threshold'
4

1 回答 1

1

你可以这样改变

retval, threshold = cv2.threshold(img, 127, 255, cv2.THRESH_TOZERO)
于 2019-10-05T02:38:45.997 回答