[英]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.