from skimage.measure import compare_ssim
import argparse
import imutils
import cv2
first = ("original_02.png")
second = ("modified_02.png")
imageA = cv2.imread("first")
imageB = cv2.imread("second")
grayA = cv2.cvtColor(imageA, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(imageB, cv2.COLOR_BGR2GRAY)
(score, diff) = compare_ssim(grayA, grayB, full=True)
diff = (diff * 255).astype("uint8")
print("SSIM: {}".format(score))
thresh = cv2.threshold(diff, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
for c in cnts:
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(imageA, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.rectangle(imageB, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.imshow("Original", imageA)
cv2.imshow("Modified", imageB)
cv2.imshow("Diff", diff)
cv2.imshow("Thresh", thresh)
cv2.waitKey(0)
这是我的代码,我遇到了标题中提到的错误。我将代码和必要的文件保存在同一个文件夹中
greyA = cv2.cvtColor(imageA, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-j8nxabm_\opencv\modules\imgproc \src\color.cpp:182: 错误: (-215:断言失败) !_src.empty() 在函数“cv::cvtColor”中
上面是我收到的错误
绝地无双
紫衣仙女
相关分类