如何使用openCV和其他库在python中找到两个视频文件的PSNR和SSIM?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何使用openCV和其他库在python中找到两个视频文件的PSNR和SSIM?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1508字,纯文字阅读大概需要3分钟。
内容图文
我想用openCv和numpy找出python中两个视频文件的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)
解决方法:
您可以按帧读取视频帧,并使用此功能计算帧之间的相似性并找到平均值.
确保提供图像的完整路径.
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
内容总结
以上是互联网集市为您收集整理的如何使用openCV和其他库在python中找到两个视频文件的PSNR和SSIM?全部内容,希望文章能够帮你解决如何使用openCV和其他库在python中找到两个视频文件的PSNR和SSIM?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。