Как найти PSNR и SSIM двух видеофайлов в python, используя openCV и другие библиотеки?
Я хочу узнать PSNR и SSIM двух видеофайлов в python, используя openCv и numpy. Как найти PSNR в питоне
Я попробовал ниже код для SSIM
# 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))
# threshold the difference image, followed by finding contours to
# obtain the regions of the two input images that differ
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 = cnts[0] if imutils.is_cv2() else cnts[1]
# loop over the contours
for c in cnts:
# compute the bounding box of the contour and then draw the
# bounding box on both input images to represent where the two
# images differ
(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)
1 ответ
Вы можете читать видеокадры по кадрам и использовать эту функцию, чтобы вычислить сходство между кадрами и найти среднее значение.
Убедитесь, что вы указали полный путь к изображению.
def compare(ImageAPath, ImageBPath):
img1 = cv2.imread(ImageAPath) # queryImage
img2 = cv2.imread(ImageBPath)
image1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
image2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY) # trainImage
score, diff = compare_ssim(image1, image2, full=True, multichannel=False)
print("SSIM: {}".format(score))
Если ваше изображение красочное и вы не хотите использовать серое изображение, передайте
multichannel=True