简体   繁体   English

TypeError:structure_similarity() 需要 2 个位置 arguments 但给出了 8 个

[英]TypeError: structural_similarity() takes 2 positional arguments but 8 were given

When I calculate the similarity between two grayscale images in python and opencv, the function called compare_ssim() is reported incorrectly.当我在 python 和 opencv 中计算两个灰度图像之间的相似度时,错误地报告了名为compare_ssim()的 function。

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

The error message is as follows:错误信息如下:

TypeError: structural_similarity() takes 2 positional arguments but 8 were given TypeError:structure_similarity() 需要 2 个位置 arguments 但给出了 8 个

This is a function from library.这是来自图书馆的 function。 From the _structural_similarity.py file.The directory is \skimage\measure\_structural_similarity.py .来自_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 line, error message is displayed in this line. return行,此行显示错误信息。

And structural_similarity() .The directory of this function is \skimage\metrics\_structural_similarity.py , the function is as follows:还有structural_similarity() 。这个function的目录是\skimage\metrics\_structural_similarity.py ,function如下:

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

What is the problem, why is this?这是什么问题,这是为什么?

from skimage.metrics import structural_similarity

Do try...试试...

I tried using this:我尝试使用这个:

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

here, gray_image_1.shape = gray_image_2.shape = (420,420).在这里,gray_image_1.shape = gray_image_2.shape = (420,420)。 This worked for me (python 3.6.6).这对我有用(python 3.6.6)。

` `

Thank you for your patience.感谢您的耐心等待。 I have solved this problem.我已经解决了这个问题。 It should be a function call error.when I replace the header file 'from skimage.measures import compare_ssim' with from skimage.metrics import structural_similarity , and replace the function call with a (score, diff) = structural_similarity(gray1, gray2, full=True) , compiled successfully It should be a function call error.when I replace the header file 'from skimage.measures import compare_ssim' with from skimage.metrics import structural_similarity , and replace the function call with a (score, diff) = structural_similarity(gray1, gray2, full=True) ,编译成功

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:publish()接受2个位置参数,但给出了3个 - TypeError: publish() takes 2 positional arguments but 3 were given TypeError:get()接受2个位置参数,但给出了3个 - TypeError: get() takes 2 positional arguments but 3 were given 类型错误:hook() 需要 2 个位置参数,但给出了 3 个 - TypeError: hook() takes 2 positional arguments but 3 were given TypeError:_transform()需要2个位置参数,但是给出了3个 - TypeError: _transform() takes 2 positional arguments but 3 were given 类型错误:forward() 需要 2 个位置参数,但给出了 3 个 - TypeError: forward() takes 2 positional arguments but 3 were given TypeError: init() 需要 2 个位置 arguments 但给出了 3 个 - TypeError: init() takes 2 positional arguments but 3 were given TypeError: hook() 需要 3 个位置 arguments 但给出了 4 个 - TypeError: hook() takes 3 positional arguments but 4 were given Python TypeError:接受 4 个位置参数,但给出了 5 个 - Python TypeError: takes 4 positional arguments but 5 were given TypeError:open()接受0个位置参数,但给出了2个 - TypeError: open() takes 0 positional arguments but 2 were given TypeError:invoke()接受2个位置参数,但给出了3个 - TypeError: invoke() takes 2 positional arguments but 3 were given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM