TypeError:structural_similarity()接受2个位置参数,但给出了8个

时间:2019-10-22 06:06:26

标签: python python-3.x opencv

当我在python和opencv中计算两个灰度图像之间的相似度时,错误报告了compare_ssim()函数。

gray1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY)
(score, diff) = compare_ssim(gray1, gray2, full=True)

错误消息如下:

  

TypeError:structural_similarity()接受2个位置参数,但给出了8个

这是库中的函数。来自_structural_similarity.py文件。目录为\skimage\measure\_structural_similarity.py

def compare_ssim(X, Y, win_size=None, gradient=False,
                 data_range=None, multichannel=False, gaussian_weights=False,
                 full=False, **kwargs):
    warn('DEPRECATED: skimage.measure.compare_ssim has been moved to '
         'skimage.metrics.structural_similarity. It will be removed from '
         'skimage.measure in version 0.18.', stacklevel=2)
       return structural_similarity(X, Y, win_size, gradient,
                                 data_range, multichannel, gaussian_weights, 
                                 full, **kwargs)

  

return行,此行中显示错误消息。

structural_similarity()。此函数的目录为\skimage\metrics\_structural_similarity.py,该函数如下:

def structural_similarity(im1, im2,
                          *,
                          win_size=None, gradient=False, data_range=None,
                          multichannel=False, gaussian_weights=False,
                          full=False, **kwargs):

出什么问题了,为什么?

3 个答案:

答案 0 :(得分:0)

from skimage.metrics import structural_similarity

尝试...

答案 1 :(得分:0)

我尝试使用这个:

from skimage.metrics import structural_similarity as ssim
...
s = ssim(gray_image_1,gray_image_2)

此处,gray_image_1.shape = gray_image_2.shape =(420,420)。 这对我有用(python 3.6.6)。

`

答案 2 :(得分:0)

感谢您的耐心配合。我已经解决了这个问题。 应该是函数调用错误。当我将头文件'from skimage.measures import compare_ssim'替换为from skimage.metrics import structural_similarity,并将函数调用替换为(score, diff) = structural_similarity(gray1, gray2, full=True)时,编译成功