Я следил за этим на YouTube, его канале (KostasT). При запуске я получаю следующую ошибку в строке 5:
(line 5, print
from skiimage.measure import compare_ssim
ImportError: cannot import name 'compare_ssim' from 'skimage.measure' )
Я установил библиотеку :scikit-image, но она по-прежнему выдает ошибку.
Пожалуйста, помогите.
import cv2
import imutils
import numpy as np
from skimage.measure import compare_ssim
img1 = cv2.imread("F:\\d.png")
img1 = cv2.resize(img1, (600,360))
img2 = cv2.imread("F:\\x.png")
img2 = cv2.resize(img2, (606,360))
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
(similar,diff) =cstructural_similarity.difference(gray1, gray2,full=True)
diff = (diff*255) .astype("unit8")
cv2.imshow("ODifference", diff)
thresh = cv2.threshold(diff, 0, 255, cv2. THRESH_BINARY | cv2. THRESH_OTSU)[1]
cv2. imshow("Threshold", thresh)
contours = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(contours)
for contour in contours:
if cv2.contowrArea(contour)>100:
x, y. w, h=cv2.boundingRect (contour)
cv2.rectangle(imgl, (x,y), (xew, yeh), (6,0,255), 2)
cv2.rectangle(img2, (x,y), (xew, yer), (6,0,255), 2)
Cv2.putText(img2, "Similarity:"+str(similar),(10,30), cv2.FONT_HERSHEY_SIMPLEX, .7, (0,0,255), 2)
cv2.waitKey(0)
cv2.destroyAllWindows()
Подробнее здесь: https://stackoverflow.com/questions/789 ... sim-opencv