Sha*_*aul 5 python image-processing python-imaging-library python-3.x python-imageio
试图匹配两个图像以找出它们之间的分数。但它显示了一些尺寸错误。无法解决问题。我的代码如下:
from skimage.measure import compare_ssim
#import argparse
#import imutils
import cv2
img1="1.png"
img2="2.png"
# load the two input images
imageA = cv2.imread(img1)
imageB = cv2.imread(img2)
# convert the images to grayscale
grayA = cv2.cvtColor(imageA, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(imageB, cv2.COLOR_BGR2GRAY)
# compute the Structural Similarity Index (SSIM) between the two
# images, ensuring that the difference image is returned
(score, diff) = compare_ssim(grayA, grayB, full=True)
diff = (diff * 255).astype("uint8")
print("SSIM: {}".format(score))
Run Code Online (Sandbox Code Playgroud)
这给 n 一个错误:
raise ValueError('Input images must have the same dimensions.')
ValueError: Input images must have the same dimensions.
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
修改 Saurav Panda 的回答:
您可以将其中一个图像重塑为其他图像的大小,如下所示:
imageB=cv2.resize(imageB,imageA.shape)
Run Code Online (Sandbox Code Playgroud)
注意
(H, W) = imageA.shape
# to resize and set the new width and height
imageB = cv2.resize(imageB, (W, H))
Run Code Online (Sandbox Code Playgroud)
该cv2.resize功能的输入期望(W,H)。这是cv2.shape(H,W)输出的相反顺序,因此您需要捕获它,否则在比较非方形图像时会出现相同的错误。
错误
“输入图像必须具有相同的尺寸。”
告诉您您调用的函数需要相同尺寸的输入图像,但您没有这样做。
显然,您可以通过提供具有相同尺寸的输入图像来解决这个问题,或者如果图像具有不同的尺寸并且由于任何原因无法更改它,则不调用该函数。
从文件加载图像后比较 imageA.shape 和 imageB.shape。
对于简单的调试:
print imageA.shape
print imageB.shape
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9064 次 |
| 最近记录: |