使用下面的代码,尝试去除一个非常简单的图像。当打印出数据数组时,我会得到以下结构,因为图像是灰度的,因此需要这样做:
[[ 62 62 63 ... 29 16 6]
[ 75 90 103 ... 21 16 12]
[ 77 100 118 ... 29 29 30]
...
[ 84 68 56 ... 47 50 53]
[101 94 89 ... 40 44 48]这是代码和相关的错误,在这一点上我有点卡住了。有什么建议吗?
import cv2
from matplotlib import pyplot as plt
img = cv2.imread(path,0)
dst = cv2.fastNlMeansDenoising(img,None,10,10,7,21)
plt.subplot(211),plt.imshow(dst)
plt.subplot(212),plt.imshow(img)
plt.show()
____________________________________________________________________
runfile(___, wdir='G:/James Alexander/Python Programs')
Traceback (most recent call last):
File "<ipython-input-127-ce832752c183>", line 1, in <module>
runfile('G:/James Alexander/Python Programs/Noiseremoval.py', wdir=___)
File "___", line 704, in runfile
execfile(filename, namespace)
File "___", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "___", line 13, in <module>
dst = cv2.fastNlMeansDenoising(img,None,10,10,7,21)
error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\photo\src\denoising.cpp:120: error: (-215:Assertion failed) hn == 1 || hn == cn in function 'cv::fastNlMeansDenoising'发布于 2019-12-04 16:51:23
阅读您正在使用的去噪函数上的文档。有两种方法来调用这个函数,而您似乎是在将两者结合起来。
dst = cv.fastNlMeansDenoising(src[, dst[, h[, templateWindowSize[, searchWindowSize]]]])
或
dst = cv.fastNlMeansDenoising(src, h[, dst[, templateWindowSize[, searchWindowSize[, normType]]]])
您正在使用(src, dst, h, templateWindowSize, searchWindowSize, normType)调用它,它要么有太多的参数,要么顺序错误,这取决于您想要使用的方法。
发布于 2021-09-03 10:36:47
将参数更改为
dst = cv2.fastNlMeansDenoising(img, None, 30, 7, 21)https://stackoverflow.com/questions/59180712
复制相似问题