【问题标题】:How to find PSNR and SSIM of two video files in python using openCV and other libraries?如何使用openCV和其他库在python中查找两个视频文件的PSNR和SSIM?
【发布时间】:2018-07-17 09:16:49
【问题描述】:

我想在 python 中使用 openCv 和 numpy 找出两个视频文件的 PSNR 和 SSIM。 如何在python中找到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)

【问题讨论】:

    标签: python numpy opencv matplotlib ssim


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2017-05-17
      • 2023-04-04
      • 1970-01-01
      • 2016-09-20
      • 2014-04-10
      • 1970-01-01
      • 2019-07-02
      • 1970-01-01
      • 2020-06-27
      相关资源
      最近更新 更多