首页 > 解决方案 > 将python中的图像与opencv进行比较的最快方法是什么

问题描述

我必须将所有视频帧与一张图像进行比较,并且使用 compare_ssim 需要很长时间。我可以用什么最快的方法将图像与图像的相似程度进行比较?

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import cv2
from skimage.measure import compare_ssim as ssim
import time

start_time = time.time()

# Load File
opening = cv2.VideoCapture("/content/drive/My Drive/Skipper/DrStone-OP1.webm")
episode = cv2.VideoCapture("/content/drive/My Drive/Skipper/[Erai-raws] Dr. Stone - 06 [720p].mkv")

# Get First
opening.set(1, 0)
off_ret, opening_firstframe = opening.read()
opening_firstframe = cv2.cvtColor(opening_firstframe, cv2.COLOR_BGR2GRAY)
# (H, W) = opening_firstframe.shape

# Iterate over the episode
while episode.isOpened():
    ep_ret, ep_frame = episode.read()
    if ep_ret:
        frames = episode.get(cv2.CAP_PROP_POS_FRAMES)
        #ep_frame = cv2.resize(ep_frame, (W, H))
        ep_frame = cv2.cvtColor(ep_frame, cv2.COLOR_BGR2GRAY)
        sim_index = ssim(opening_firstframe, ep_frame) * 100
        print(str(frames) + " : " + str(sim_index))
    else:
        break
print("--- %s seconds ---" % (time.time() - start_time))

标签: pythonopencvimage-comparison

解决方案


您可以使用均方误差 (mse) 或峰值信噪比 (psnr) 来比较图像。它们通常用于衡量编解码器的质量。


推荐阅读